예제 #1
0
파일: test_algos.py 프로젝트: stand2y/bt
def test_run_yearly():
    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.RunYearly()
    # adds the initial day
    backtest = bt.Backtest(bt.Strategy('', [algo]), data)
    target.data = backtest.data

    # end of year
    target.now = dts[364]
    assert not algo(target)

    # new year
    target.now = dts[365]
    assert algo(target)

    algo = algos.RunYearly(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 year
    target.now = dts[364]
    assert algo(target)

    # new year
    target.now = dts[365]
    assert not algo(target)
예제 #2
0
def test_run_yearly():
    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.RunYearly()

    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 year
    target.now = dts[364]
    assert not algo(target)

    # new year
    target.now = dts[365]
    assert algo(target)

    # last date
    target.now = dts[len(dts) - 1]
    assert not algo(target)

    algo = algos.RunYearly(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 year
    target.now = dts[364]
    assert algo(target)

    # new year
    target.now = dts[365]
    assert not algo(target)

    # last date
    target.now = dts[len(dts) - 1]
    assert algo(target)
예제 #3
0
파일: test_algos.py 프로젝트: xyicheng/bt
def test_run_yearly():
    algo = algos.RunYearly()

    target = mock.MagicMock()

    target.now = datetime(2010, 1, 1)
    actual = algo(target)
    assert not actual

    target.now = datetime(2010, 5, 1)
    actual = algo(target)
    assert not actual

    target.now = datetime(2011, 1, 1)
    actual = algo(target)
    assert actual