Back

How do I alter the FX fill model?

Hi, I am trying to control the way the my order in FX is filled. I would like to specify a Market Fill type execution, but be able to specify the slippage in terms of ticks.

So if close of Bar is P then:

if (Order is BUY)
TradePrice = P+X ticks
else
TradePrice = P-X ticks

How do I do that?
Update Backtest








Hey @DroidMaster,

Its a little tricky but you have to override the default models with your own. The full documentation is here: https://www.quantconnect.com/docs/API#2.10.1 but I've hacked up a quick example and set the Slippage to 0 to give you an example in the attached code.

I tested two backtests with different slippage values and surely enough a higher slippage gave a lower profit figure :)

You can view the default model here for FX and use it as an example: https://raw.github.com/QuantConnect /QCAlgorithm/master/QuantConnect.Common/ Securities/Forex/ForexTransactionModel.cs
1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Thanks for that Jared!

What is the easiest way for me to add this class/file into an existing project that I have?
0

There are just two places where its different:
1. In the initialize function of algorithm add one line (AFTER you've added your assets)
Securities[symbol].Model = new CustomTransactionModel(this);

2. Create a new file to hold the class: and copy the whole source of the file manually with copy-paste,
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Jared,

I get this error:

The type or namespace name `CustomTransactionModel' could not be found. Are you missing a using directive or an assembly reference?
0

Ahh, solved that one.

I was using the name of the .cs file instead of the class name.

Silly mistake.
0

Perfect -- what slippage would you recommend? You mentioned 0.001 was huge for FX. We're always open to improving the default transaction models.

It is currently:
//Assume slippage is 1/1000th of the price
slippage = lastBar.Price*0.001m;
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed