LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
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.
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.
Alexandre Catarino
,
Hi Gmamuze Cht ,
When we subscribe to futures data with AddFuture, we create a universe of futures' contracts that are filtered by the function set by the SetFilter method. Consequently, we need to use SetSecurityInitializer in order to set models and properties of the Security object that represents each futures' contract.
If we want to set the same slippage model across all the futures' contracts, we need to use:
Thanks for your response ! Is there a same simple way to apply a model based on the % of volume traded ?
0
Gmamuze Cht
14.4k
,
And i have a general question about slippage :
The minimum deviation is equal to the minimum price fluctuation, right ? Or is it normal that the model slippage above make a filled price value with lot of decimal than the original minimum price fluctuation ? And is it real to fill a price like this ?
0
Alexandre Catarino
,
Hi Gmamuze Cht ,
If you mean what the changes should be made in the custom model in the attached backtest, we just need to use a different formula:
var orderVolume = order.AbsoluteQuantity * asset.Price;
var slippage = orderVolume * 0.01m;
The slippage model is responsible for the rounding to the minimum price fluctuation. We can find the value to make the adjustment in asset.SymbolProperties.MinimumPriceVariation.
0
Gmamuze Cht
14.4k
,
I Follow your advice and I update in function of my needs.
The result take into account :
- Size of the last candle (High - Low) divide by a %. (enable the correlation with volatility)
- The ratio of OrderVolume divide by the last AssetVolume. (enable the correlation with liquidity)
Final Formula : var slippage = (High[0]-Low[0]) * 0.01m / (orderVolume/Volume[0]);
public class CustomSlippageModel : ISlippageModel
{
private readonly QCAlgorithm _algorithm;
public RollingWindow<decimal> High = new RollingWindow<decimal>(2);
public RollingWindow<decimal> Low = new RollingWindow<decimal>(2);
public RollingWindow<decimal> Volume = new RollingWindow<decimal>(2);
public CustomSlippageModel(QCAlgorithm algorithm)
{
_algorithm = algorithm;
}
public decimal GetSlippageApproximation(Security asset, Order order)
{
var orderVolume = order.AbsoluteQuantity;
var slippage = (High[0]-Low[0]) * 0.01m / (orderVolume/Volume[0]);
return slippage;
}
}
0
Gmamuze Cht
14.4k
,
A Question, volumes given from the market data is the same unit than the quantity emit by the algorithm ?
0
Alexandre Catarino
,
Hi Gmamuze Cht
Volume is the sum of quantity of all trades within the data resolution period.
0
Gmamuze Cht
14.4k
,
Hi Alexander, it was not the goal of my question :) I am talking about unit applyed to the data in thousand, million etc.. I pose this question because for example on Dukascopy when you download data they propose this option to choose your volume data unit. In case which 1 lot of EUR/USD was not equal to 1 lot = 100.000 unit, it would preferable to rethink the formula below.
Ps : In My code upper, I make a mistake the final formula is not :
var slippage = (High[0]-Low[0]) * 0.01m / (orderVolume/Volume[0]);
But :
var slippage = (High[0]-Low[0]) * 0.01m / (Volume[0]/orderVolume);
0
Edited by Gmamuze Cht
Alexandre Catarino
,
Hi Gmamuze Cht ,
Ok. For Futures (and Options), the Quantity refers to the number of contracts. 1 = 1 contract.
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...
To unlock posting to the community forums please complete at least 30% of Boot Camp. You can
continue your Boot Camp training progress from the terminal. We
hope to see you in the community soon!