mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 00:23:07 +00:00
Fix edge-case when calculating cagr
edge-case with leveraged trades - yielding a negative final balance. closes #9820
This commit is contained in:
@@ -191,6 +191,9 @@ def calculate_cagr(days_passed: int, starting_balance: float, final_balance: flo
|
||||
:param final_balance: Final balance to calculate CAGR against
|
||||
:return: CAGR
|
||||
"""
|
||||
if final_balance < 0:
|
||||
# With leveraged trades, final_balance can become negative.
|
||||
return 0
|
||||
return (final_balance / starting_balance) ** (1 / (days_passed / 365)) - 1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user