I've been playing with WeightedData and wanted a financial engineering example, a colleague suggested working with the fractional return (FinancialData["Name","FractionalChange") of a weighted portfolio.

Things were going well until I tried to build a Manipulate:

{{Style[DateString[fractionalChanges[[1, day, 1]], {"DayName", " ", "Day", " ", 
   "MonthName", " ", "Year"}], "Text"], SpanFromLeft},
{Style["Unweighted Mean Fractional Change:", "Text"], 
Style[ToString@Mean[fractionalChanges[[All, day, 2]]], "Text"]},
{Style["Weighted Mean Fractional Change:", "Text"], 
Style[ToString@Mean[allWeightedFChanges[[day]]], "Text"]},
 Plot[{PDF[HistogramDistribution[allWeightedFChanges[[day]], 10], 
    x], PDF[HistogramDistribution[
     allWeightedFChanges[[day]]["InputData"], 10], x]}, {x, -0.03,
    0.03}, Filling -> Axis, PlotStyle -> {Red, Blue},
  PlotLegends -> {"Weighted Fractional \nChange Distribution", 
    "Unweighted Fractional \nChange Distribution"}, 
  AxesLabel -> {"Fractional Change", " "}], {700, 280}, 
 ImageSizeAction -> "ResizeToFit", Alignment -> {Center, Center}],
 SpanFromLeft}}, Frame -> All], {day, 1, 253, 1},
Initialization :> (thirtyRandomStocks = 
RandomChoice[FinancialData["FTSE100", "Members"], 30];
fractionalChanges = 
Chop@Map[FinancialData[#, "FractionalChange", DatePlus[-360]] &, 
stockWeights = RandomInteger[{100, 10000}, 30];
allFChange = fractionalChanges[[All, All, 2]];
allWeightedFChanges = 
Table[WeightedData[allFChange[[All, i]], stockWeights], {i, 1, 
    Length[allFChange[[i, All]]], {i, 1, 

I get an "Initialization Time Out" error and can't figure out how to give the Manipulate more time to initialise.

Therefore, I have two questions:

  • How can I give Mathematica more time to initialise, or else ensure the Manipulate gets the necessary data for the calculations?
  • Note: This Manipulate will always be used within notebooks, so Free CDF limitations aren't important for me at this point.
  • Are there any suggestions you'd be willing to share to improve the code in general? I'm aware that if you look closely I'm not working with the data correctly; allWeightedFChanges doesn't really do what it should do.
  • 2
    $\begingroup$ First thing I'd do is to pay close attention to the reason of slow initialization. A quick guess is that this is due to FinancialData, so I'd start by caching it outside your Manipulate code if I were you. $\endgroup$ – Leonid Shifrin Feb 2 '13 at 16:46
  • $\begingroup$ @LeonidShifrin, I'd like to be able to use this Manipulate without having Initialization Cells if at all possible. Cormulion's answer below is probably the fastest way to do this. $\endgroup$ – Charlie Joey Hadley Feb 3 '13 at 17:28
  • $\begingroup$ Sure. Mu suggestion was anyway coming from general common sense and not necessarily taking into account your specific situation. $\endgroup$ – Leonid Shifrin Feb 3 '13 at 17:46
  • $\begingroup$ Understandable, I usually employ common sense when building things up and then it goes out the window when I attempt to dump everything within a Manipulate. DynamicModule would have provided me with more flexibility but I wanted a quick solution. Thanks again for commenting. $\endgroup$ – Charlie Joey Hadley Feb 3 '13 at 18:28
  • $\begingroup$ Sure, no problem. $\endgroup$ – Leonid Shifrin Feb 3 '13 at 18:37

Probably better to heed Leonid's advice to re-configure, but, with SynchronousInitialization -> False added I got this after a while:


| improve this answer | |
  • $\begingroup$ Thanks @cormullion, I guess I just need to adjust my DatePlus value so that "a while" is "a little while". $\endgroup$ – Charlie Joey Hadley Feb 3 '13 at 17:31
  • $\begingroup$ I have the same problem because of using Manipulate in my code. As Cormullion pointed out, when add the "SynchronousInitialization -> False" into the code, Initialization Time Out error can be solved. If you don't mind, please help me explain. Thanks in advanced! $\endgroup$ – Nguyen Ha Dec 22 '17 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.