MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Basic programming

  • To: mathgroup at
  • Subject: [mg93583] RE: [mg93576] Basic programming
  • From: "David Park" <djmpark at>
  • 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]}

Next we calculate the 10 day trailing standard deviation:

dji10daystd = StandardDeviation /@ Partition[djidata, 10, 1];
{Min[dji10daystd], Max[dji10daystd]}

Finally we calculate the cumulative standard deviation:

djicumstd = 
  Table[StandardDeviation[Take[djidata, {1, i}]], {i, 2, 100}];
{Min[djicumstd], Max[djicumstd]}

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.


  ListDraw[Rescale[#, {0, 1200}, {8000, 12000}] & /@ dji10daystd, 
   DataRange -> {9, 100},
   Joined -> True],
  ListDraw[Rescale[#, {0, 1200}, {8000, 12000}] & /@ djicumstd, 
   DataRange -> {2, 100},
   Joined -> True],
  Text["10 Day", {82, 9500}, {-1, 0}],
  Text["Cumulative", {86, 11000}, {-1, 0}]},
 AspectRatio -> .4,
 Frame -> True,
 FrameTicks -> {{Automatic, 
     Rescale[#, {0, 1200}, {8000, 12000}] &, {0, 1200, 200, 5}, 
     CTNumberFunction -> (Style[#, Red] &)]}, {Automatic, 
 FrameLabel -> {{"DJI", "STD"}, {"Days following Jun 26, 2008", 
 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
[ ] has kindly undertaken to maintain an archive that
provides downloadable notebooks and PDF files for various Presentations
solutions that have appeared on MathGroup. 

David Park
djmpark at 

From: BionikBlue [mailto:frankflip at] 

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

So basically, I would like to do something like this :
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 :
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!

  • Prev by Date: Re: Basic programming
  • Next by Date: Re: DSolve and assuming: wrong solution found by Mathematica 6. A bug
  • Previous by thread: Re: Basic programming
  • Next by thread: Machine-precision Exp[] function