Margin Model Refactoring Problems

Hi All,

The margin model refactoring has seriously messed up my code. I can't locate any help or examples on how to make equivalent code in the new class model to the old class model. Has anyone worked through this new "BuyingPower" model to make their code equivalent to the previous version?

Additionally, when I look at the class code for the portfolio manager I am pretty sure it is wrong (or I don't understand what is being done).

For example:

public decimal MarginRemaining
get { return TotalPortfolioValue - UnsettledCashBook.TotalValueInAccountCurrency - TotalMarginUsed; }

Isn't the one of the purposes of buying on margin that I don't have to wait for the cash to settle to trade more?!? Here the cash is being subtracted out of the marging remaining. In the old PatternDayTradingModel everything worked fine. Now I can't seem to get any leverage.

The real, short questions here are:

1) Using the new version of Lean, is how can I replicate the PatternDayTradingModel with the refactored code and get up to 4x leverage? 

2) How can I check against the buyng power remaining for the total porfolio to see if I have enough Cash + Margin to make a trade?




Update Backtest

Update Backtest


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.


This discussion is closed