backtest export: include enter,exit dates

This commit is contained in:
kryofly 2018-01-12 21:28:56 +01:00
parent 4781a23809
commit d4008374f6

View File

@ -94,13 +94,13 @@ def get_trade_entry(pair, row, ticker, trade_count_lock, args):
(row2.sell == 1 and use_sell_signal) or \ (row2.sell == 1 and use_sell_signal) or \
current_profit_percent <= stoploss: current_profit_percent <= stoploss:
current_profit_btc = trade.calc_profit(rate=row2.close) current_profit_btc = trade.calc_profit(rate=row2.close)
return row2.Index, (pair, return row2, (pair,
current_profit_percent, current_profit_percent,
current_profit_btc, current_profit_btc,
row2.Index - row.Index, row2.Index - row.Index,
current_profit_btc > 0, current_profit_btc > 0,
current_profit_btc < 0 current_profit_btc < 0
) )
def backtest(args) -> DataFrame: def backtest(args) -> DataFrame:
@ -146,12 +146,16 @@ def backtest(args) -> DataFrame:
ret = get_trade_entry(pair, row, ticker, ret = get_trade_entry(pair, row, ticker,
trade_count_lock, args) trade_count_lock, args)
if ret: if ret:
lock_pair_until, trade_entry = ret row2, trade_entry = ret
lock_pair_until = row2.Index
trades.append(trade_entry) trades.append(trade_entry)
if record: if record:
# Note, need to be json.dump friendly # Note, need to be json.dump friendly
# record a tuple of pair, current_profit_percent, entry-date, duration # record a tuple of pair, current_profit_percent,
# entry-date, duration
records.append((pair, trade_entry[1], records.append((pair, trade_entry[1],
row.date.strftime('%s'),
row2.date.strftime('%s'),
row.Index, trade_entry[3])) row.Index, trade_entry[3]))
# For now export inside backtest(), maybe change so that backtest() # For now export inside backtest(), maybe change so that backtest()
# returns a tuple like: (dataframe, records, logs, etc) # returns a tuple like: (dataframe, records, logs, etc)