SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Sep 26, 2020 10:29 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Dec 17, 2012 5:18 pm 
Offline

Joined: Tue Sep 11, 2012 12:41 pm
Posts: 41
I want to do the back-test for a strategy where I need to select instruments everyday as described in viewtopic.php?f=60&t=10414

In Scenario.cs, I need to request historical daily data until the simulation time, and use the data to select instruments.

Code:
foreach (Instrument instrument in InstrumentManager.Instruments)
{
   if (instrument.Type == InstrumentType.Stock)
   {
      DateTime datetime1 = Clock.Now;
      DateTime datetime2 = datetime1.AddDays(-(MALength+MAFilter+1));
      BarSeries series = DataManager.GetHistoricalBars(instrument,datetime1,datetime2,BarType.Time,86400);
...
   }
}


I found, under simulation mode, this Clock.Now returns the real time but not the desired simulation time. Is this normal? Is there any other methods could tell me the simulation time in Scenario.cs?

Thanks a lot for any help.


Regards,

JC


Top
 Profile  
 
PostPosted: Mon Dec 17, 2012 6:07 pm 
Offline

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

In scenario.cs Clock is always in realtime mode, since the simulation has not started yet. But you can use Solution.StartDate or Solution.StopDate to obtain the timestamp of the beginning or the end of the Simulation. Hope it will be heplful.

Regards,
Sergey.


Top
 Profile  
 
PostPosted: Mon Dec 17, 2012 6:21 pm 
Offline

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

In scenario.cs Clock is always in realtime mode, since the simulation has not started yet. But you can use Solution.StartDate or Solution.StopDate to obtain the timestamp of the beginning or the end of the Simulation. Hope it will be heplful.

Regards,
Sergey.


Thanks a lot for your help, Sergey.

I will have a try to see whether I can make it. Do you mean I should stop strategy at the end of day, and set Solution.StartDate the next day, and run again?

Thanks.


JC


Top
 Profile  
 
PostPosted: Tue Dec 18, 2012 9:42 am 
Offline

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

Maybe I missunderstood what you are trying to do. I guess that you start your strategy in the scenario for each day separately? But in this case you should have some variable in the scenario code telling you the current day, no?

Also in OnStrategyStop handler of the strategy code you can "remember" the stop date in some static variable and later use in the scenario.

Regards,
Sergey.


Top
 Profile  
 
PostPosted: Tue Dec 18, 2012 1:15 pm 
Offline

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

Maybe I missunderstood what you are trying to do. I guess that you start your strategy in the scenario for each day separately? But in this case you should have some variable in the scenario code telling you the current day, no?

Also in OnStrategyStop handler of the strategy code you can "remember" the stop date in some static variable and later use in the scenario.

Regards,
Sergey.



Yes, I am trying to use several filter to select my universe everyday. So it is like: select instruments in scenario, run strategy for that day, select again for next day, run again,...

Thank you very much for your hints. I will try to do this using static variable as you said.

Regards,

JC


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