The behavior you are seeing stems from the fact that
resample by more than a 1W increment is ambiguous. Resampling 'W-FRI' is easy. It will fetch every Friday. However, resampling '2W-FRI' actually needs one more piece of information. It needs to know which Friday to start counting. Pandas doesn't have an explicit way of setting the 'starting Friday'. So, if one starts resampling with '2W-FRI' this week it will choose one set of Fridays. However, if one starts resampling next week it will choose a different set of Fridays. Unfortunately, one cannot even use 'even' or 'odd' Fridays. Because the last Friday of the year can fall in either the 51, 52, or 53 week, every other Friday is not always even or odd.
So, a workaround is to first define all the possible Fridays one wants to resample on. Use the
date_range method something like this
import pandas as pd
context.resample_dates = pd.date_range(start='1/1/2001',
The 'starting Friday' can be set by choosing a different 'start' date. Ensure the 'end' date includes all the resample dates in the backtest. (The attached algo uses the
get_environment method to determine this`) .
Now, rather than
resample simply select just those dates from close which are in the 'resample_list'. Maybe like this
close = data.history(context.signal, 'close', 30, '1d')
# Use `dropna` to narrow the dates to just those in 'close'.
prices_biweek_close = close[context.resample_dates].dropna()
That 'workaround' should resolve the dates abruptly changing issue. However, if markets weren't open on one of the desired Fridays, there won't be any data. This is different from the behavior of the
resample method which would fetch the last known price.
There are ways to get prices if markets weren't open but they introduce some other anomalies. Is there a particular reason you wish to check specific 'every other Fridays'?