pep8 compliance
This commit is contained in:
parent
2d273a8509
commit
eb53a796e2
@ -41,7 +41,7 @@ def generate_text_table(
|
|||||||
floatfmt = ('s', 'd', '.2f', '.8f', '.1f')
|
floatfmt = ('s', 'd', '.2f', '.8f', '.1f')
|
||||||
tabular_data = []
|
tabular_data = []
|
||||||
headers = ['pair', 'buy count', 'avg profit %',
|
headers = ['pair', 'buy count', 'avg profit %',
|
||||||
'total profit ' + stake_currency, 'avg duration', 'profit','loss']
|
'total profit ' + stake_currency, 'avg duration', 'profit', 'loss']
|
||||||
for pair in data:
|
for pair in data:
|
||||||
result = results[results.currency == pair]
|
result = results[results.currency == pair]
|
||||||
tabular_data.append([
|
tabular_data.append([
|
||||||
@ -62,14 +62,14 @@ def generate_text_table(
|
|||||||
results.profit_BTC.sum(),
|
results.profit_BTC.sum(),
|
||||||
results.duration.mean() * ticker_interval,
|
results.duration.mean() * ticker_interval,
|
||||||
results.profit.sum(),
|
results.profit.sum(),
|
||||||
results.loss.sum(),
|
results.loss.sum()
|
||||||
|
|
||||||
])
|
])
|
||||||
return tabulate(tabular_data, headers=headers, floatfmt=floatfmt)
|
return tabulate(tabular_data, headers=headers, floatfmt=floatfmt)
|
||||||
|
|
||||||
|
|
||||||
def backtest(stake_amount: float, processed: Dict[str, DataFrame],
|
def backtest(stake_amount: float, processed: Dict[str, DataFrame],
|
||||||
max_open_trades: int = 0, realistic: bool = True, sell_profit_only: bool = False, stoploss: int = -1.00, use_sell_signal: bool = False) -> DataFrame:
|
max_open_trades: int = 0, realistic: bool = True, sell_profit_only: bool = False,
|
||||||
|
stoploss: int = -1.00, use_sell_signal: bool = False) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
Implements backtesting functionality
|
Implements backtesting functionality
|
||||||
:param stake_amount: btc amount to use for each trade
|
:param stake_amount: btc amount to use for each trade
|
||||||
@ -116,9 +116,11 @@ def backtest(stake_amount: float, processed: Dict[str, DataFrame],
|
|||||||
trade_count_lock[row2.date] = trade_count_lock.get(row2.date, 0) + 1
|
trade_count_lock[row2.date] = trade_count_lock.get(row2.date, 0) + 1
|
||||||
|
|
||||||
current_profit_percent = trade.calc_profit_percent(rate=row2.close)
|
current_profit_percent = trade.calc_profit_percent(rate=row2.close)
|
||||||
if (sell_profit_only and current_profit_percent < 0) :
|
if (sell_profit_only and current_profit_percent < 0):
|
||||||
continue
|
continue
|
||||||
if min_roi_reached(trade, row2.close, row2.date) or (row2.sell == 1 and use_sell_signal) or current_profit_percent <= stoploss:
|
if min_roi_reached(trade, row2.close, row2.date)
|
||||||
|
or (row2.sell == 1 and use_sell_signal)
|
||||||
|
or current_profit_percent <= stoploss:
|
||||||
current_profit_btc = trade.calc_profit(rate=row2.close)
|
current_profit_btc = trade.calc_profit(rate=row2.close)
|
||||||
lock_pair_until = row2.Index
|
lock_pair_until = row2.Index
|
||||||
|
|
||||||
@ -127,13 +129,13 @@ def backtest(stake_amount: float, processed: Dict[str, DataFrame],
|
|||||||
pair,
|
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
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration', 'profit','loss']
|
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration', 'profit', 'loss']
|
||||||
return DataFrame.from_records(trades, columns=labels)
|
return DataFrame.from_records(trades, columns=labels)
|
||||||
|
|
||||||
|
|
||||||
@ -181,7 +183,9 @@ def start(args):
|
|||||||
|
|
||||||
# Execute backtest and print results
|
# Execute backtest and print results
|
||||||
results = backtest(
|
results = backtest(
|
||||||
config['stake_amount'], preprocessed, max_open_trades, args.realistic_simulation, config.get('experimental',{}).get('sell_profit_only', False), config.get('stoploss'), config.get('experimental',{}).get('use_sell_signal',False)
|
config['stake_amount'], preprocessed, max_open_trades, args.realistic_simulation,
|
||||||
|
config.get('experimental', {}).get('sell_profit_only', False), config.get('stoploss'),
|
||||||
|
config.get('experimental', {}).get('use_sell_signal', False)
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
'\n====================== BACKTESTING REPORT ================================\n%s',
|
'\n====================== BACKTESTING REPORT ================================\n%s',
|
||||||
|
@ -17,8 +17,8 @@ def test_generate_text_table():
|
|||||||
'profit_percent': [0.1, 0.2],
|
'profit_percent': [0.1, 0.2],
|
||||||
'profit_BTC': [0.2, 0.4],
|
'profit_BTC': [0.2, 0.4],
|
||||||
'duration': [10, 30],
|
'duration': [10, 30],
|
||||||
'profit': [2,0],
|
'profit': [2, 0],
|
||||||
'loss': [0,0]
|
'loss': [0, 0]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
print(generate_text_table({'BTC_ETH': {}}, results, 'BTC', 5))
|
print(generate_text_table({'BTC_ETH': {}}, results, 'BTC', 5))
|
||||||
|
Loading…
Reference in New Issue
Block a user