SmartQuant Discussion

SMA, SMD without pre-known length
Page 1 of 1

Author:  Olive [ Mon Dec 08, 2008 6:13 pm ]
Post subject:  SMA, SMD without pre-known length

I want to accumulate a series of data points, and then find out its mean and standard deviation...without first knowing how many data points I would have, how to I do it with OQ? Currently to construct an SMA or SMD, you will have to specify the length in the constructor.

Author:  Baraz Sergey [ Mon Dec 08, 2008 6:41 pm ]
Post subject: 


Please use the following sample to find std. dev of a series:
double stdDev = new SMD(mySeries, mySeries.Count).Last;


Author:  Olive [ Mon Dec 08, 2008 6:50 pm ]
Post subject: 

Great, thanks!!

Author:  kkkwj [ Tue Dec 09, 2008 12:53 am ]
Post subject: 

That's a really elegant way of getting the standard deviation. I've always created the SMD series along with all the other series in OnStrategyStart.

But from your code it looks like I can execute that code at any time during the strategy (say at the end of my strategy in OnStrategyStop). And it also looks like I can execute that line multiple times during the strategy too, right?

Does the act of creating the new SMD series with a looong length that is equal to the underlying series immediately calculate a fresh value for the StdDev from the existing values in the underlying series?

Author:  Olive [ Tue Dec 09, 2008 1:56 am ]
Post subject:  Strange...

The formula works, however I am not sure if it is getting all the data points...I used a running counter to keep track and confirm how many data points are inserted to the time series:

totalBar++; // this should end up equal to mySeries.Count
mySeries.add( myInstrument.Bar.DateTime, myValue )

and then later I used Sergey's formula to compute standard deviation of myValues:

double stdDev = new SMD(mySeries, mySeries.Count).Last;

However, I learned that mySeries.Count is less then totalBar...I would expect them to be the this a bug? in my case, totalBar is 96670, mySeries.Count is 93940.

Author:  mikembb [ Fri Dec 06, 2019 2:04 pm ]
Post subject:  Re: SMA, SMD without pre-known length


would be good, if we get another option for TimeSeries class in OQ2014, that would give StdDev for the whole population and not just for the sample, like TimeSeries.GetStdDev does it right now. So, then we would have TimeSeries.GetStdDev for the sample and TimeSeries.GetStdDevPopulation for the whole data set...

As you see here: it is just the divisor different.


Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group