Skip to content

Commit

Permalink
port cumulator fix
Browse files Browse the repository at this point in the history
  • Loading branch information
richklee committed Feb 26, 2024
1 parent d0e2da6 commit 6d0097f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 41 deletions.
17 changes: 8 additions & 9 deletions alphavec/backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ def backtest(
Strategy is simulated using the given weights, returns, and cost parameters.
Zero costs are calculated by default: no commission, no borrowing, no spread.
To prevent look-ahead bias by default the returns will be shifted 1 interval
relative to the weights during backtest.
To prevent look-ahead bias the returns will be shifted 1 interval by default relative to the weights during backtest.
Daily interval data is assumed by default.
Daily interval data is default.
If you wish to use a different interval pass in the appropriate freq_day value
e.g. if you are using hourly data in a 24-hour market such as crypto, you should pass in 24.
Expand Down Expand Up @@ -104,13 +103,13 @@ def backtest(
ann_risk_free_rate: Annualized risk-free rate used to calculate Sharpe ratio. Defaults to 0.02.
Returns:
A tuple containing five DataFrames that report backtest performance:
1. Asset-wise performance.
A tuple containing five data sets:
1. Asset-wise performance table.
2. Asset-wise equity curve.
3. Asset-wise rolling annual Sharpe ratio.
4. Portfolio performance.
3. Asset-wise rolling annualized Sharpe.
4. Portfolio performance table.
5. Portfolio returns.
5. Portoflio equity curve.
6. Portoflio equity curve.
"""

assert weights.shape == prices.shape, "Weights and prices must have the same shape"
Expand Down Expand Up @@ -196,7 +195,7 @@ def backtest(

# Evaluate the strategy portfolio performance
port_rets = strat_rets.sum(axis=1)
port_cum = strat_cum.sum(axis=1)
port_cum = (1 + port_rets).cumprod() - 1

# Aproximate the portfolio turnover as the weighted average sum of the asset-wise turnover
port_ann_turnover = (strat_ann_turnover * weights.mean().abs()).sum()
Expand Down
35 changes: 3 additions & 32 deletions example.ipynb

Large diffs are not rendered by default.

0 comments on commit 6d0097f

Please sign in to comment.