SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sun Sep 15, 2019 8:45 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Dec 31, 2010 11:27 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
This scenario shows how to filter and add the most liquid stocks into strategy project
Code:
public class MyScenario : Scenario
{
   public override void Run()
   {   
      // get reference to strategy project
      
      Project project = Solution.Projects[0];
      
      // clear project instrument list
      
      project.ClearInstruments();
      
      // add most liquid stocks to instrument list
      
      foreach (Instrument instrument in InstrumentManager.Instruments)
         if (instrument.Type == InstrumentType.Stock)
         {
            BarSeries series = DataManager.GetHistoricalBars(instrument, BarType.Time, 86400);
         
            if (series.Count != 0 && series.Last.Volume > 50000000)
            {
               Console.WriteLine("Adding " + instrument);
            
               project.AddInstrument(instrument);
            }
         }
      
      // start backtest
      
      Start();
   }
}


Top
 Profile  
 
PostPosted: Sun Jan 23, 2011 11:17 pm 
Offline

Joined: Mon Oct 31, 2005 12:47 pm
Posts: 37
It seems you cannot run a Solution without a Market Data interval and Instrument already selected in the Solution Explorer (i.e. you cannot solely Add the instruments programmatically via the Scenario and leave the Solution Explorer instrument list and market data interval empty).

An error is generated "The Solution can not start because it has no selected requests. You should add requests to the Solution."


Top
 Profile  
 
PostPosted: Sun Jan 23, 2011 11:53 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
Thanks, will check and fix this. Meanwhile you can add any instrument manually and then call ClearInstruments in the beginning of your scenario.

Regards,
Anton


Top
 Profile  
 
PostPosted: Thu May 26, 2011 8:30 am 
Offline

Joined: Mon Feb 21, 2011 10:46 am
Posts: 48
I've tried the scenario demo and found out that after the backtest ended, the instrument list in solution explorer had not changed. It seems that the scenario adds the instruments to the project dynamically and removed them after the backtest ends? How could the scenario add the instruments permanently to the project's instrument list?


Top
 Profile  
 
PostPosted: Thu May 26, 2011 11:24 am 
Offline

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

The scenario doesn't change startup solution/project settings, you can change them only manually before strategy start. If the scenario changed the startup settings, it would be too hard to debug the scenario, since after each incorrect run you would need to manually rollback all "wrong" changes. So we decided that the scenario changes only runtime solution/project settings, while startup settings you configure manually.

Regards,
Sergey.


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