SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Wed Nov 21, 2018 3:23 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Feb 25, 2013 12:42 pm 
Offline

Joined: Sun Jun 01, 2008 1:18 pm
Posts: 32
Location: Paris France
Following code obviously generates compiler errors. :oops:
Idea is to control public variable declaration at compile (preprocessing) time...can this be done without going outside OQ (dll's etc.)?
public class M:UserIndicator//OQ 2 version 2.9.13
{
public const bool declarethis=true;
if(declarethis)public double[]Hugearray=new double[99999999];
public M(BarSeries input):base(input){Name="M";}
public override double Calculate(int index){/*some calculation*/if(declarethis)return Hugearray[Hugearray.Length-1];else return 0;}
}
public class MyStrategy:Strategy
{
if(M.declarethis)M Mvar;
public override void OnBar(Bar bar){if(M.delcarethis)if(Mvar.Last>0)/*do this*/;else /*do that*/;else /*Can't use Mvariable, it doesn't exist or waste any memory.*/;}
public override void OnStrategyStart(){if(M.delcarethis)M M=new M(Bars);}
}

_________________
Thx!!


Top
 Profile  
 
PostPosted: Mon Feb 25, 2013 12:55 pm 
Offline

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

You can always declare the variable but initialize it only if some flag is set to true. In this case memory will be wasted only when needed. Is it what you are looking for?

Regards,
Sergey.


Top
 Profile  
 
PostPosted: Mon Feb 25, 2013 1:08 pm 
Offline

Joined: Sun Jun 01, 2008 1:18 pm
Posts: 32
Location: Paris France
if(M.declarethis)M Mvar;
is the line of code we're needing to find a way to compile...
Would like to render this declaration conditional since otherwise it would seem to generate tons of meaningless Mvar.Ago(...) values in memory.
Or would
public override void OnStrategyStart(){if(M.delcarethis)M M=new M(Bars);}
prevent that?
The goal being to save memory during Solution Optimize runs that don't use Mvar.... :wink:

_________________
Thx!!


Last edited by ccguys on Mon Feb 25, 2013 1:25 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon Feb 25, 2013 1:21 pm 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Please try the following code:
Code:
#define declarethis

using System;
using System.Drawing;

using OpenQuant.API;
using OpenQuant.API.Plugins;
using OpenQuant.API.Indicators;

   public class M:UserIndicator//OQ 2 version 2.9.13
   {      
      #if declarethis
      public double[]Hugearray=new double[99999999];
      #endif
   
      public M(BarSeries input):base(input){Name="M";}
      public override double Calculate(int index)
      {
      /*some calculation*/
         #if declarethis
            return Hugearray[Hugearray.Length-1];
         #else
            return 0;
         #endif
      }
   }

   public class MyStrategy:Strategy
   {
      #if declarethis
      M Mvar;
      #endif
      
      public override void OnBar(Bar bar)
      {
         #if declarethis
            if(Mvar.Last>0)
               /*do this*/;
            else /*do that*/;
         #else
            /*Can't use Mvariable, it doesn't exist or waste any memory.*/;
         #endif
      }
      public override void OnStrategyStart()
      {
         #if declarethis
            M M=new M(Bars);
         #endif
      }
   }


if you remove or comment out the very first line - the indicator should not be declared.

Regards,
Sergey.


Top
 Profile  
 
PostPosted: Mon Feb 25, 2013 1:27 pm 
Offline

Joined: Sun Jun 01, 2008 1:18 pm
Posts: 32
Location: Paris France
:D
Gratitude for super-fast reply!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 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