SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Feb 22, 2020 4:27 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Sat Mar 01, 2008 11:57 pm 
Offline

Joined: Sat Mar 01, 2008 11:46 pm
Posts: 3
Hi,

I'm fairly new to programming in C# and very new to using OpenQuant. Now I know in the new version of OpenQuant you can have multiple strategies running. But i was wondering if there was a way to make references to methods, ect. across the 2 strategies. For example if Test1 strategy has a function inside the MyStrategy class, can Test2 strategy (they are indicated by the picture of blue dice, and might actually be called projects, which might be my whole problem) access that function?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 03, 2008 2:36 am 
Offline

Joined: Tue Oct 23, 2007 11:47 pm
Posts: 154
I'm not 100% about this, but I do not believe so.

If you want to have a "global variable" among 2 different strategies what I do is write to a text file in one strategy, and then the other strategy can read that text file


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 03, 2008 11:41 pm 
Offline

Joined: Sat Mar 01, 2008 11:46 pm
Posts: 3
That's what I thought.. also I was considering writing to a SQL server instead of a bunch of text files or one big one. But if anyone knows how to share variables/functions across strategies I would be very great full!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 04, 2008 3:34 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
A strategy (project) within a solution is compiled in a separate assembly, so that two strategies don't know about each other (thus even if you add static MyStrategy.MyGlobalVariable it would not help).

We can add static Hashtable Strategy.Global which will solve this problem.

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 1:42 am 
Offline

Joined: Sat Mar 01, 2008 11:46 pm
Posts: 3
So are you saying that it's not currently a feature and might be added?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 11:53 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
It's already added in our code base and will be available in the next build, but you can use a simple work around. Create an assmbly in VS and define a static class or a class with a public static variable / property. Then reference this assembly in your strategy and use this static variable accross the strategies. I think this should work.

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 29, 2008 9:30 am 
Offline

Joined: Sat Sep 27, 2003 8:53 am
Posts: 19
hi, has the static Hashtable been added in the latest build yet?
if so, can you please give an example of how to use it.
thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 30, 2008 12:12 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
Global["MyVariable"] = 3.14;

in one strategy

double Pi = (double)Global["MyVariable"];

in another.

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 16, 2008 8:30 pm 
Offline

Joined: Fri May 25, 2007 1:57 am
Posts: 24
Unfortunately, the example code fails. Strategy.Global doesn't seem to be shared among strategies.

Will the SmartQuant team confirm whether this is a real bug, and if so add it to their issue list?

Version: 2.5.4
Strategy 1:
Code:
   public override void OnStrategyStart()
   {
      Console.WriteLine("OnStrategyStart 1");
      Global["MyVar1"] = 3.14;
      Global["MyVar2"] = 3.15;
      Console.WriteLine("Global.Count " + Global.Count);
      foreach (object theEntry in Global)
         Console.WriteLine(theEntry);
   }


Strategy 2 (should be lower in the Solution Explorer so that it initializes after Strategy 1):
Code:
   public override void OnStrategyStart()
   {
      Console.WriteLine("OnStrategyStart 2");
      Console.WriteLine("Global.Count " + Global.Count);

      foreach (object theEntry in Global)
         Console.WriteLine(theEntry);
         
      double myVar1 = (double) Global["MyVar1"];
      Console.WriteLine("myVar1 " + myVar1);
   }


Output:
Code:
OnStrategyStart 1
Global.Count 2
System.Collections.DictionaryEntry
System.Collections.DictionaryEntry
OnStrategyStart 2
Global.Count 0


After Global.Count reaches 2 in Strategy 1 it still shows 0 in Strategy 2. This is not due to a race condition as Global.Count is 0 in subsequent OnBar events in Strategy 2.

Looks like Strategy.Global is not shared among strategies.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 1:09 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi,

Yes, this is a bug in a case of OnStrategyStart methods only.
We will fix it in the next release of OQ.

Regards,
Alex

_________________
SmartQuant Development Team


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

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 5 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