Exemplo n.º 1
0
def test_macd():
    factor = TechnicalFactor(codes=['000338'],
                             start_timestamp='2019-01-01',
                             end_timestamp='2019-06-10',
                             level=IntervalLevel.LEVEL_1DAY,
                             provider=Provider.JoinQuant,
                             computing_window=None,
                             transformer=MacdTransformer(),
                             adjust_type='qfq')

    print(factor.factor_df.tail())

    # compare with east money manually
    diff = factor.factor_df['diff']
    dea = factor.factor_df['dea']
    macd = factor.factor_df['macd']

    assert round(diff.loc[('stock_sz_000338', '2019-06-10')], 2) == -0.14
    assert round(dea.loc[('stock_sz_000338', '2019-06-10')], 2) == -0.15
    assert round(macd.loc[('stock_sz_000338', '2019-06-10')], 2) == 0.02

    factor.move_on(to_timestamp='2019-06-17')
    diff = factor.factor_df['diff']
    dea = factor.factor_df['dea']
    macd = factor.factor_df['macd']

    assert round(diff.loc[('stock_sz_000338', '2019-06-17')], 2) == 0.06
    assert round(dea.loc[('stock_sz_000338', '2019-06-17')], 2) == -0.03
    assert round(macd.loc[('stock_sz_000338', '2019-06-17')], 2) <= 0.19
Exemplo n.º 2
0
def test_macd():
    factor = TechnicalFactor(entity_type='stock',
                             codes=['000338'],
                             start_timestamp='2019-01-01',
                             end_timestamp='2019-06-10',
                             level=IntervalLevel.LEVEL_1DAY,
                             provider='joinquant',
                             indicators=['macd'],
                             indicators_param=[{
                                 'slow': 26,
                                 'fast': 12,
                                 'n': 9
                             }],
                             auto_load=True)

    print(factor.get_depth_df().tail())

    # compare with east money manually
    diff = factor.get_depth_df()['diff']
    dea = factor.get_depth_df()['dea']
    macd = factor.get_depth_df()['macd']

    assert round(diff.loc[('stock_sz_000338', '2019-06-10')], 2) == -0.14
    assert round(dea.loc[('stock_sz_000338', '2019-06-10')], 2) == -0.15
    assert round(macd.loc[('stock_sz_000338', '2019-06-10')], 2) == 0.02

    factor.move_on(to_timestamp='2019-06-17')
    diff = factor.get_depth_df()['diff']
    dea = factor.get_depth_df()['dea']
    macd = factor.get_depth_df()['macd']

    assert round(diff.loc[('stock_sz_000338', '2019-06-17')], 2) == 0.06
    assert round(dea.loc[('stock_sz_000338', '2019-06-17')], 2) == -0.03
    assert round(macd.loc[('stock_sz_000338', '2019-06-17')], 2) == 0.19
Exemplo n.º 3
0
def test_ma():
    factor = TechnicalFactor(codes=['000338'],
                             start_timestamp='2019-01-01',
                             end_timestamp='2019-06-10',
                             level=IntervalLevel.LEVEL_1DAY,
                             provider=Provider.JoinQuant,
                             computing_window=30,
                             transformer=MaTransformer(windows=[5, 10, 30]),
                             adjust_type='qfq')

    print(factor.factor_df.tail())

    # compare with east money manually
    ma5 = factor.factor_df['ma5']
    ma10 = factor.factor_df['ma10']
    ma30 = factor.factor_df['ma30']

    assert round(ma5.loc[('stock_sz_000338', '2019-06-10')], 2) <= 11.23
    assert round(ma10.loc[('stock_sz_000338', '2019-06-10')], 2) <= 11.43
    assert round(ma30.loc[('stock_sz_000338', '2019-06-10')], 2) <= 11.52

    factor.move_on(to_timestamp='2019-06-17')
    ma5 = factor.factor_df['ma5']
    ma10 = factor.factor_df['ma10']
    ma30 = factor.factor_df['ma30']

    assert round(ma5.loc[('stock_sz_000338', '2019-06-17')], 2) <= 12.06
    assert round(ma10.loc[('stock_sz_000338', '2019-06-17')], 2) <= 11.64
    assert round(ma30.loc[('stock_sz_000338', '2019-06-17')], 2) <= 11.50
Exemplo n.º 4
0
def test_ma():
    factor = TechnicalFactor(security_type=SecurityType.stock,
                             codes=['000338'],
                             start_timestamp='2019-01-01',
                             end_timestamp='2019-06-10',
                             level=TradingLevel.LEVEL_1DAY,
                             provider=Provider.JOINQUANT,
                             indicators=['ma', 'ma', 'ma'],
                             indicators_param=[{
                                 'window': 5
                             }, {
                                 'window': 10
                             }, {
                                 'window': 30
                             }])

    print(factor.get_depth_df().tail())

    # compare with east money manually
    ma5 = factor.get_depth_df()['ma5']
    ma10 = factor.get_depth_df()['ma10']
    ma30 = factor.get_depth_df()['ma30']

    assert round(ma5.loc[('stock_sz_000338', '2019-06-10')], 2) == 11.48
    assert round(ma10.loc[('stock_sz_000338', '2019-06-10')], 2) == 11.69
    assert round(ma30.loc[('stock_sz_000338', '2019-06-10')], 2) == 11.79

    factor.move_on(to_timestamp='2019-06-17')
    ma5 = factor.get_depth_df()['ma5']
    ma10 = factor.get_depth_df()['ma10']
    ma30 = factor.get_depth_df()['ma30']

    assert round(ma5.loc[('stock_sz_000338', '2019-06-17')], 2) == 12.33
    assert round(ma10.loc[('stock_sz_000338', '2019-06-17')], 2) == 11.91
    assert round(ma30.loc[('stock_sz_000338', '2019-06-17')], 2) == 11.76
Exemplo n.º 5
0
def test_macd():
    factor = TechnicalFactor(security_type=SecurityType.stock,
                             codes=['000338'],
                             start_timestamp='2019-01-01',
                             end_timestamp='2019-06-10',
                             level=TradingLevel.LEVEL_1DAY,
                             provider=Provider.JOINQUANT,
                             indicators=['macd'],
                             indicators_param=[{
                                 'slow': 26,
                                 'fast': 12,
                                 'n': 9
                             }])

    print(factor.get_depth_df().tail())

    # compare with east money manually
    diff = factor.get_depth_df()['diff']
    dea = factor.get_depth_df()['dea']
    macd = factor.get_depth_df()['macd']

    assert round(diff.loc[('stock_sz_000338', '2019-06-10')], 2) == -0.15
    assert round(dea.loc[('stock_sz_000338', '2019-06-10')], 2) == -0.16
    assert round(macd.loc[('stock_sz_000338', '2019-06-10')], 2) == 0.02

    factor.move_on(to_timestamp='2019-06-17')
    diff = factor.get_depth_df()['diff']
    dea = factor.get_depth_df()['dea']
    macd = factor.get_depth_df()['macd']

    assert round(diff.loc[('stock_sz_000338', '2019-06-17')], 2) == 0.07
    assert round(dea.loc[('stock_sz_000338', '2019-06-17')], 2) == -0.03
    assert round(macd.loc[('stock_sz_000338', '2019-06-17')], 2) == 0.19
Exemplo n.º 6
0
def test_macd():
    factor = TechnicalFactor(
        provider="joinquant",
        codes=["000338"],
        start_timestamp="2019-01-01",
        end_timestamp="2019-06-10",
        level=IntervalLevel.LEVEL_1DAY,
        computing_window=None,
        transformer=MacdTransformer(),
        adjust_type="qfq",
    )

    print(factor.factor_df.tail())

    # compare with east money manually
    diff = factor.factor_df["diff"]
    dea = factor.factor_df["dea"]
    macd = factor.factor_df["macd"]

    assert round(diff.loc[("stock_sz_000338", "2019-06-10")], 2) == -0.14
    assert round(dea.loc[("stock_sz_000338", "2019-06-10")], 2) == -0.15
    assert round(macd.loc[("stock_sz_000338", "2019-06-10")], 2) == 0.02

    factor.move_on(to_timestamp="2019-06-17")
    diff = factor.factor_df["diff"]
    dea = factor.factor_df["dea"]
    macd = factor.factor_df["macd"]

    assert round(diff.loc[("stock_sz_000338", "2019-06-17")], 2) == 0.06
    assert round(dea.loc[("stock_sz_000338", "2019-06-17")], 2) == -0.03
    assert round(macd.loc[("stock_sz_000338", "2019-06-17")], 2) <= 0.19
Exemplo n.º 7
0
def test_ma():
    factor = TechnicalFactor(
        provider="joinquant",
        codes=["000338"],
        start_timestamp="2019-01-01",
        end_timestamp="2019-06-10",
        level=IntervalLevel.LEVEL_1DAY,
        computing_window=30,
        transformer=MaTransformer(windows=[5, 10, 30]),
        adjust_type="qfq",
    )

    print(factor.factor_df.tail())

    # compare with east money manually
    ma5 = factor.factor_df["ma5"]
    ma10 = factor.factor_df["ma10"]
    ma30 = factor.factor_df["ma30"]

    assert round(ma5.loc[("stock_sz_000338", "2019-06-10")], 2) <= 11.23
    assert round(ma10.loc[("stock_sz_000338", "2019-06-10")], 2) <= 11.43
    assert round(ma30.loc[("stock_sz_000338", "2019-06-10")], 2) <= 11.52

    factor.move_on(to_timestamp="2019-06-17")
    ma5 = factor.factor_df["ma5"]
    ma10 = factor.factor_df["ma10"]
    ma30 = factor.factor_df["ma30"]

    assert round(ma5.loc[("stock_sz_000338", "2019-06-17")], 2) <= 12.06
    assert round(ma10.loc[("stock_sz_000338", "2019-06-17")], 2) <= 11.64
    assert round(ma30.loc[("stock_sz_000338", "2019-06-17")], 2) <= 11.50
Exemplo n.º 8
0
def test_ma():
    factor = TechnicalFactor(entity_type='stock',
                             codes=['000338'],
                             start_timestamp='2019-01-01',
                             end_timestamp='2019-06-10',
                             level=IntervalLevel.LEVEL_1DAY,
                             provider='joinquant',
                             indicators=['ma', 'ma', 'ma'],
                             indicators_param=[{
                                 'window': 5
                             }, {
                                 'window': 10
                             }, {
                                 'window': 30
                             }],
                             auto_load=True)

    print(factor.get_depth_df().tail())

    # compare with east money manually
    ma5 = factor.get_depth_df()['ma5']
    ma10 = factor.get_depth_df()['ma10']
    ma30 = factor.get_depth_df()['ma30']

    assert round(ma5.loc[('stock_sz_000338', '2019-06-10')], 2) == 11.23
    assert round(ma10.loc[('stock_sz_000338', '2019-06-10')], 2) == 11.43
    assert round(ma30.loc[('stock_sz_000338', '2019-06-10')], 2) == 11.52

    factor.move_on(to_timestamp='2019-06-17')
    ma5 = factor.get_depth_df()['ma5']
    ma10 = factor.get_depth_df()['ma10']
    ma30 = factor.get_depth_df()['ma30']

    assert round(ma5.loc[('stock_sz_000338', '2019-06-17')], 2) == 12.06
    assert round(ma10.loc[('stock_sz_000338', '2019-06-17')], 2) == 11.64
    assert round(ma30.loc[('stock_sz_000338', '2019-06-17')], 2) == 11.50