Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
context.portfolio_value

Here is a simple back test here, where I short 100% of my portfolio on day #1 and exit all my position on day #2.

I started of with $1,000,000 in cash.
On day #1, I short OIL at the price of 12.21, which gives me a total of 81900 unit of OIL.
On day #2, I exited my short position of OIL at the price of 11.47. That makes me $40950.0 profit.

What I don't understand is that on day #1, the porfolio_value is $1,000,000 which is expected as I have yet to do anything. However, on day #2, the portfolio_value is still at $1,000,000 instead of expected 1040950.0. Only after I exit all my positions that on day #3 the portfolio_value API give me the right value.

Is this expected? From documentation, it seems to say that portfolio_value should returns the sum of all open position as well as ending cash balance, which I interpret as should I exit all my position now, that is how much cash I would end up with.

From the attached backtest, you cannot observe the logs, so you will need to clone them.