[Date Index]
[Thread Index]
[Author Index]
Re: Basic programming
*To*: mathgroup at smc.vnet.net
*Subject*: [mg93590] Re: Basic programming
*From*: "sjoerd.c.devries at gmail.com" <sjoerd.c.devries at gmail.com>
*Date*: Sun, 16 Nov 2008 07:04:49 -0500 (EST)
*References*: <gfmaak$g6c$1@smc.vnet.net>
As always, there will be a multitude of possible solutions. A
functional programming style solution would be:
Map[
StandardDeviation,
Partition[yourData, 10, 1]
]
or, in a more procedural or imperative programming style:
Table[
StandardDeviation[
Take[yourData, {i, i + 9}]
],
{i, 1, Length[yourData] - 9}
]
or even more procedural (and ugly):
result = {};
Do[
b = StandardDeviation[ yourData[[i ;; i + 9]] ];
result = Append[result, b];,
{i, 1, Length[yourData] - 9}
]
result
yourData should be an array with your data set, e.g. yourData={2.2,
3.7, -1.3, 4.5, 9.0, 2.2, 2.4, 5.6, 9.8, 12.3,3.8} ;
With respect to your second question: are you sure you want to
calculate the standard deviation of a single data point? Doesn't make
much sense to me. Anyway, to do this, the first example can be
modified thus:
Map[
StandardDeviation,
Partition[yourData, 10, 1, {-1, 1}, {}]
]
The others are easy to modify as well, but will become even more ugly
in the process.
Cheers -- Sjoerd
On Nov 15, 1:03 pm, BionikBlue <frankf... at hotmail.com> wrote:
> Hey I'm a beginner in mathematica and I'm trying to code a little somethi=
ng 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 comp=
ute 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 rolli=
ng 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: Basic programming**
| |