Performance of shorted stock
Are shorted stocks handled any differently to long stocks in the Performance module? As far as I'm aware shorted stocks have separate margin requirements (50% of the value for example) which would influence the returns.
@warren-oneill I think at the moment short stocks are basically just considered as negative positions. Building a proper margin model is something we've had on our radar for a while, we just haven't gotten around to building it yet. cc @jfkirk, who is thinking about this as part of the futures trading branch I think
@ssanderson so does that mean it is currently calculated the same as a long position, e.g. if a stock is shorted for $10 and the price falls to $5 then the returns are (10-5)/10=%50?
@warren-oneill I believe what happens is roughly as follows:
I enter into a short position of 10 shares for stock X, which is trading at $10 when I enter the position. If I have no other assets and $10 in cash reserves (an unrealistic scenario because of margin limits, as you point out), my portfolio value is $50 + $10 * (-10 shares) = -$50 in the PerformanceTracker. The price of the stock then dips to $5 over the course of the day. At the end of the day, my portfolio value is $50 + $5 * (-10 shares) = $0. IIRC we calculate returns between t_0 and t_1 as:
(portfolio_value at t_1 - portfolio_value at t_0) / capital_base
which means that we calculate (0 - (-50)) / 10 = 50 / 10 = 500% returns.
Notably, this calculation depends entirely on your input capital base. If you double your capital base you halve your returns. Inversely, if you halve your capital base you double your returns. This is an accurate reflection of the fact that your real return on investment is measured relative to the amount of money you're managing. However, because we don't impose margin limits, it's easy to artificially inflate returns by leveraging as much as you want.
Hope that all makes sense.
@ssanderson ok, I have to say that that's pretty unrealistic esp since you cannot go short without satisfying margin requirements unlike going long. This prob means that strategies that go short fair much better in zipline than they should and once margins are implemented people could see a big change in there returns. Also, above you haven't accounted for the money received for the initial sale. Anyway, I'll keep in touch with @jfkirk with the latest margin developments and I'm more than willing to help in the developing if needs be.