3bb5cd95ac09d62c520aaac9ff4174d1f6250255,tests/test_algos.py,,test_run_quarterly,#,239

Before Change



    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)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 48

Instances


Project Name: pmorissette/bt
Commit Name: 3bb5cd95ac09d62c520aaac9ff4174d1f6250255
Time: 2018-04-17
Author: jordan.platts@ahss.org
File Name: tests/test_algos.py
Class Name:
Method Name: test_run_quarterly


Project Name: pmorissette/bt
Commit Name: 3bb5cd95ac09d62c520aaac9ff4174d1f6250255
Time: 2018-04-17
Author: jordan.platts@ahss.org
File Name: tests/test_algos.py
Class Name:
Method Name: test_run_quarterly


Project Name: pmorissette/bt
Commit Name: 3bb5cd95ac09d62c520aaac9ff4174d1f6250255
Time: 2018-04-17
Author: jordan.platts@ahss.org
File Name: tests/test_algos.py
Class Name:
Method Name: test_run_weekly


Project Name: pmorissette/bt
Commit Name: 3bb5cd95ac09d62c520aaac9ff4174d1f6250255
Time: 2018-04-17
Author: jordan.platts@ahss.org
File Name: tests/test_algos.py
Class Name:
Method Name: test_run_monthly