2020-01-02 06:33:55 +00:00
|
|
|
import pandas as pd
|
|
|
|
|
2020-01-09 05:52:34 +00:00
|
|
|
from freqtrade.edge import PairInfo
|
|
|
|
from freqtrade.optimize.optimize_reports import (
|
|
|
|
generate_edge_table, generate_text_table, generate_text_table_sell_reason,
|
2020-01-02 06:33:55 +00:00
|
|
|
generate_text_table_strategy)
|
|
|
|
from freqtrade.strategy.interface import SellType
|
|
|
|
|
|
|
|
|
|
|
|
def test_generate_text_table(default_conf, mocker):
|
|
|
|
|
|
|
|
results = pd.DataFrame(
|
|
|
|
{
|
|
|
|
'pair': ['ETH/BTC', 'ETH/BTC'],
|
|
|
|
'profit_percent': [0.1, 0.2],
|
|
|
|
'profit_abs': [0.2, 0.4],
|
|
|
|
'trade_duration': [10, 30],
|
2020-02-07 02:51:50 +00:00
|
|
|
'wins': [2, 0],
|
|
|
|
'draws': [0, 0],
|
|
|
|
'losses': [0, 0]
|
2020-01-02 06:33:55 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
result_str = (
|
2020-02-27 12:28:28 +00:00
|
|
|
'| Pair | Buys | Avg Profit % | Cum Profit % | Tot Profit BTC |'
|
|
|
|
' Tot Profit % | Avg Duration | Wins | Draws | Losses |\n'
|
|
|
|
'|---------+--------+----------------+----------------+------------------+'
|
|
|
|
'----------------+----------------+--------+---------+----------|\n'
|
2020-02-07 02:54:47 +00:00
|
|
|
'| ETH/BTC | 2 | 15.00 | 30.00 | 0.60000000 |'
|
2020-02-27 12:28:28 +00:00
|
|
|
' 15.00 | 0:20:00 | 2 | 0 | 0 |\n'
|
|
|
|
'| TOTAL | 2 | 15.00 | 30.00 | 0.60000000 |'
|
|
|
|
' 15.00 | 0:20:00 | 2 | 0 | 0 |'
|
2020-01-02 06:33:55 +00:00
|
|
|
)
|
|
|
|
assert generate_text_table(data={'ETH/BTC': {}},
|
|
|
|
stake_currency='BTC', max_open_trades=2,
|
|
|
|
results=results) == result_str
|
|
|
|
|
|
|
|
|
|
|
|
def test_generate_text_table_sell_reason(default_conf, mocker):
|
|
|
|
|
|
|
|
results = pd.DataFrame(
|
|
|
|
{
|
|
|
|
'pair': ['ETH/BTC', 'ETH/BTC', 'ETH/BTC'],
|
2020-01-09 05:46:39 +00:00
|
|
|
'profit_percent': [0.1, 0.2, -0.1],
|
|
|
|
'profit_abs': [0.2, 0.4, -0.2],
|
2020-01-02 06:33:55 +00:00
|
|
|
'trade_duration': [10, 30, 10],
|
2020-02-07 02:51:50 +00:00
|
|
|
'wins': [2, 0, 0],
|
|
|
|
'draws': [0, 0, 0],
|
|
|
|
'losses': [0, 0, 1],
|
2020-01-02 06:33:55 +00:00
|
|
|
'sell_reason': [SellType.ROI, SellType.ROI, SellType.STOP_LOSS]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
result_str = (
|
2020-02-27 12:28:28 +00:00
|
|
|
'| Sell Reason | Sells | Wins | Draws | Losses |'
|
2020-02-07 02:54:47 +00:00
|
|
|
' Avg Profit % | Cum Profit % | Tot Profit BTC | Tot Profit % |\n'
|
2020-02-27 12:28:28 +00:00
|
|
|
'|---------------+---------+--------+---------+----------+'
|
|
|
|
'----------------+----------------+------------------+----------------|\n'
|
|
|
|
'| roi | 2 | 2 | 0 | 0 |'
|
2020-02-07 02:54:47 +00:00
|
|
|
' 15 | 30 | 0.6 | 15 |\n'
|
2020-02-27 12:28:28 +00:00
|
|
|
'| stop_loss | 1 | 0 | 0 | 1 |'
|
2020-02-07 02:54:47 +00:00
|
|
|
' -10 | -10 | -0.2 | -5 |'
|
2020-01-02 06:33:55 +00:00
|
|
|
)
|
|
|
|
assert generate_text_table_sell_reason(
|
2020-01-31 03:39:18 +00:00
|
|
|
data={'ETH/BTC': {}},
|
|
|
|
stake_currency='BTC', max_open_trades=2,
|
|
|
|
results=results) == result_str
|
2020-01-02 06:33:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_generate_text_table_strategy(default_conf, mocker):
|
|
|
|
results = {}
|
2020-02-07 02:51:50 +00:00
|
|
|
results['TestStrategy1'] = pd.DataFrame(
|
2020-01-02 06:33:55 +00:00
|
|
|
{
|
|
|
|
'pair': ['ETH/BTC', 'ETH/BTC', 'ETH/BTC'],
|
|
|
|
'profit_percent': [0.1, 0.2, 0.3],
|
|
|
|
'profit_abs': [0.2, 0.4, 0.5],
|
|
|
|
'trade_duration': [10, 30, 10],
|
2020-02-07 02:51:50 +00:00
|
|
|
'wins': [2, 0, 0],
|
|
|
|
'draws': [0, 0, 0],
|
|
|
|
'losses': [0, 0, 1],
|
2020-01-02 06:33:55 +00:00
|
|
|
'sell_reason': [SellType.ROI, SellType.ROI, SellType.STOP_LOSS]
|
|
|
|
}
|
|
|
|
)
|
2020-02-07 02:51:50 +00:00
|
|
|
results['TestStrategy2'] = pd.DataFrame(
|
2020-01-02 06:33:55 +00:00
|
|
|
{
|
|
|
|
'pair': ['LTC/BTC', 'LTC/BTC', 'LTC/BTC'],
|
|
|
|
'profit_percent': [0.4, 0.2, 0.3],
|
|
|
|
'profit_abs': [0.4, 0.4, 0.5],
|
|
|
|
'trade_duration': [15, 30, 15],
|
2020-02-07 02:51:50 +00:00
|
|
|
'wins': [4, 1, 0],
|
|
|
|
'draws': [0, 0, 0],
|
|
|
|
'losses': [0, 0, 1],
|
2020-01-02 06:33:55 +00:00
|
|
|
'sell_reason': [SellType.ROI, SellType.ROI, SellType.STOP_LOSS]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
result_str = (
|
2020-02-27 12:28:28 +00:00
|
|
|
'| Strategy | Buys | Avg Profit % | Cum Profit % | Tot'
|
|
|
|
' Profit BTC | Tot Profit % | Avg Duration | Wins | Draws | Losses |\n'
|
|
|
|
'|---------------+--------+----------------+----------------+------------------+'
|
|
|
|
'----------------+----------------+--------+---------+----------|\n'
|
|
|
|
'| TestStrategy1 | 3 | 20.00 | 60.00 | 1.10000000 |'
|
|
|
|
' 30.00 | 0:17:00 | 3 | 0 | 0 |\n'
|
|
|
|
'| TestStrategy2 | 3 | 30.00 | 90.00 | 1.30000000 |'
|
|
|
|
' 45.00 | 0:20:00 | 3 | 0 | 0 |'
|
2020-01-02 06:33:55 +00:00
|
|
|
)
|
|
|
|
assert generate_text_table_strategy('BTC', 2, all_results=results) == result_str
|
2020-01-09 05:52:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_generate_edge_table(edge_conf, mocker):
|
|
|
|
|
|
|
|
results = {}
|
|
|
|
results['ETH/BTC'] = PairInfo(-0.01, 0.60, 2, 1, 3, 10, 60)
|
2020-02-27 12:28:28 +00:00
|
|
|
assert generate_edge_table(results).count('+') == 7
|
2020-01-09 05:52:34 +00:00
|
|
|
assert generate_edge_table(results).count('| ETH/BTC |') == 1
|
|
|
|
assert generate_edge_table(results).count(
|
2020-02-07 02:51:50 +00:00
|
|
|
'| Risk Reward Ratio | Required Risk Reward | Expectancy |') == 1
|