nautechsystems/nautilus_trader · error
unapplied CFD swap total overflow
Error message
unapplied CFD swap total overflow
What it means
Raised when accumulating a failed (non-retryable) CFD swap adjustment amount into the per-currency `unapplied_swap_totals` diagnostic would overflow. Like the applied-total overflow, it protects the integrity of diagnostic aggregation for swap adjustments that could not be applied.
Source
Thrown at crates/backtest/src/modules/cfd_swap.rs:505
AccountAdjustmentOutcome::Failed(error) if error.is_retryable() => {
log::warn!(
"Cannot apply CFD swap adjustment for {} on {}: {error}",
adjustment.amount.currency,
adjustment.booking_date
);
failed.push(adjustment);
}
AccountAdjustmentOutcome::Failed(error) => {
log::warn!(
"CFD swap adjustment {} on {} is recorded as unapplied: {error}",
adjustment.amount,
adjustment.booking_date
);
let mut totals = self.unapplied_swap_totals.borrow_mut();
let total = totals.entry(adjustment.amount.currency).or_default();
*total = total
.checked_add(adjustment.amount.as_decimal())
.ok_or_else(|| anyhow::anyhow!("unapplied CFD swap total overflow"))?;
}
}
}
let mut day = self.rollover_day.borrow_mut();
let day = day
.as_mut()
.ok_or_else(|| anyhow::anyhow!("CFD swap rollover day is not initialized"))?;
if failed.is_empty() {
day.date = batch_end_date;
day.pending_end_date = None;
day.warned_failures.clear();
self.rollover_completed.set(true);
} else {
day.pending_adjustments = Some(failed);
}
Ok(())
}View on GitHub (pinned to 18893faf8b)
Solutions
- Fix the root cause making adjustments fail (funding, account config, rate data) so failures stop accumulating.
- Run a shorter backtest window or reset diagnostics periodically.
- Validate input amounts and account currencies before starting the run.
Defensive patterns
Strategy: validation
Validate before calling
anyhow::ensure!(account.is_funded_for(currency), "account must hold {currency} before swaps accrue"); Try / catch
if let Err(e) = engine.acknowledge(&outcomes) {
if e.to_string().contains("unapplied CFD swap total overflow") {
log::error!("too many failed adjustments accumulated; fix underlying failures");
} else { return Err(e); }
} Prevention
- Fix the root causes of failed adjustments early (funding, currencies, rate data)
- Monitor failed-adjustment counts during the run instead of letting them accrue for the full window
- Validate adjustment amounts against realistic bounds before the backtest
When it happens
Trigger: Many failed swap adjustments (e.g. persistent account/funding errors) whose summed amounts exceed the Decimal accumulator bound during a backtest.
Common situations: Long backtests where every rollover fails (e.g. account currency never funded, missing rate data) so unapplied amounts pile up daily; corrupted amount data inflating each adjustment.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- CFD swap diagnostic total overflow
- cannot calculate CFD swap for {instrument_id}: midpoint over
- cannot calculate CFD swap for position {}: adjustment overfl
- cannot calculate CFD swap for position {}: currency conversi
- Simulation module {module_index} log_diagnostics failed: {e:
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/94a1b8d88083b8b3.
Report an issue: GitHub.