algo = algos.RunQuarterly()
target.now = None
assert not algo(target)
// run on first date
target.now = dts[0]
assert algo(target)
target.now = dts[1]
assert not algo(target)
// end of quarter
target.now = dts[89]
assert not algo(target)
// new quarter
target.now = dts[90]
assert algo(target)
// last date
target.now = dts[len(dts) - 1]
assert not algo(target)
algo = algos.RunQuarterly(
run_on_first_date=False,
run_on_end_of_period=True,
run_on_last_date=True
)
// run on first date
target.now = dts[0]
assert not algo(target)
target.now = dts[1]
assert not algo(target)
// end of quarter
target.now = dts[89]
assert algo(target)
// new quarter
target.now = dts[90]
assert not algo(target)
// last date
target.now = dts[len(dts) - 1]
assert algo(target)
dts = pd.DatetimeIndex([datetime(2016, 1, 3), datetime(2017, 1, 8), datetime(2018, 1, 7)])
data = pd.DataFrame(index=dts, columns=["c1", "c2"], data=100)
target.data = data
// check next year
target.now = dts[1]
assert algo(target)
After Change
dts = pd.date_range("2010-01-01", periods=367)
data = pd.DataFrame(index=dts, columns=["c1", "c2"], data=100)
target = mock.MagicMock()
target.data = data
algo = algos.RunQuarterly()
// adds the initial day
backtest = bt.Backtest(
bt.Strategy("", [algo]),
data
)target.data = backtest.data
// end of quarter
target.now = dts[89]
assert not algo(target)
// new quarter
target.now = dts[90]
assert algo(target)
algo = algos.RunQuarterly(
run_on_first_date=False,
run_on_end_of_period=True,
run_on_last_date=True
)
// adds the initial day
backtest = bt.Backtest(
bt.Strategy("", [algo]),
data
)target.data = backtest.data
// end of quarter
target.now = dts[89]
assert algo(target)
// new quarter
target.now = dts[90]
assert not algo(target)
dts = pd.DatetimeIndex([datetime(2016, 1, 3), datetime(2017, 1, 8), datetime(2018, 1, 7)])
data = pd.DataFrame(index=dts, columns=["c1", "c2"], data=100)
// adds the initial day
backtest = bt.Backtest(
bt.Strategy("", [algo]),
data
)target.data = backtest.data
// check next year
target.now = dts[1]
assert algo(target)