Exemplo n.º 1
0
def test_proccess_logic_and_actions_enter_exit_confirmations_multi_2():
    mock_df = pd.read_csv("./test/ohlcv_data.csv.txt",
                          parse_dates=True).set_index("date")
    # fake an indicator
    mock_df["ind_1"] = [5, 5, 5, 2, 6, 7, 9, 9, 1]

    mock_backtest = {
        "enter": [["ind_1", "=", 5, 2]],
        "any_enter": [],
        "exit": [["ind_1", ">", 6, 3]],
        "any_exit": [],
    }

    res = process_logic_and_generate_actions(mock_df, mock_backtest)

    print(res)
    assert list(res.action.values) == [
        "h",
        "e",
        "e",
        "h",
        "h",
        "h",
        "h",
        "x",
        "h",
    ]
Exemplo n.º 2
0
def test_proccess_logic_and_actions_enter_exit_confirmations_multi():
    mock_df = pd.read_csv("./test/ohlcv_data.csv.txt",
                          parse_dates=True).set_index("date")
    # fake an indicator
    mock_df["ind_1"] = [0, 1, 2, 4, 5, 6, 7, 8, 9]
    mock_df["ind_2"] = [5, 5, 4, 2, 6, 4, 9, 9, 1]
    mock_df["ind_3"] = [1, 1, 2, 3, 5, 9, 9, 9, 8]

    mock_backtest = {
        "enter": [["ind_1", "<", 2, 2]],
        "any_enter": [],
        "exit": [["ind_2", ">", 8, 2], ["ind_3", "<", 8, 3]],
        "any_exit": [],
    }

    res = process_logic_and_generate_actions(mock_df, mock_backtest)

    assert list(res.action.values) == [
        "h",
        "e",
        "h",
        "h",
        "h",
        "h",
        "h",
        "h",
        "h",
    ]
Exemplo n.º 3
0
def test_proccess_logic_and_actions_multi_enter_exit():
    mock_df = pd.read_csv("./test/ohlcv_data.csv.txt",
                          parse_dates=True).set_index("date")
    # fake an indicator
    mock_df["ind_1"] = [0, 1, 2, 4, 5, 6, 7, 8, 9]
    mock_backtest = {
        "exit": [["ind_1", ">", 8], ["ind_1", "<", 10]],
        "any_exit": [],
        "enter": [["ind_1", "<", 9], ["ind_1", ">", 7]],
        "any_enter": [],
    }

    res = process_logic_and_generate_actions(mock_df, mock_backtest)

    assert list(res.action.values) == [
        "h",
        "h",
        "h",
        "h",
        "h",
        "h",
        "h",
        "e",
        "x",
    ]
Exemplo n.º 4
0
def test_proccess_logic_and_actions_3():
    mock_df = pd.read_csv("./test/ohlcv_data.csv.txt",
                          parse_dates=True).set_index("date")
    mock_backtest = {
        "exit": [],
        "any_exit": [["close", ">", 0.02199]],
        "enter": [],
        "any_enter": [],
    }

    res = process_logic_and_generate_actions(mock_df, mock_backtest)
    assert res.action.values[5] == "ax"
Exemplo n.º 5
0
def test_proccess_logic_and_actions_4():
    mock_df = pd.read_csv("./test/ohlcv_data.csv.txt",
                          parse_dates=True).set_index("date")
    mock_df["ind_1"] = [0, 0, 0, 0, 1, 1, 1, 0, 0]
    mock_backtest = {
        "exit": [],
        "any_exit": [],
        "enter": [["ind_1", "=", 1, 3]],
        "any_enter": [],
    }

    res = process_logic_and_generate_actions(mock_df, mock_backtest)
    assert res.action.values[6] == "e"
Exemplo n.º 6
0
def test_proccess_logic_and_actions_1():
    mock_df = pd.read_csv("./test/ohlcv_data.csv.txt",
                          parse_dates=True).set_index("date")
    mock_backtest = {
        "exit": [],
        "any_exit": [],
        "enter": [],
        "any_enter": [],
    }

    res = process_logic_and_generate_actions(mock_df, mock_backtest)

    assert isinstance(res, pd.DataFrame)
Exemplo n.º 7
0
def test_proccess_logic_and_actions_single_enter():
    mock_df = pd.read_csv("./test/ohlcv_data.csv.txt",
                          parse_dates=True).set_index("date")
    mock_backtest = {
        "exit": [],
        "any_exit": [],
        "enter": [["volume", ">", 171000]],
        "any_enter": [],
    }

    res = process_logic_and_generate_actions(mock_df, mock_backtest)
    assert list(
        res.action.values) == ["h", "h", "h", "h", "h", "e", "e", "e", "e"]
Exemplo n.º 8
0
def test_proccess_logic_and_actions_no_logics():
    mock_df = pd.read_csv("./test/ohlcv_data.csv.txt",
                          parse_dates=True).set_index("date")
    mock_backtest = {
        "exit": [],
        "any_exit": [],
        "enter": [],
        "any_enter": [],
    }

    res = process_logic_and_generate_actions(mock_df, mock_backtest)

    assert "h" in res.action.unique()
Exemplo n.º 9
0
def test_proccess_logic_and_actions_single_any_exit():
    mock_df = pd.read_csv("./test/ohlcv_data.csv.txt",
                          parse_dates=True).set_index("date")
    mock_df["ind_1"] = [0, 0, 0, 0, 1, 1, 1, 0, 0]
    mock_backtest = {
        "exit": [],
        "any_exit": [["ind_1", "=", 1]],
        "enter": [],
        "any_enter": [],
    }

    res = process_logic_and_generate_actions(mock_df, mock_backtest)
    assert list(res.action) == [
        "h",
        "h",
        "h",
        "h",
        "ax",
        "ax",
        "ax",
        "h",
        "h",
    ]