SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Sep 29, 2020 8:38 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Dec 11, 2012 5:39 pm 
Offline

Joined: Tue Sep 11, 2012 12:41 pm
Posts: 41
Is there a way to only fire the OnTrade or OnQuote events for some selected instruments?

To be more specific, I have a trading strategy which is trading in intra-day, but the universe and other indicators are calculated daily. I want the monitored instruments fulfilled some criteria (like liquidity). The total number of the universe is 3500, and my criteria will reduce this number to around 1700. I am using IQfeed and the max symbol number is 1800. Therefore, I don't want to monitor every instruments in this 3500 universe, but only these 1700 instruments. Is there a way to do this automatically, in both live trading and back testing?

Thanks a lot in advance

JC


Top
 Profile  
 
PostPosted: Tue Dec 11, 2012 6:16 pm 
Offline

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

If I've understood you correctly you should add all 3500 instruments to your project.Then in the scenario.cs remove all instruments from the project and add 1700 back using the criteria. Please see this thread that shows how to add/remove instruments from the scenario:
viewtopic.php?f=64&t=8636

Regards,
Sergey.


Top
 Profile  
 
PostPosted: Tue Dec 11, 2012 6:20 pm 
Offline

Joined: Tue Sep 11, 2012 12:41 pm
Posts: 41
Baraz Sergey wrote:
Hi,

If I've understood you correctly you should add all 3500 instruments to your project.Then in the scenario.cs remove all instruments from the project and add 1700 back using the criteria. Please see this thread that shows how to add/remove instruments from the scenario:
viewtopic.php?f=64&t=8636

Regards,
Sergey.


Hi Sergey,

Thanks a lot for your quick reply.

I've looked through this thread about Scenario functionality before. From my understanding, I think it will do a one-off selection of instruments and fix this selected universe until the end of the backtest. Is my understanding right or wrong? Can the scenario functionality select instruments everyday?

Thanks for your kind help

JC


Top
 Profile  
 
PostPosted: Wed Dec 12, 2012 9:47 am 
Offline

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

You can stop the strategy at the end of the day in the strategy code by calling StopStrategy method.

Meanwhile in the scenario.cs you can call Start several times (in while cycle for example), selecting new instruments for the new day each time.

Regards,
Sergey.


Top
 Profile  
 
PostPosted: Wed Dec 12, 2012 12:37 pm 
Offline

Joined: Tue Sep 11, 2012 12:41 pm
Posts: 41
Baraz Sergey wrote:
Hi,

You can stop the strategy at the end of the day in the strategy code by calling StopStrategy method.

Meanwhile in the scenario.cs you can call Start several times (in while cycle for example), selecting new instruments for the new day each time.

Regards,
Sergey.



Thanks a lot for your help. This is exactly what I want. Thank you so much!


Top
 Profile  
 
PostPosted: Tue Dec 18, 2012 5:27 pm 
Offline

Joined: Tue Sep 11, 2012 12:41 pm
Posts: 41
I tried to do this in a loop, but it seems to be not very well. I can see the strategy runs several times(equal to days number), but in Performance and Result, it only keep the last day's result rather than the entire Simulation period.

I modify the Solution.StartDate in a for loop, and run the strategy after I selected instruments. In my strategy, I stop the strategy after a certain time. This is my codes:

Code:
   public override void Run()
   {
      DateTime tempStart = Solution.StartDate;
      tempStart = tempStart.AddWorkDays(-1).AddWorkDays(1);
      for(DateTime tempDate = tempStart;tempDate<Solution.StopDate;tempDate = tempDate.AddWorkDays(1))
      {
         Project project = Solution.Projects["123"];
         project.ClearInstruments();
         int totalNum = 0;
         foreach (Instrument instrument in InstrumentManager.Instruments)
         {
            if (instrument.Type == InstrumentType.Stock)
            {
               DateTime datetime1 = tempDate;
               DateTime datetime2 = datetime1.AddWorkDays(-(23+1));
               BarSeries series = DataManager.GetHistoricalBars(instrument,datetime2,datetime1,BarType.Time,86400);
               if ((series.Count>(23)))
               {
                  ......
                  project.AddInstrument(instrument);
                  totalNum++;
               }
            }
         }
         Console.Out.WriteLine("On "+tempDate+" "+totalNum+" is being monitored");
         Solution.StartDate = tempDate.AddWorkDays(1);
         Start();
      }
   }


Could you please give me some advice in how to deal with this problem, to keep all the results when run strategy several times? Thanks a lot in advance.


Regards,

JC


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 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