Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions gs_quant/timeseries/backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
specific language governing permissions and limitations
under the License.
"""

import numpy as np
from functools import partial

from dateutil.relativedelta import relativedelta as rdelta
Expand Down Expand Up @@ -80,7 +80,10 @@ def backtest_basket(
rebal_dates = [cal[0] + i * rdelta(months=1) for i in range(num_rebals + 1)]

# Convert the hypothetical weekly/monthly rebalance dates to actual calendar days
rebal_dates = [min(cal[cal >= date]) for date in rebal_dates if date < max(cal)]
idxs = cal.searchsorted(rebal_dates) # find insertion indices for all dates at once
idxs = idxs[idxs < len(cal)] # filter out indices beyond last date
rebal_dates = cal[idxs] # map to actual calendar dates


# Create Units dataframe
units = pd.DataFrame(index=cal, columns=series.columns)
Expand Down