1
Offline regression tests / windows (3.11) (push) Canceled after 0s
Offline regression tests / windows (3.12) (push) Canceled after 0s
Offline regression tests / windows (3.13) (push) Canceled after 0s

This commit is contained in:
listik committed 2026-10-23 20:49:12 +03:00
1 parent 2ea1a79bda
commit 85425483c0
50 files changed
+6468 -1854

No files matched your search

+42
View File
@@ -310,5 +310,47 @@ class CacheTests(unittest.TestCase):
self.assertEqual(len(hb.fetch_klines("AAA", 60, 0, 3_600_000, cache_path=path)[0]), 5)
class RiskRegressionTests(unittest.TestCase):
def test_percentage_and_absolute_drawdown_have_independent_peaks(self):
rows = [[0, 90, 90, 90, 90], [MIN, 100, 100, 100, 100],
[2 * MIN, 100, 100, 80, 80], [3 * MIN, 80, 200, 80, 200],
[4 * MIN, 200, 200, 170, 170]]
result = run({'AAA': rows}, {'AAA': cfg(stake=100, take_profit=0, max_adds=0)})
self.assertAlmostEqual(result['summary']['max_drawdown_usdt'], 30)
self.assertAlmostEqual(result['summary']['max_drawdown_pct'], 20)
def test_mode_capital_floor_precedes_later_stop_with_fees(self):
fixture = ModeBacktestTests()
candles = fixture.breakout_rows([(102.5, 102.6, 90, 91, 10)])
params = fixture.params(stake_pct=50, leverage=10, partial_r=0, partial_pct=0)
for fee in (0, 0.055):
with self.subTest(fee=fee):
result = hb.run_mode_backtest(candles, strategy.STRATEGY_BREAKOUT, params,
100, fee_pct=fee, min_equity_pct=95)
self.assertTrue(result['summary']['equity_stop_triggered'])
self.assertAlmostEqual(result['summary']['equity_at_stop_usdt'], 95)
self.assertTrue(any(t['status'] != 'CLOSED' for t in result['trades']))
def test_position_stop_before_capital_floor_is_not_skipped(self):
fixture = ModeBacktestTests()
result = fixture.run_mode(fixture.breakout_rows([(102.5, 102.6, 90, 91, 10)]),
fixture.params(stake_pct=50, leverage=10), min_equity_pct=80)
self.assertFalse(result['summary']['equity_stop_triggered'])
self.assertTrue(result['trades'][0]['reason'].startswith('Стоп'))
def test_short_floor_is_crossed_on_rising_price(self):
params = mode_params(strategy.STRATEGY_FADE, timeframe_min=60, min_growth_24h=30,
min_funding_pct=0, high_lookback_hours=6, pullback_pct=3, vwap_hours=6, atr_period=3,
stop_buffer_atr=0.5, max_stop_pct=30, trail_atr=0, take_profit_r=0,
partial_r=0, partial_pct=0, max_hold_hours=48, stake_pct=50, leverage=10)
rows = [(100, 101, 99, 100, 1)] * 20
rows += [(p - 2, p + 2, p - 4, p, 5) for p in (110, 125, 140, 150, 146)]
rows += [(146, 147, 128, 130, 5), (130, 160, 129, 155, 5)]
result = hb.run_mode_backtest({'AAA': minute_rows(rows, tf_min=60)}, strategy.STRATEGY_FADE,
params, 100, fee_pct=0.055, min_equity_pct=95)
self.assertEqual(result['trades'][0]['side'], 'SHORT')
self.assertAlmostEqual(result['summary']['equity_at_stop_usdt'], 95)
if __name__ == "__main__":
unittest.main()