Skip to main content

strategy.strategies.dynamic_lp.states.check_for_rebalance

datetime

timedelta

pprint

TYPE_CHECKING

Tuple

np

pd

pytz

log_rebalance_trigger_metrics

get_price_and_volatility

convert_time_window

Config

DEBUG_ALWAYS_REBALANCE

PRODUCTION_MODE

check_for_rebalance

def check_for_rebalance(strat: "StrategyDynamicLP") -> None

Evaluates the need for rebalancing the strategy based on market conditions and strategy parameters.

This method checks if the current position is out of the rebalance soft bounds or if a rebalance is due based on the set rebalance interval (frequency). It sets the strategy's next state accordingly, either to close the current position for rebalancing or to mark the completion if no rebalance is needed. A grace period can be used to avoid frequent rebalances when the bounds are quickly exceeded but the price is mean reverting.

Raises:

  • ValueError - If a rebalance is needed but there are no positions to rebalance, which is currently not supported by the strategy.

Returns:

  • None - No actions are required in this state.