SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Wed Oct 28, 2020 11:44 am

All times are UTC + 3 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Oct 29, 2013 5:38 pm 

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Sometimes tick data is not available and backtesting is done on Daily data. In this case one may want to choose in which order Open, Close, High and Low prices are simulated, since it may have an impact on the execution of orders. The following sample shows how to generate "fake" trades in OnStrategyStart handler, that will be simulated. OHLC or OLHC order is choosen using "High - Close < Close - Low" condition. In this case FillOnBar property of Simulation (Execution) provider should be set to false and FillOnTrade to true. The same technique can be used to simulate quotes as well.

Note, that EmitTrade method doesn't call OnTrade handler directly, it schedules the trade to be simulated as a normal trade, putting it in Simulation queue.

using System;
using System.Drawing;

using OpenQuant.API;
using OpenQuant.API.Indicators;

public class MyStrategy : Strategy
   public TimeSpan SessionStart = new TimeSpan(9, 0, 0);
   public TimeSpan SessionEnd = new TimeSpan(17, 30, 0);
   public override void OnStrategyStart()
      if (Mode == StrategyMode.Simulation)
         // iterate through historical daily bars and generate trades to be simulated         
         foreach (Bar bar in DataManager.GetHistoricalBars(Instrument, DateTime.MinValue, DateTime.MaxValue, BarType.Time, 86400))
            DateTime sessionStartTime = bar.DateTime.Add(SessionStart);
            DateTime sessionEndTime = bar.DateTime.Add(SessionEnd);
            // generate a trade at Open
            EmitTrade(new Trade(sessionStartTime, bar.Open, 1));            
            // generate 2 trades at High and Low, in user defined order
            if (bar.High - bar.Close < bar.Close - bar.Low)
               EmitTrade(new Trade(sessionStartTime.AddHours(1), bar.Low, 1));                     
               EmitTrade(new Trade(sessionStartTime.AddHours(2), bar.High, 1));
               EmitTrade(new Trade(sessionStartTime.AddHours(1), bar.High, 1));                     
               EmitTrade(new Trade(sessionStartTime.AddHours(2), bar.Low, 1));
            // generate a trade at Close
            EmitTrade(new Trade(sessionEndTime, bar.Close, 1));

   public override void OnTrade(Trade trade)

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

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