jrmeier/fast-trade

Error when run_backtest

uysalibov opened this issue · 9 comments

print(validate_backtest(strategy_object))
datafile_path = "./archive/BTCUSDT1.csv"
result = run_backtest(strategy_object, datafile_path)

File "blablab\venv\lib\site-packages\fast_trade\build_data_frame.py", line 246, in standardize_df
new_df.open = pd.to_numeric(new_df.open)

AttributeError: 'DataFrame' object has no attribute 'open'

I cant run_backtest on my computer

Hi @uysalibov, can you verify the file /archive/BTCUSDT1.csv has the columns open,high, low,close as headers? It should look something like this sample csv file

Thanks for answer. Yes my csv file format doesn't have open, high, low and close headers i download your sample csv file and this time i get this error

File "bla\venv\lib\site-packages\fast_trade\build_data_frame.py", line 153, in apply_transformers_to_dataframe
    if len(ind.get("args", [])):
TypeError: object of type 'int' has no len()

gotcha. Can you verify all the indicators have an arguments property? If possible, can you post your strategy file? You can also run the validate_backtest function which might give more clues.

Yes, i validate_backtest. It returns

{'base_balance': None, 'chart_period': None, 'chart_start': None, 'chart_stop': None, 'comission': None, 'datapoints': None, 'enter': None, 'exit': None, 'any_enter': None, 'any_exit': None, 'trailing_stop_loss': None, 'exit_on_end': None, 'has_error': False}

Why it returns all keys None?

Hmm, there must be a bug where its missing this case. The None value should indicate any errors. In this case its not saying there's any errors. Can you confirm all your indicators have arguments and match the format in the README

I set all transformers from fast_trade.transformers_map
image

Can you check this is my example backtest?

{
    "name": "many-pandora",
    "base_balance": 100000,
    "exit_on_end": false,
    "chart_period": "15Min",
    "enter": [
        ["open", "<", "baspn__mid", 1],
        ["close", "<", "pivot__mid", 4],
        ["open", "=", "wma__short", 1],
        ["low", ">", "vzo__long", 2]
    ],
    "exit": [
        ["close", "=", "bbands__long", 1]
    ],
    "datapoints": [{
        "name": "baspn__mid",
        "transformer": "baspn",
        "args": 22
    }, {
        "name": "pivot__mid",
        "transformer": "pivot",
        "args": 44
    }, {
        "name": "wma__short",
        "transformer": "wma",
        "args": 21
    }, {
        "name": "vzo__long",
        "transformer": "vzo",
        "args": 23
    }, {
        "name": "bbands__long",
        "transformer": "bbands",
        "args": 41
    }]
}

Thanks for sharing. Inside of datapoints, each datapoint accepts args as a list, not a int. So changing for the datapoint baspn_mid it should look like

        "name": "baspn__mid",
        "transformer": "baspn",
        "args": [22] # should be a list of args

Hope this helps!

Yesss It works. Thanks for helping. 🎉