SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Oct 08, 2024 5:07 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Dec 08, 2008 6:13 pm 
Offline

Joined: Mon Nov 24, 2008 8:44 pm
Posts: 36
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2008 6:41 pm 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Hi,

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

Regards,
Sergey.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2008 6:50 pm 
Offline

Joined: Mon Nov 24, 2008 8:44 pm
Posts: 36
Great, thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2008 12:53 am 
Offline

Joined: Thu Jun 08, 2006 3:56 pm
Posts: 537
Location: BC Canada
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?


Top
 Profile  
 
 Post subject: Strange...
PostPosted: Tue Dec 09, 2008 1:56 am 
Offline

Joined: Mon Nov 24, 2008 8:44 pm
Posts: 36
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:

OnBarSlice()
{
...
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 same...is this a bug? in my case, totalBar is 96670, mySeries.Count is 93940.


Top
 Profile  
 
PostPosted: Fri Dec 06, 2019 2:04 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 273
Hi,

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: http://csharphelper.com/blog/2015/12/make-an-extension-method-that-calculates-standard-deviation-in-c/ it is just the divisor different.

Thanks
Mike

_________________
Best regards
Mike


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group