SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Mon Dec 16, 2019 6:48 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Fri Nov 13, 2015 1:04 pm 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Hi Smartquant,

I’m backtesting a futures contract (in OQ 2014) that has a minimum tick size of .25, however the backtest results are showing my trades closed at prices that are not multiples of .25 (such as 2030.27 and 2030.68).

Any idea why this is happening?

(FYI: I checked the historical data I uploaded for the symbol and its all in multiples of .25 as shown in attached 1.jpg. I also made sure the TickSize was set to 0.25 in the Properties tab as shown in attached screenshot 2.jpg)


Thanks!


Attachments:
2.jpg
2.jpg [ 20.79 KiB | Viewed 6554 times ]
1.jpg
1.jpg [ 71.39 KiB | Viewed 6554 times ]
Top
 Profile  
 
PostPosted: Fri Nov 13, 2015 3:04 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
I guess if you are talking about limit orders and have FillAtLimitPrice option set to true, then the simulator fills you with limit order price and doesn't take tick size into account. So I suggest you set limit price in accordance with tick size.

Regards,
Anton


Top
 Profile  
 
PostPosted: Mon Nov 16, 2015 3:59 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
I see.

Can you please type out the exact code I'd need to write in order set a limit order’s limit price to be whatever the best bid price is at the time the limit order is placed?

Would really appreciate the example.

Thanks!


Top
 Profile  
 
PostPosted: Mon Nov 16, 2015 11:33 am 
Offline

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

I am not sure your question is relevant to our discussion above and perhaps I am missing something but I guess

BuyLimit(100, Instrument.Bid.Price)

that's it.

Instrument.Bid property holds the last best bid for the instrument.

Regards,
Anton


Top
 Profile  
 
PostPosted: Mon Nov 16, 2015 10:29 pm 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
That solved it, thanks!


Top
 Profile  
 
PostPosted: Fri Nov 20, 2015 6:18 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
False alarm, I did not figure out how to fix this after all:)

I ran a backtest of the "BollingerBands" Solution (that came with OQ 2014) on a Future with a minimum tick size of 0.25, but the backtest results show certain trades closed at prices that are not multiples of 0.25. Can you please type out the exact code I'd write to get the mentioned "BollingerBands" solution to recognize the Future it is trading has a minimum Tick size of 0.25?

(FYI: I'm not sure if the code to do this is something I should add to the Scenario.cs file, MyStrategy.cs file or somewhere else.)

Thanks


Top
 Profile  
 
PostPosted: Fri Nov 20, 2015 8:17 am 
Offline

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

I think all you need to do is to round sma.Last to 0.25 in

if (Position.Side == PositionSide.Long)
exitOrder = SellLimitOrder(Instrument, Qty, sma.Last, "Exit");
else
exitOrder = BuyLimitOrder(Instrument, Qty, sma.Last, "Exit");

in BollingerBands example.

Regards,
Anton


Top
 Profile  
 
PostPosted: Fri Nov 20, 2015 1:11 pm 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
How do I round sma.Last to 0.25?


Top
 Profile  
 
PostPosted: Fri Nov 20, 2015 5:59 pm 
Offline

Joined: Fri Nov 20, 2015 2:42 pm
Posts: 4
Hello, M101.

You may round sma.Last to 0.25 this way:

Math.Round(sma.Last/0.25)*0.25


Top
 Profile  
 
PostPosted: Sat Nov 21, 2015 5:23 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Thanks Valentine.

Can you please show me how/where exactly I'd type that into the Scenario.cs file?

The more details the better:)


Top
 Profile  
 
PostPosted: Sat Nov 21, 2015 1:45 pm 
Offline

Joined: Fri Nov 20, 2015 2:42 pm
Posts: 4
You have to edit MyStrategy.cs file.

First, add new parameter before constructor:
Code:
[Parameter]
public double TickSize = 0.25;

public MyStrategy(Framework framework, string name)
   : base(framework, name)

Then, add new method, you may add it to the end of the MyStrategy class body:
Code:
private double ShrinkPrice(double price)
{
   return Math.Round(price/TickSize)*TickSize;
}

Finally, edit UpdateExitLimit method:
Code:
if (Position.Side == PositionSide.Long)
   exitOrder = SellLimitOrder(Instrument, Qty, ShrinkPrice(sma.Last), "Exit");
else
   exitOrder = BuyLimitOrder(Instrument, Qty, ShrinkPrice(sma.Last), "Exit");

Send(exitOrder);


Top
 Profile  
 
PostPosted: Sat Nov 21, 2015 1:59 pm 
Offline

Joined: Fri Nov 20, 2015 2:42 pm
Posts: 4
Another way, you may use TickSize parameter in Instrument. So you don't need to add your own, and ShrinkPrice method will be changed to:
Code:
private double ShrinkPrice(double price)
{
   return Math.Round(price/Instrument.TickSize)*Instrument.TickSize;
}


Top
 Profile  
 
PostPosted: Mon Nov 23, 2015 7:02 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Thanks Valentin, that definitely got all the backtest results to be multiples of 0.25!

However, the backtest results are showing certain limit orders were filled for prices that did not exist at the time. For instance, the backtest results show a Buy limit order was filled at 2086.75 while best Ask price at the time was 2087.25.

Any idea why this is happening?


Top
 Profile  
 
PostPosted: Mon Nov 23, 2015 5:22 pm 
Offline

Joined: Fri Nov 20, 2015 2:42 pm
Posts: 4
Please explain how may I reproduce this issue.


Top
 Profile  
 
PostPosted: Mon Nov 23, 2015 5:49 pm 
Offline

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

I've mentioned in the beginning of this thread that if you

have FillAtLimitPrice option set to true, then the simulator fills you with limit order price

This means there can be a fill that doesn't correspond to any bid/ask in the simulated market data. Try to set this option to false in the scenario or in the execution simulator properties in the OQ IDE and see what happens.

Regards,
Anton


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 5 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