Back

How to use the PartialFillModel?

I migrated from Quantopian and I really enjoy the QC here. One thing I want to ask is, in Quantopian they provide default slippage model like this:

"If you do not specify a slippage method, slippage defaults to VolumeShareSlippage(volume_limit=0.025, price_impact=0.1) (you can take up to 2.5% of a minute's trade volume)."

I was wondering in QC, how can I set up something like above - as far as I could understand, all partially filled orders in QC are set to immediately filled. After some research, it seems that I should use

// Set the fill models in initialize:
Securities["IBM"].FillModel = new PartialFillModel();

// Custom fill model implementation stub
public class PartialFillModel : ImmediateFillModel {
public override OrderEvent MarketFill(Security asset, MarketOrder order) {
//Override order event handler and return partial order fills,
}
}

However, I am stuck at this point:

1. My algo is not using individual Securities function to add stocks, it is using custom universe, so I was wondering if I could use something like, Universe.FillModel to set every stock in the universe.

 

2. What code should go in the the PartialFillModel to let it perform similar function as the slippage model in Quantopian?

 

Thanks so much!

Update Backtest








In order to set models for securities coming out of universe selection I recommend using the `ISecurityInitializer`. We'll invoke that after the security is created (either via universe selection or via `AddSecurity` methods). Check out this partial fill model: 

https://github.com/QuantConnect/Lean/blob/1ccd33bef724af683d0e806f116ef22cfdac9cf4/Tests/Common/Orders/Fills/PartialMarketFillModelTests.cs#L130

Yours will need to be different. Instead of accepting a `numberOfFills` it should just accept the `percentage` directly. The rest of the logic there *should* work. If this ends up working well, we can look at putting it into the core LEAN.

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.


Michael Handschuh 

Thanks for the answer. If I understand correctly, the "numberOfFills" indicates the number of "smaller" orders to make the original complete order. So if 100 shares are wanted, the numberOfFills = 4, then 25 shares is filled immediately each time.

 

If my understanding above is correct, then I think there is still some difference between the Slippage model stated in the original post above and the github link you provided. The Slippage model stated in the original post is constrained by the *volume* of the *market*, which means if the volume of the market at this moment = 100 shares, the order can only be filled to up to a set percentage of it (say, 5%, then the order could only be filled for 5 shares at this moment)...

 

Please let me know if I made it more confusing... and thanks a lot for your help!!! 

0

bump for answers... thanks!

0

You can make the reality models do anything you like. There is no model as you've described though. It will be a few lines of code to implement it.

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 Broad 

If I use "Securities["SPY"].FillModel = new PartialMarketFillModel(Transactions, 2);" as Michael Handschuh mentioned, I am not quite sure how I can use all the stocks in my universe to the same FillModel as I tried "UniverseSettings.FillModel = new PartialMarketFillModel(Transactions, 2);" which returns errors. Thanks...

0

Thats a cool idea -- "UniverseSettings.FillModel = new PartialMarketFillModel()" !

The "right" way to do this is with a SecurityInitializer class:

https://github.com/QuantConnect/Lean/blob/master/Algorithm.CSharp/CustomSecurityInitializerAlgorithm.cs#L37
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