VaR
VaR copied to clipboard
VaR for Long/Short Portfolios
Weight supplied that adds to 0 will yield error due to
self.pnl = pd.DataFrame(np.average(self.returns, 1, self.weights),
index=self.returns.index,
columns=["Daily PnL"])
A workaround that I have used is to change the above to:
self.pnl = pd.DataFrame((self.returns * self.weights).sum(axis=1),
index=self.returns.index,
columns=["Daily PnL"])
The above change will make the PnL into a long short excess return for the portfolio. However, the backtest() function doesn't yield correct graph though.
That is a very good point! Thank you very much. I will try to implement and include short positions!