don't use "can_short" in backtesting to determine application of leverage
This commit is contained in:
parent
fb1541bdf6
commit
b09fb5826f
@ -739,7 +739,7 @@ class Backtesting:
|
|||||||
proposed_leverage=1.0,
|
proposed_leverage=1.0,
|
||||||
max_leverage=max_leverage,
|
max_leverage=max_leverage,
|
||||||
side=direction, entry_tag=entry_tag,
|
side=direction, entry_tag=entry_tag,
|
||||||
) if self._can_short else 1.0
|
) if self.trading_mode != TradingMode.SPOT else 1.0
|
||||||
# Cap leverage between 1.0 and max_leverage.
|
# Cap leverage between 1.0 and max_leverage.
|
||||||
leverage = min(max(leverage, 1.0), max_leverage)
|
leverage = min(max(leverage, 1.0), max_leverage)
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from unittest.mock import MagicMock
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from freqtrade.data.history import get_timerange
|
from freqtrade.data.history import get_timerange
|
||||||
from freqtrade.enums import ExitType
|
from freqtrade.enums import ExitType, TradingMode
|
||||||
from freqtrade.optimize.backtesting import Backtesting
|
from freqtrade.optimize.backtesting import Backtesting
|
||||||
from freqtrade.persistence.trade_model import LocalTrade
|
from freqtrade.persistence.trade_model import LocalTrade
|
||||||
from tests.conftest import EXMS, patch_exchange
|
from tests.conftest import EXMS, patch_exchange
|
||||||
@ -925,11 +925,13 @@ def test_backtest_results(default_conf, fee, mocker, caplog, data: BTContainer)
|
|||||||
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
mocker.patch(f"{EXMS}.get_max_leverage", return_value=100)
|
mocker.patch(f"{EXMS}.get_max_leverage", return_value=100)
|
||||||
|
mocker.patch(f"{EXMS}.calculate_funding_fees", return_value=0)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
frame = _build_backtest_dataframe(data.data)
|
frame = _build_backtest_dataframe(data.data)
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
# TODO: Should we initialize this properly??
|
# TODO: Should we initialize this properly??
|
||||||
backtesting._can_short = True
|
backtesting._can_short = True
|
||||||
|
backtesting.trading_mode = TradingMode.MARGIN
|
||||||
backtesting._set_strategy(backtesting.strategylist[0])
|
backtesting._set_strategy(backtesting.strategylist[0])
|
||||||
backtesting.required_startup = 0
|
backtesting.required_startup = 0
|
||||||
backtesting.strategy.advise_entry = lambda a, m: frame
|
backtesting.strategy.advise_entry = lambda a, m: frame
|
||||||
|
@ -10,7 +10,7 @@ from arrow import Arrow
|
|||||||
from freqtrade.configuration import TimeRange
|
from freqtrade.configuration import TimeRange
|
||||||
from freqtrade.data import history
|
from freqtrade.data import history
|
||||||
from freqtrade.data.history import get_timerange
|
from freqtrade.data.history import get_timerange
|
||||||
from freqtrade.enums import ExitType
|
from freqtrade.enums import ExitType, TradingMode
|
||||||
from freqtrade.optimize.backtesting import Backtesting
|
from freqtrade.optimize.backtesting import Backtesting
|
||||||
from tests.conftest import EXMS, patch_exchange
|
from tests.conftest import EXMS, patch_exchange
|
||||||
|
|
||||||
@ -108,9 +108,10 @@ def test_backtest_position_adjustment_detailed(default_conf, fee, mocker, levera
|
|||||||
default_conf.update({
|
default_conf.update({
|
||||||
"stake_amount": 100.0,
|
"stake_amount": 100.0,
|
||||||
"dry_run_wallet": 1000.0,
|
"dry_run_wallet": 1000.0,
|
||||||
"strategy": "StrategyTestV3"
|
"strategy": "StrategyTestV3",
|
||||||
})
|
})
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
|
backtesting.trading_mode = TradingMode.FUTURES
|
||||||
backtesting._can_short = True
|
backtesting._can_short = True
|
||||||
backtesting._set_strategy(backtesting.strategylist[0])
|
backtesting._set_strategy(backtesting.strategylist[0])
|
||||||
pair = 'XRP/USDT'
|
pair = 'XRP/USDT'
|
||||||
|
Loading…
Reference in New Issue
Block a user