Export sell_reason from backtest

This commit is contained in:
Matthias 2018-07-11 20:32:56 +02:00
parent 8c0b19f80c
commit 2a61629014
2 changed files with 6 additions and 3 deletions

View File

@ -124,7 +124,7 @@ class Backtesting(object):
records = [(t.pair, t.profit_percent, t.open_time.timestamp(), records = [(t.pair, t.profit_percent, t.open_time.timestamp(),
t.close_time.timestamp(), t.open_index - 1, t.trade_duration, t.close_time.timestamp(), t.open_index - 1, t.trade_duration,
t.open_rate, t.close_rate, t.open_at_end) t.open_rate, t.close_rate, t.open_at_end, t.sell_reason.value)
for index, t in results.iterrows()] for index, t in results.iterrows()]
if records: if records:

View File

@ -660,7 +660,9 @@ def test_backtest_record(default_conf, fee, mocker):
"open_index": [1, 119, 153, 185], "open_index": [1, 119, 153, 185],
"close_index": [118, 151, 184, 199], "close_index": [118, 151, 184, 199],
"trade_duration": [123, 34, 31, 14], "trade_duration": [123, 34, 31, 14],
"open_at_end": [False, False, False, True] "open_at_end": [False, False, False, True],
"sell_reason": [SellType.ROI, SellType.STOP_LOSS,
SellType.ROI, SellType.FORCE_SELL]
}) })
backtesting._store_backtest_result("backtest-result.json", results) backtesting._store_backtest_result("backtest-result.json", results)
assert len(results) == 4 assert len(results) == 4
@ -673,7 +675,7 @@ def test_backtest_record(default_conf, fee, mocker):
# Below follows just a typecheck of the schema/type of trade-records # Below follows just a typecheck of the schema/type of trade-records
oix = None oix = None
for (pair, profit, date_buy, date_sell, buy_index, dur, for (pair, profit, date_buy, date_sell, buy_index, dur,
openr, closer, open_at_end) in records: openr, closer, open_at_end, sell_reason) in records:
assert pair == 'UNITTEST/BTC' assert pair == 'UNITTEST/BTC'
assert isinstance(profit, float) assert isinstance(profit, float)
# FIX: buy/sell should be converted to ints # FIX: buy/sell should be converted to ints
@ -682,6 +684,7 @@ def test_backtest_record(default_conf, fee, mocker):
assert isinstance(openr, float) assert isinstance(openr, float)
assert isinstance(closer, float) assert isinstance(closer, float)
assert isinstance(open_at_end, bool) assert isinstance(open_at_end, bool)
assert isinstance(sell_reason, str)
isinstance(buy_index, pd._libs.tslib.Timestamp) isinstance(buy_index, pd._libs.tslib.Timestamp)
if oix: if oix:
assert buy_index > oix assert buy_index > oix