Skip to content

Add scheduled walk-forward optimization support#9611

Open
scarab-systems wants to merge 3 commits into
QuantConnect:masterfrom
scarab-systems:feature-7031-walk-forward-optimization
Open

Add scheduled walk-forward optimization support#9611
scarab-systems wants to merge 3 commits into
QuantConnect:masterfrom
scarab-systems:feature-7031-walk-forward-optimization

Conversation

@scarab-systems

@scarab-systems scarab-systems commented Jul 13, 2026

Copy link
Copy Markdown

Description

Adds scheduled walk-forward optimization support for algorithms:

  • QCAlgorithm.Optimize(...) overloads that schedule walk-forward optimization similarly to Train(...).
  • A provider abstraction for local and cloud-backed walk-forward optimization execution.
  • Local optimizer and QuantConnect API-backed providers.
  • Result plumbing for selected parameter sets and backtest summaries, with safeguards against nested child optimizations.

Related Issue

Addresses #7031

Motivation and Context

Issue #7031 requests walk-forward optimization support in LEAN. This PR adds a core API contract and provider routing so algorithms can trigger optimization over time and apply chosen parameters without hard-coding a single execution backend.

Requires Documentation Change

Yes. If accepted, documentation should describe the new Optimize(...) API and the walk-forward-optimization-* configuration keys for local and cloud execution.

How Has This Been Tested?

Local environment: macOS, .NET SDK in this checkout.

  • dotnet build Tests/QuantConnect.Tests.csproj /p:Configuration=Debug /v:quiet
  • Focused walk-forward optimization tests: 13 passed
  • Optimizer regression tests: 186 passed
  • git diff --check origin/master...HEAD

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed. I ran the build, focused WFO tests, and optimizer regression coverage listed above; I did not run the entire repository test suite locally.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

Disclosure: I used AI-assisted coding tools while preparing this PR. I reviewed the changes myself, tested them, and take responsibility for the implementation and any follow-up revisions needed.

Adds QCAlgorithm Optimize overloads backed by a pluggable walk-forward optimization provider contract in Common, including request/result DTOs and Python wrapper forwarding.

Verification: dotnet build Tests/QuantConnect.Tests.csproj /p:Configuration=Debug /v:quiet in the SDS Lean workspace; PYTHONNET_PYDLL=/usr/local/lib/libpython3.13.so dotnet test Tests/bin/Debug/QuantConnect.Tests.dll --filter FullyQualifiedName~AlgorithmWalkForwardOptimizationTests.
Exports the walk-forward optimization provider contract through Composer and injects the configured provider when LocalLeanManager receives the algorithm.

Verification: dotnet build Tests/QuantConnect.Tests.csproj /p:Configuration=Debug /v:quiet; PYTHONNET_PYDLL=/usr/local/lib/libpython3.13.so dotnet test Tests/bin/Debug/QuantConnect.Tests.dll --filter FullyQualifiedName~WalkForwardOptimizationProviderRoutingTests.
Adds local and cloud walk-forward optimization providers, captures lightweight optimizer backtests for selector flows, and covers target, selector, timeout, abort, and engine-routing behavior with focused tests.

Verification: dotnet build Tests/QuantConnect.Tests.csproj /p:Configuration=Debug /v:quiet; dotnet test QuantConnect.Tests.dll --filter WFO provider/algorithm/routing filters; dotnet test QuantConnect.Tests.dll --filter FullyQualifiedName~QuantConnect.Tests.Optimizer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant