QuantJourney Backtester

QuantJourney Backtester

Share product feedback

✓

Thank you.

Your note is now in the QuantJourney inbox.

docs/engine/rebalancing.mdx

Rebalancing

How QuantJourney converts target weights into realized drifted weights and rebalance trades.

Rebalancing is a weight-mode portfolio process. It decides when target weights are allowed to become actual weights.

Sourcebacktester/portfolio/rebalance.py + backtester/core.py
LayerPortfolio execution timing for weights
ModeWeight mode
Inputshifted target weights, asset returns, optional benchmark returns
Outputactual weights, rebalance flags and rebalance statistics
Primary APIrebalance_policy=RebalancePolicy(...)
Main caveatRebalancing is not the same as market/limit/stop order simulation.

Engine Contract

Between rebalance dates, weights drift with price movement. On rebalance dates, selected positions snap back to target weights, subject to policy gates.

target weights -> shift(1) -> cash buffer -> RebalanceEngine.run() -> actual weights + rebalance_flags -> turnover cost + positions + NAV

Level 1: Monthly Rebalance

Business month-end rebalance
python
from backtester.portfolio.rebalance import RebalancePolicy

strategy = MyStrategy(
    ...,
    execution_mode="weights",
    rebalance_policy=RebalancePolicy(frequency="BME"),
)

Level 2: Monthly Plus Drift Band

Rebalance monthly or when drift exceeds 5 percent
python
strategy = MyStrategy(
    ...,
    rebalance_policy=RebalancePolicy(
        frequency="BME",
        drift_threshold=0.05,
    ),
)

Level 3: Institutional-Style Policy

Partial rebalance with turnover budget
python
strategy = MyStrategy(
    ...,
    rebalance_policy=RebalancePolicy(
        frequency="BME",
        drift_threshold=0.03,
        partial_rebalance=True,
        max_annual_turnover=6.0,
        avoid_short_term_gains=True,
    ),
)

Supported Triggers

TriggerField
Calendarfrequency, weekday
Driftdrift_threshold, drift_type
Tracking errortracking_error_threshold
Signal changerebalance_on_signal_change
Drawdown breakermax_drawdown_trigger
Turnover budgetmax_annual_turnover
Partial rebalancepartial_rebalance
Tax heuristicavoid_short_term_gains

Implementation Note

The enum RebalanceAt.OPEN/CLOSE/VWAP_WINDOW records timing intent. The current weight-mode performance path should still be treated as daily close-to-close accounting unless open/VWAP execution is explicitly implemented and tested in the performance path.

Failure Modes

  • Using daily rebalance by default without checking turnover.
  • Confusing rebalance trades with order-mode fills.
  • Assuming drift threshold triggers are free of transaction cost.
  • Ignoring the cash buffer applied by the performance path.
  • Advertising open/VWAP weight execution before implementation is fully wired.