Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
difference in portfolio_value vs. equity_with_loan when live trading

In live trading I've observed a difference in the reported context.portfolio.portfolio_value and context.account.equity_with_loan. I believe at least in theory these should be the same.


2016-08-04 14:54 log_account_balance:136 INFO EquityWithLoanValue:1224**178**.68 PortfolioValue:1224**262**.485

2016-08-04 14:56 SYSTEM INFO (IB) Updating cash in minute performance tracker from 915179.448323 to 915167.42
2016-08-04 14:56 log_account_balance:136 INFO EquityWithLoanValue:1223**485**.3 PortfolioValue:1223**638**.215

As best I can tell zipline uses portfolio_value in calculations for order_target_percent. Perhaps it would be more appropriate to use equity_with_loan for calculations or sync portfolio value to equity_with_loan when doing live trading.

2 responses

Are you sure these should be the same? ELV probably subtracts maintenance margin, portfolio value probably doesn't.

No I'm not sure at all. I botched the bold, but to make it clear it's just off by a little.

EquityWithLoanValue:1224178.68 PortfolioValue:1224262.485

The difference is not enough to account for anything significant like maintenance margin. Here is it only $84.

From the IB documentation:
https://www.interactivebrokers.com/php/whiteLabel/Screens/Account_Information.htm

Cash Account: Settled Cash
Margin Account:
Total cash value + stock value + bond value + (non-U.S. & Canada securities options value)

https://www.quantopian.com/help#api-portfolio

portfolio_value
Float: Sum value of all open positions and ending cash balance.

https://www.quantopian.com/help#api-account
context.account.equity_with_loan (IB: EquityWithLoanValue)
(Float) IB Cash Account: Settled Cash.
IB Margin Account: Total cash value + stock value + bond value + (non-U.S. & Canada securities options value).
Backtest value: context.portfolio.portfolio_value

I don't have any bonds so that's not the difference. I suspect it's something subtle like margin costs, or short borrow costs.

I guess the main point is order_target_percent uses portfolio_value which might result in a reject if portfolio_value is too high.

target_value = self.portfolio.portfolio_value * target  

https://github.com/quantopian/zipline/blob/98ee8efe3db6a5cf3edb6b44b675bdb3276a750b/zipline/algorithm.py#L942