Skip to content

Commit

Permalink
Merge pull request #407 from brrrak/add-date-check
Browse files Browse the repository at this point in the history
Fix "Momentum lag results in IndexError"
  • Loading branch information
timkpaine authored Nov 20, 2023
2 parents 6930ccc + 654b7a9 commit 51ec0c0
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bt/algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,8 @@ def __init__(self, lookback=pd.DateOffset(months=3), lag=pd.DateOffset(days=0)):
def __call__(self, target):
selected = target.temp["selected"]
t0 = target.now - self.lag
if target.universe[selected].index[0] > t0:
return False
prc = target.universe.loc[t0 - self.lookback : t0, selected]
target.temp["stat"] = prc.calc_total_return()
return True
Expand Down

0 comments on commit 51ec0c0

Please sign in to comment.