RE: Basic programming

*To*: mathgroup at smc.vnet.net*Subject*: [mg93583] RE: [mg93576] Basic programming*From*: "David Park" <djmpark at comcast.net>*Date*: Sun, 16 Nov 2008 07:03:30 -0500 (EST)*References*: <18026241.1226748141587.JavaMail.root@m02>

First we extract some financial data and get the minimum and maximum values: djidata = Part[#, 2] & /@ FinancialData["^DJI", {"Jun. 26, 2008", "Nov. 14, 2008"}]; {Min[djidata], Max[djidata]} {8175.77,11782.4} Next we calculate the 10 day trailing standard deviation: dji10daystd = StandardDeviation /@ Partition[djidata, 10, 1]; {Min[dji10daystd], Max[dji10daystd]} {95.562,878.838} Finally we calculate the cumulative standard deviation: djicumstd = Table[StandardDeviation[Take[djidata, {1, i}]], {i, 2, 100}]; {Min[djicumstd], Max[djicumstd]} {49.5963,1134.97} Then I use the Presentations package to plot these all in one plot with a special scale for the standard deviation curves on the right. Needs["Presentations`Master`"] Draw2D[ {ListDraw[djidata], Red, ListDraw[Rescale[#, {0, 1200}, {8000, 12000}] & /@ dji10daystd, DataRange -> {9, 100}, Joined -> True], ListDraw[Rescale[#, {0, 1200}, {8000, 12000}] & /@ djicumstd, DataRange -> {2, 100}, Joined -> True], Black, Text["10 Day", {82, 9500}, {-1, 0}], Text["Cumulative", {86, 11000}, {-1, 0}]}, AspectRatio -> .4, Frame -> True, FrameTicks -> {{Automatic, CustomTicks[ Rescale[#, {0, 1200}, {8000, 12000}] &, {0, 1200, 200, 5}, CTNumberFunction -> (Style[#, Red] &)]}, {Automatic, Automatic}}, FrameLabel -> {{"DJI", "STD"}, {"Days following Jun 26, 2008", None}}, PlotLabel -> Style["DJI and Trailing Standard Deivation", 20], BaseStyle -> {FontSize -> 12}, ImageSize -> 600] Peter Lindsay at the Mathematical Institute in the University of St Andrews [ www.mcs.st-and.ac.uk ] has kindly undertaken to maintain an archive that provides downloadable notebooks and PDF files for various Presentations solutions that have appeared on MathGroup. http://blackbook.mcs.st-and.ac.uk/~Peter/djmpark/html/ David Park djmpark at comcast.net http://home.comcast.net/~djmpark From: BionikBlue [mailto:frankflip at hotmail.com] Hey I'm a beginner in mathematica and I'm trying to code a little something but can't seem to be able to make it work... I know its pretty basic and that's exactly my problem since the mathematica help is a bit overkill for what I need. I have daily stock prices for a stock on a 100 day period, I want to compute the standard deviation for a rolling 10 days period for the whole list of data. So basically, I would like to do something like this : stdev(1;;10) then stdev(2;;11) until stdev(91;;100) and get the results in a list Id also like to get it another way, by starting with only one observation and building my standard deviation calculation until I have my whole rolling period built up, for example : stdev(1) stdev(1,2) stdev(1,2,3) until stdev(1;;10) then same as before, roll the period until the end of dataset and produce a list of the results. Thanks for the help, if what I wrote is not clear enough let me know, Ill try to explain it in more details!