[Date Index]
[Thread Index]
[Author Index]
RE: Basic programming
*To*: mathgroup at smc.vnet.net
*Subject*: [mg93588] RE: [mg93576] Basic programming
*From*: "Richard Hofler" <rhofler at bus.ucf.edu>
*Date*: Sun, 16 Nov 2008 07:04:26 -0500 (EST)
*References*: <200811151103.GAA16591@smc.vnet.net>
Hi,
I'm betting that you'll get many useful answers. Here's one solution
that I hope will help you.
One starting point to give you the rolling std. deviation is to create a
function that outputs three values:
{the location of the 1st element used to calculate the std. dev., the
location of the last element used to calculate the std. dev., the std.
dev.}
lst = {1,20,3,40,5,60,7,80,9,100,11,120,5,7,90};
(* You might want to look up SetPrecision in the Documentation Center *)
out[i_]:={i,i+9,SetPrecision[StandardDeviation[lst[[i;;i+9]]],4]}
Then, evaluate the function for several ranges of elements in your list.
out[1]
{1,10,35.90}
out[2]
{2,11,35.06}
out[3]
{3,12,43.92}
Now that you see how it works, here's the concise method:
Table[out[i],{i,1,6}]
{{1,10,35.90},{2,11,35.06},{3,12,43.92},{4,13,43.72},{5,14,45.25},{6,15,45.84}}
HTH,
Richard Hofler
________________________________
From: BionikBlue [mailto:frankflip at hotmail.com]
Sent: Sat 11/15/2008 6:03 AM
To: mathgroup at smc.vnet.net
Subject: [mg93588] [mg93576] Basic programming
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!
Prev by Date:
**Re: Basic programming**
Next by Date:
**Re: Basic programming**
Previous by thread:
**Re: Basic programming**
Next by thread:
**Re: Re: LatticeReduce**
| |