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).

https://github.com/QuantConnect/Lean/blob/master/Common/Securities/SecurityPortfolioManager.cs

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?

Thanks

 

Matt