Back

Margin calls and Liquidate Last preferences?

Interactive Brokers has a setting to choose which positions to liquidate last on a margin call. Is it possible to configure this in a QuantConnect algortihm for both a backtest and live trading? Essentially, what I'd like to do is have some control over which positions get liquidated in the event of a margin call.

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.


Hi Mirza,

We have an OnMarginCall method for this purpose.

Best,
Shile Wen

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.


Oh, can I use OnMarginCall to choose what gets sold? How do I do that? I was under the impression that it gives me a chance to know what the engine chose to sell for me, but I didn't realize that I could act on it.

0

You can either write your own MarginCallModel (your original question) to chose the "requested orders for liquidation" or you can handle the order requests which come through the OnMarginCall event handler. The engine liquidates the requests in order to get back to meet the minimum margin requirements again. 

This is on the more advanced side of the engine -- so kudos =D But apologies it's not documented. Setting a MarginCallModel is on the portfolio object; DefaultMarginCallModel

 

 

Example of using the user-layer event handler:

https://github.com/QuantConnect/Lean/blob/master/Algorithm.CSharp/MarginCallEventsAlgorithm.cs

 

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.


Thanks! How does this work in live trading? Does IB notify QC and give it a chance to run the OnMarginCall handler? Does the initial OnMarginCall request list reflect IB's selection? Or is QC trying to anticipate a margin call before IB (and is there a race?)? If I setup my own MarginCallModel, does that interact with live trading in some way?

0

>Or is QC trying to anticipate a margin call before IB
This one -- we're trying to make our fictional models as realistic as possible. There's no race as IB is very slow at issuing margin calls and updating their portfolio margin math in general. In live-trading, the portfolio is updated at least minutely whether you're using hour-daily data or not. I think there's a "non-zero" chance of a race but we've never seen it happen in reality.

If that were to happen it would be an untracked order event -- when an order event comes in which isn't tracked by LEAN the default behavior is to shutdown.

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.


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