{"record":{"id":"6c58efde5fecf521","repo":"nautechsystems/nautilus_trader","slug":"cfd-swap-rollover-day-is-not-initialized","errorCode":null,"errorMessage":"CFD swap rollover day is not initialized","messagePattern":"CFD swap rollover day is not initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/backtest/src/modules/cfd_swap.rs","lineNumber":391,"sourceCode":"                    Some(Self::next_weekday(day.date)?)\n                }\n                Some(_) => None,\n            }\n        };\n\n        if let Some(date) = initialize_date {\n            self.initialize_rollover_day(date);\n        }\n\n        if self.rollover_completed.get() {\n            return Ok(SimulationModuleResult::NotReady);\n        }\n\n        {\n            let day = self.rollover_day.borrow();\n            let day = day\n                .as_ref()\n                .ok_or_else(|| anyhow::anyhow!(\"CFD swap rollover day is not initialized\"))?;\n            if let Some(adjustments) = &day.pending_adjustments {\n                return Ok(SimulationModuleResult::Completed(\n                    adjustments\n                        .iter()\n                        .map(|adjustment| adjustment.amount)\n                        .collect(),\n                ));\n            }\n        }\n\n        let date = self\n            .rollover_day\n            .borrow()\n            .as_ref()\n            .ok_or_else(|| anyhow::anyhow!(\"CFD swap rollover day is not initialized\"))?\n            .date;\n        if ts_now.as_u64() < self.rollover_time_ns(date)? {\n            return Ok(SimulationModuleResult::NotReady);","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/backtest/src/modules/cfd_swap.rs#L373-L409","documentation":"During process(), when the engine asks for already-completed pending adjustments, the rollover_day cell is None — the CFD swap module was never initialized with a rollover day. The module cannot return results for a day it does not know about, so it throws.","triggerScenarios":"Calling process() on the CFD swap module (e.g. as part of the simulation loop) on a code path that reads pending adjustments before the module's initialization (on_start / first on_bar / set_rollover_day) has populated rollover_day.","commonSituations":"Running the engine without firing the module's start/initialization event; adding the module to the engine but never sending bars/dates it uses to seed the rollover day; misordered module startup.","solutions":["Ensure the module's initialization path runs before the simulation loop (call its on_start / feed the first bar or time event)","Verify the module is registered so its on_start receives engine config dates","Check that the backtest data actually contains bars/events for the instrument before rollover processing begins"],"exampleFix":"// before: processing module before init\nmodule.process(ts_now)?; // rollover_day is None\n// after: initialize first\nmodule.on_start(&config)?;\nmodule.on_bar(&first_bar)?;\nmodule.process(ts_now)?;","handlingStrategy":"try-catch","validationCode":"// ensure module lifecycle ran before process\nmodule.on_start(&engine_config)?;","typeGuard":null,"tryCatchPattern":"match module.process(ts_now) {\n    Err(e) if e.to_string().contains(\"rollover day is not initialized\") => {\n        log::warn!(\"CFD swap module not initialized yet, skipping\");\n        SimulationModuleResult::NotReady\n    }\n    other => other,\n}","preventionTips":["Always run the engine's normal start sequence; don't call process on a freshly constructed module","Feed data/timestamps that trigger the module's day seeding before rollover checks"],"tags":["backtest","cfd","uninitialized-state","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}