예제 #1
0
def test_generate_sell_reason_stats():

    results = pd.DataFrame({
        'pair': ['ETH/BTC', 'ETH/BTC', 'ETH/BTC'],
        'profit_ratio': [0.1, 0.2, -0.1],
        'profit_abs': [0.2, 0.4, -0.2],
        'trade_duration': [10, 30, 10],
        'wins': [2, 0, 0],
        'draws': [0, 0, 0],
        'losses': [0, 0, 1],
        'sell_reason': [SellType.ROI, SellType.ROI, SellType.STOP_LOSS]
    })

    sell_reason_stats = generate_sell_reason_stats(max_open_trades=2,
                                                   results=results)
    roi_result = sell_reason_stats[0]
    assert roi_result['sell_reason'] == 'roi'
    assert roi_result['trades'] == 2
    assert pytest.approx(roi_result['profit_mean']) == 0.15
    assert roi_result['profit_mean_pct'] == round(
        roi_result['profit_mean'] * 100, 2)
    assert pytest.approx(roi_result['profit_mean']) == 0.15
    assert roi_result['profit_mean_pct'] == round(
        roi_result['profit_mean'] * 100, 2)

    stop_result = sell_reason_stats[1]

    assert stop_result['sell_reason'] == 'stop_loss'
    assert stop_result['trades'] == 1
    assert pytest.approx(stop_result['profit_mean']) == -0.1
    assert stop_result['profit_mean_pct'] == round(
        stop_result['profit_mean'] * 100, 2)
    assert pytest.approx(stop_result['profit_mean']) == -0.1
    assert stop_result['profit_mean_pct'] == round(
        stop_result['profit_mean'] * 100, 2)
예제 #2
0
def test_text_table_sell_reason():

    results = pd.DataFrame({
        'pair': ['ETH/BTC', 'ETH/BTC', 'ETH/BTC'],
        'profit_ratio': [0.1, 0.2, -0.1],
        'profit_abs': [0.2, 0.4, -0.2],
        'trade_duration': [10, 30, 10],
        'wins': [2, 0, 0],
        'draws': [0, 0, 0],
        'losses': [0, 0, 1],
        'sell_reason': [SellType.ROI, SellType.ROI, SellType.STOP_LOSS]
    })

    result_str = (
        '|   Sell Reason |   Sells |   Wins |   Draws |   Losses |'
        '   Avg Profit % |   Cum Profit % |   Tot Profit BTC |   Tot Profit % |\n'
        '|---------------+---------+--------+---------+----------+'
        '----------------+----------------+------------------+----------------|\n'
        '|           roi |       2 |      2 |       0 |        0 |'
        '             15 |             30 |              0.6 |             15 |\n'
        '|     stop_loss |       1 |      0 |       0 |        1 |'
        '            -10 |            -10 |             -0.2 |             -5 |'
    )

    sell_reason_stats = generate_sell_reason_stats(max_open_trades=2,
                                                   results=results)
    assert text_table_sell_reason(sell_reason_stats=sell_reason_stats,
                                  stake_currency='BTC') == result_str