Moonshot cash positions wrong for short positions?

Noticed cash positions being greater than 1.0 within backtest results from a short only strategy, and thought this might be a bug, but wanted to confirm.

In pyfolio/quantrocket_moonshot.py the from_moonshot method returns the following for positions:

image

I would think cash would be 1 - active positions, which appears to be the intention within from_moonshot per the following code snippet:

returns = results.loc["Return"].sum(axis=1)
positions = results.loc["NetExposure"]
positions["cash"] = 1 - positions.sum(axis=1)

Should the last line maybe use abs() before sum() instead?

positions["cash"] = 1 - positions.abs().sum(axis=1)

In an academic context you actually do get cash from selling short, so cash could be above 0. However, in the real world, shorts will reduce your buying power, so I agree that adding abs() makes more sense. Thanks for the suggestion.

Ok cool; thanks for confirming! I've built a set of utility methods to streamline my backtesting and analysis, so I've added this customization there, and will update QR if/when added.

As always, thanks for creating a product the rest of us quants can build off of!

This issue is fixed in version 2.5.0.

1 Like