SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue May 21, 2019 6:18 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Thu May 19, 2011 12:12 pm 
Offline

Joined: Tue May 17, 2011 12:08 pm
Posts: 5
Hello,
Is it realy possible to achieve Backtest at a tick level in a multitimeframe strategy ?
I would like to avoid any relation with OHLC as I do in the live execution.

For example :
Entry at market when these conditions happen :

- Cross between 2 MA (in 5 mn time frame)
AND
- Cross between 2 other MA (in 20mn time frame)

An important thing is that these conditions/crosses should be updated at each tick.

Exit (target or stop) at market (tick level) when these conditions happen :

- Cross between two other indicators (in 1 mn time frame)

An important thing is that these conditions/crosses should be updated at each tick.

Thanks for your feed back,


Top
 Profile  
 
PostPosted: Fri May 20, 2011 10:28 am 
Offline

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

The sample below shows how to use two pairs of SMAs (5 and 20 minute) and how to use "tick update" technique. The sample just outputs some info when 5 min or 20 min SMAs are crossing each other.
Code:
using System;
using System.Drawing;

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

public class MyStrategy : Strategy
{
   // 5 min SMAs
   SMA sma1_5min;
   SMA sma2_5min;
   
   // 20 min SMAs   
   SMA sma1_20min;
   SMA sma2_20min;
   
   // BarSeries - 5 and 20 min
   BarSeries Bars_5min;
   BarSeries Bars_20min;
   
   // current bars - 5 and 20 mins
   Bar currBar_5min;
   Bar currBar_20min;
   
   public override void OnStrategyStart()
   {
      Bars_5min = GetBars(BarType.Time, 300);
      Bars_20min = GetBars(BarType.Time, 1200);
      
      sma1_5min = new SMA(Bars_5min, 7);
      sma2_5min = new SMA(Bars_5min, 14);
      
      sma1_20min = new SMA(Bars_20min, 7);
      sma2_20min = new SMA(Bars_20min, 14);
   }

   public override void OnBarOpen(Bar bar)
   {
      // store the reference to the current bars      
      if (bar.Size == 300)
         currBar_5min = bar;
      
      if (bar.Size == 1200)
         currBar_20min = bar;
   }

   public override void OnQuote(Quote quote)
   {      
      // update the last bars in the series
      if (currBar_5min != null)
         Bars_5min.Add(currBar_5min);
      
      if (currBar_20min != null)
         Bars_20min.Add(currBar_20min);
      
      // check crossing for 5 min SMAs
      if (sma1_5min.Count == 0 || sma2_5min.Count == 0)
         return;      
      
      if (sma1_5min.Crosses(sma2_5min, Bar) == Cross.Above)
         Console.WriteLine("sma1_5min crosses above sma2_5min at " + Clock.Now);         
      
      if (sma1_5min.Crosses(sma2_5min, Bar) == Cross.Below)
         Console.WriteLine("sma1_5min crosses below sma2_5min at " + Clock.Now);
      
      // check crossing for 20 min SMAs
      if (sma1_20min.Count == 0 || sma2_20min.Count == 0)
         return;      
      
      if (sma1_20min.Crosses(sma2_20min, Bar) == Cross.Above)
         Console.WriteLine("sma1_20min crosses above sma2_20min at " + Clock.Now);         
      
      if (sma1_20min.Crosses(sma2_20min, Bar) == Cross.Below)
         Console.WriteLine("sma1_20min crosses below sma2_20min at " + Clock.Now);         
   }
}


Regards,
Sergey.


Top
 Profile  
 
PostPosted: Fri May 20, 2011 10:32 am 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
P.S. please move the logic from OnQuote to OnTrade handler if you build bars from trades.


Top
 Profile  
 
PostPosted: Tue May 24, 2011 1:48 pm 
Offline

Joined: Tue May 24, 2011 8:51 am
Posts: 1
Pretty Interesting post. Couldn't be written any better.I will forward this post to him. Pretty sure he will have a good read. Thanks for sharing! :lol:


Top
 Profile  
 
PostPosted: Sat May 28, 2011 9:11 am 
Offline

Joined: Tue May 17, 2011 12:08 pm
Posts: 5
Hello and thanks for your replies...
This sample shows that it is possible to code a strategy with multi time frame + with tick level decision on live market but will it work same on backtest ? Most of time, OHLC are use instead of tick level.
Regards


Top
 Profile  
 
PostPosted: Sat May 28, 2011 9:19 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6812
Hi,

there should be no difference between live trading and simulations. Of course you should have ticks stored in the historical db to run this example.

Regards,
Anton


Top
 Profile  
 
PostPosted: Mon May 30, 2011 10:10 am 
Offline

Joined: Tue May 17, 2011 12:08 pm
Posts: 5
OK, thanks for your answer.
In this case, OQ is probably the lonely soft whish is able to backtest with this granularity !
I will try this soon...


Top
 Profile  
 
PostPosted: Mon May 30, 2011 10:25 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6812
OQ can also backtest with order book / market depth granularity ...


Top
 Profile  
 
PostPosted: Thu Jun 23, 2011 11:18 am 
Offline

Joined: Tue May 17, 2011 12:08 pm
Posts: 5
Hello,
Now, I would like to backtest my strategy on historical data (Tick level) for DAX Future and BUND on years 2009/2010/2011.
Which datafeed in OQ can I use for such a kind of data ? Is there a free one or do I have to purchase it ?
Best regards,


Top
 Profile  
 
PostPosted: Thu Jun 23, 2011 11:30 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6812
Do you mean live feed or historical data?


Top
 Profile  
 
PostPosted: Thu Jun 23, 2011 11:32 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6812
I don't think a data provider would give you three years of good quality historical tick data for free. You can try to get some from IB for example.

Regards,
Anton


Top
 Profile  
 
PostPosted: Thu Jun 23, 2011 11:44 am 
Offline

Joined: Tue May 17, 2011 12:08 pm
Posts: 5
If it exits a good provider for this kind of historical date, I am ok to buy it...

I currently have a Kinetick and ZenFire connection on NinjaTrader, do you think it is possible to use it into OQ or to import tick data from NT into OQ ?
If yes, OQ should be able to rebuild bar from this imported historical, am I right ?


Top
 Profile  
 
PostPosted: Thu Jun 23, 2011 11:50 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6812
Hi,

you can import text files in OQ. Once you have historical tick data, OQ can either compress it and write to its historical data base, or build bars from trades on the fly when you backtest your strategy.

Regards,
Anton


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 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:  
cron
Powered by phpBB® Forum Software © phpBB Group