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:
Manipulate[
Grid[
{{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"]},
{Pane[
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]] &,
thirtyRandomStocks];
stockWeights = RandomInteger[{100, 10000}, 30];
allFChange = fractionalChanges[[All, All, 2]];
allWeightedFChanges =
Table[WeightedData[allFChange[[All, i]], stockWeights], {i, 1,
Min[Table[
Length[allFChange[[i, All]]], {i, 1,
Length[allFChange]}]]}];)]
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
Manipulategets the necessary data for the calculations? - Note: This
Manipulatewill 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;
allWeightedFChangesdoesn't really do what it should do.

FinancialData, so I'd start by caching it outside yourManipulatecode if I were you. – Leonid Shifrin Feb 2 at 16:46Manipulate.DynamicModulewould have provided me with more flexibility but I wanted a quick solution. Thanks again for commenting. – Martin John Hadley Feb 3 at 18:28