SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Wed Oct 28, 2020 12:17 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Standarddeviation
PostPosted: Thu Mar 03, 2011 12:37 am 
Offline

Joined: Thu Mar 16, 2006 12:15 pm
Posts: 184
If i would like to compute the standarddeviation of an indicator over a n-bar period how to program this?

I know GetstdDev(datetime1, datetime2). But how to obtain the current datetime and especially the datetime n-bars ago?

_________________
Expect the unexpected. May your MM/RM be with you.


Top
 Profile  
 
 Post subject: Re: Standarddeviation
PostPosted: Thu Mar 03, 2011 7:09 am 
Offline

Joined: Mon Sep 08, 2008 2:20 am
Posts: 40
Location: Toronto, Ontario, Canada
Just include the dll in your project and pass the bar in to the function and presto chango you have StDev.
STDDEV Standard Deviation

http://ta-lib.org/

Let me know if you need a code post.

8)

CS


Top
 Profile  
 
 Post subject: Re: Standarddeviation
PostPosted: Thu Mar 03, 2011 7:48 am 
Offline

Joined: Thu Mar 16, 2006 12:15 pm
Posts: 184
I know Ta lib since many years. But I do not need it. But could you provide a code example with GetstdDev?

_________________
Expect the unexpected. May your MM/RM be with you.


Top
 Profile  
 
 Post subject: Re: Standarddeviation
PostPosted: Thu Mar 03, 2011 8:48 am 
Offline

Joined: Thu Mar 16, 2006 12:15 pm
Posts: 184
I think this should work? Ago(0) should be the current bar?

double mystandarddeviation = myseries.GetStdDev(Bars.Ago(7).DateTime, Bars.Ago(0).DateTime);

_________________
Expect the unexpected. May your MM/RM be with you.


Top
 Profile  
 
 Post subject: Re: Standarddeviation
PostPosted: Thu Mar 03, 2011 8:50 am 
Offline

Joined: Mon Sep 08, 2008 2:20 am
Posts: 40
Location: Toronto, Ontario, Canada
I'm running an optimization right now so I can't debug the code to make sure... but I think this is what you're shooting for.

Code:
double stdev = ema.GetStdDev(ema.Ago(10).DateTime,ema.Ago(0).DateTime);


Code:
double stdev = ema.GetStdDev(ema.Ago(10),ema.Ago(0));


The docs say:

Indicator..::..GetStdDev Method (DateTime, DateTime)
Returns Standard Deviation of the series in between dateTime1 and dateTime2

public double GetStdDev(DateTime dateTime1, DateTime dateTime2)

Indicator..::..GetStdDev Method (Int32, Int32)
Returns Max of the series in between index1 and index2

public double GetStdDev( int index1,int index2)


Top
 Profile  
 
 Post subject: Re: Standarddeviation
PostPosted: Fri Mar 04, 2011 12:29 am 
Offline

Joined: Thu Mar 16, 2006 12:15 pm
Posts: 184
works. How to avoid out of range error?

_________________
Expect the unexpected. May your MM/RM be with you.


Top
 Profile  
 
 Post subject: Re: Standarddeviation
PostPosted: Sun Mar 06, 2011 6:43 am 
Offline

Joined: Mon Sep 08, 2008 2:20 am
Posts: 40
Location: Toronto, Ontario, Canada
Code:
using OpenQuant.API;
using OpenQuant.API.Indicators;
using System;
using System.Drawing;

public class MyStrategy : Strategy
{
   double stdev;
   TimeSeries ts;
   
   public override void OnStrategyStart()
   {      
      ts = new TimeSeries();
   }

   public override void OnBar(Bar bar)
   {

      ts.Add(bar.DateTime,bar.Close);
      
      if (ts.Contains(bar.DateTime))
      {
         if(Bars.Count>11)
         {
            double val = ts.GetStdDev(Bars.Ago(10).DateTime,Bars.Ago(1).DateTime);
            Console.WriteLine(val);
            //Draw(val,3);
         }
      }
   }
}


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

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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