strategic stake amounts
This commit is contained in:
parent
299dfe560a
commit
8828c43518
@ -433,7 +433,7 @@ class FreqtradeBot:
|
|||||||
Trade.total_open_trades_stakes()
|
Trade.total_open_trades_stakes()
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
stake_amount = self.config['stake_amount']
|
stake_amount = self.strategy.get_stake_amount(pair)
|
||||||
if stake_amount == constants.UNLIMITED_STAKE_AMOUNT:
|
if stake_amount == constants.UNLIMITED_STAKE_AMOUNT:
|
||||||
stake_amount = self._calculate_unlimited_stake_amount()
|
stake_amount = self._calculate_unlimited_stake_amount()
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ class Backtesting:
|
|||||||
trades.append(trade_entry)
|
trades.append(trade_entry)
|
||||||
return trades
|
return trades
|
||||||
|
|
||||||
def backtest(self, processed: Dict, stake_amount: float,
|
def backtest(self, processed: Dict,
|
||||||
start_date: datetime, end_date: datetime,
|
start_date: datetime, end_date: datetime,
|
||||||
max_open_trades: int = 0, position_stacking: bool = False) -> DataFrame:
|
max_open_trades: int = 0, position_stacking: bool = False) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
@ -292,7 +292,6 @@ class Backtesting:
|
|||||||
Avoid extensive logging in this method and functions it calls.
|
Avoid extensive logging in this method and functions it calls.
|
||||||
|
|
||||||
:param processed: a processed dictionary with format {pair, data}
|
:param processed: a processed dictionary with format {pair, data}
|
||||||
:param stake_amount: amount to use for each trade
|
|
||||||
:param start_date: backtesting timerange start datetime
|
:param start_date: backtesting timerange start datetime
|
||||||
:param end_date: backtesting timerange end datetime
|
:param end_date: backtesting timerange end datetime
|
||||||
:param max_open_trades: maximum number of concurrent trades, <= 0 means unlimited
|
:param max_open_trades: maximum number of concurrent trades, <= 0 means unlimited
|
||||||
@ -308,6 +307,7 @@ class Backtesting:
|
|||||||
# Use dict of lists with data for performance
|
# Use dict of lists with data for performance
|
||||||
# (looping lists is a lot faster than pandas DataFrames)
|
# (looping lists is a lot faster than pandas DataFrames)
|
||||||
data: Dict = self._get_ohlcv_as_lists(processed)
|
data: Dict = self._get_ohlcv_as_lists(processed)
|
||||||
|
get_stake_amount = self.strategy.get_stake_amount
|
||||||
|
|
||||||
# Indexes per pair, so some pairs are allowed to have a missing start.
|
# Indexes per pair, so some pairs are allowed to have a missing start.
|
||||||
indexes: Dict = {}
|
indexes: Dict = {}
|
||||||
@ -344,6 +344,7 @@ class Backtesting:
|
|||||||
and tmp != end_date
|
and tmp != end_date
|
||||||
and row[BUY_IDX] == 1 and row[SELL_IDX] != 1):
|
and row[BUY_IDX] == 1 and row[SELL_IDX] != 1):
|
||||||
# Enter trade
|
# Enter trade
|
||||||
|
stake_amount = get_stake_amount(pair, row[DATE_IDX])
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair=pair,
|
pair=pair,
|
||||||
open_rate=row[OPEN_IDX],
|
open_rate=row[OPEN_IDX],
|
||||||
@ -387,8 +388,7 @@ class Backtesting:
|
|||||||
"""
|
"""
|
||||||
data: Dict[str, Any] = {}
|
data: Dict[str, Any] = {}
|
||||||
|
|
||||||
logger.info('Using stake_currency: %s ...', self.config['stake_currency'])
|
logger.info("Using stake_currency: %s ...", self.config["stake_currency"])
|
||||||
logger.info('Using stake_amount: %s ...', self.config['stake_amount'])
|
|
||||||
|
|
||||||
position_stacking = self.config.get('position_stacking', False)
|
position_stacking = self.config.get('position_stacking', False)
|
||||||
|
|
||||||
@ -422,7 +422,6 @@ class Backtesting:
|
|||||||
# Execute backtest and print results
|
# Execute backtest and print results
|
||||||
results = self.backtest(
|
results = self.backtest(
|
||||||
processed=preprocessed,
|
processed=preprocessed,
|
||||||
stake_amount=self.config['stake_amount'],
|
|
||||||
start_date=min_date.datetime,
|
start_date=min_date.datetime,
|
||||||
end_date=max_date.datetime,
|
end_date=max_date.datetime,
|
||||||
max_open_trades=max_open_trades,
|
max_open_trades=max_open_trades,
|
||||||
|
@ -267,6 +267,13 @@ class IStrategy(ABC):
|
|||||||
"""
|
"""
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def get_stake_amount(self, pair: str, date: datetime) -> float:
|
||||||
|
""" Called when placing a buy order
|
||||||
|
:param pair: Pair that's about to be bought.
|
||||||
|
:param date: date of the trade (should be the latest candle for live run mode).
|
||||||
|
"""
|
||||||
|
return self.config['stake_amount']
|
||||||
|
|
||||||
###
|
###
|
||||||
# END - Intended to be overridden by strategy
|
# END - Intended to be overridden by strategy
|
||||||
###
|
###
|
||||||
|
Loading…
Reference in New Issue
Block a user