SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Thu Oct 22, 2020 6:47 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Aug 09, 2016 3:32 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Hi SQ,

Is it possible use the MyStrategy.cs to add all accordingly Instruments and Bars a strategy will use (rather then adding them via the Optimization.cs, Backtest Scenario.cs and/or Realtime Scenario.cs files)?

Or would I run into a technical issue doing this?
I tried doing this but could not get it to compile properly, I'm not sure if it won't compile because there is an error in my code or if this is just not supported in OQ2014.

(Note: It still think its a great feature in OQ2014 that I can add these items via the Optimization.cs and Scenario.cs files, but sometimes I prefer to add them entirely via the MyStrategy.cs file for various reasons.)

Thanks.


Top
 Profile  
 
PostPosted: Tue Aug 09, 2016 1:57 pm 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 578
In common usage you should not add instruments in strategy if they can be added in scenario.


Top
 Profile  
 
PostPosted: Wed Aug 10, 2016 3:44 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
My strategy uses dozens of different Bar-Types, Bar-Sizes and Symbols.

I'm finding human error to be an issue when I try adding all these items in an identical manner to the three separate .cs files (AKA: the Optimization.cs and Backtest Scenario.cs and Realtime Scenario.cs).

Any tips/examples on how to add all these items to the MyStrategy.cs file so I don't have to add them three separate times?

Thanks.


Top
 Profile  
 
PostPosted: Wed Aug 10, 2016 11:07 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
You can add a class with a static collection of symbols or instrumens that you can use everywhere in your solution.

namespace OpenQuant
{
public class Watchlist
{
public static string[] Symbols = { "IBM", "AAPL" };
}
}


Then in any scenario

foreach(string symbol in Watchlist.Symbols)
{
Console.WriteLine(symbol);
}

Regards,
Anton


Top
 Profile  
 
PostPosted: Wed Aug 10, 2016 11:46 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
Added to FAQ

How to share information between projects in a solution


You can have several projects in your solution using identical input data. The most common case is the same list of strategy instruments that you add to a strategy in Backtest, Optimization and RealTime scenario files. Usually it’s not convenient to make changes in each of these scenario files if you want to add or remove a symbol from the strategy.

In this case you can add a class in any of solution projects (for example to the strategy project) with a static field or property in this class that you can access in any scenario in your solution.

For example you can add Watchlist.cs file with the following code

using System;

using SmartQuant;

namespace OpenQuant
{
public class Watchlist
{
public static string[] Symbols = { "IBM", "AAPL" };
}
}

And then in any scenario file you can write

foreach(string symbol in Watchlist.Symbols)
{
Console.WriteLine(symbol);
// do something with symbol

}

Or simply Strategy.AddInstruments(Watchlist.Symbols).


Top
 Profile  
 
PostPosted: Wed Aug 10, 2016 8:06 pm 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Great. Will this also work the same for adding many different types of bars at once? For instance, enabling the strategy to use both 1 minute bars and 5 minute bars at the same time?

Either way, would really appreciate if you could post (or ship OQ2014 with) a full solution file off all this.
Doing all this exactly right is highly mission critical (especially when switching from backtesting to live trading) so it would be great to have a full solution file demonstrating the exact details.

Thanks Anton


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 4 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:  
Powered by phpBB® Forum Software © phpBB Group