-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add orchestrated backtest pipeline (sweep -> walk-forward -> monte carlo) #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
deb13d8
feat: add orchestrated backtest pipeline (sweep -> walk-forward -> mo…
claude 8f0f777
feat: add REST API routes for backtest pipeline
claude 20dba27
test: add pipeline integration tests for gate scenarios
claude d363c4b
refactor: remove MCP walk_forward tool (now pipeline-only)
claude a23fc32
fix: address PR review comments on pipeline implementation
claude b106a94
fix: address round 2 PR review comments
claude a75c7b1
fix: pass original sweep base_params through pipeline to walk-forward
claude 387e50f
chore: change pipeline default to false (opt-in)
claude 566a664
Merge remote-tracking branch 'origin/main' into claude/document-backt…
claude 71ee428
Update src/tools/pipeline.rs
michaelchu 96790b9
Update src/tools/pipeline.rs
michaelchu 82fcbcc
Update src/server/handlers/pipeline.rs
michaelchu 33a507f
Fix pipeline review feedback
michaelchu 0b628f7
Fix pipeline clippy warning
michaelchu c1907a0
Fix pipeline handler docs
michaelchu 5ab626a
Align pipeline defaults and docs
michaelchu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| //! REST API handler for the backtest pipeline. | ||
| //! | ||
| //! Runs the full analysis pipeline | ||
| //! (`sweep` -> `significance_gate` -> `walk-forward` -> `oos_data_gate` -> `monte carlo`) | ||
| //! and returns a `PipelineResponse` with stage statuses. | ||
| //! Monte Carlo may be skipped when earlier gates do not pass. | ||
|
|
||
| use axum::extract::State; | ||
| use axum::http::StatusCode; | ||
| use axum::Json; | ||
| use garde::Validate; | ||
| use serde::Deserialize; | ||
| use serde_json::Value; | ||
| use std::collections::HashMap; | ||
|
|
||
| use crate::server::handlers::sweeps::SweepParamDef; | ||
| use crate::server::state::AppState; | ||
| use crate::tools::backtest::BacktestToolParams; | ||
| use crate::tools::response_types::pipeline::PipelineResponse; | ||
|
|
||
| fn default_mode() -> String { | ||
| "grid".to_string() | ||
| } | ||
|
|
||
| fn default_objective() -> String { | ||
| "sharpe".to_string() | ||
| } | ||
|
|
||
| fn default_max_evaluations() -> usize { | ||
| 50 | ||
| } | ||
|
|
||
| /// Request body for `POST /runs/pipeline`. | ||
| #[derive(Debug, Deserialize)] | ||
| pub struct CreatePipelineRequest { | ||
| pub strategy: String, | ||
| #[serde(default = "default_mode")] | ||
| pub mode: String, | ||
| #[serde(default = "default_objective")] | ||
| pub objective: String, | ||
| pub params: HashMap<String, Value>, | ||
| pub sweep_params: Vec<SweepParamDef>, | ||
| #[serde(default = "default_max_evaluations")] | ||
| pub max_evaluations: usize, | ||
| #[serde(default)] | ||
| pub num_permutations: usize, | ||
| #[serde(default)] | ||
| pub thread_id: Option<String>, | ||
| } | ||
|
|
||
| pub(super) fn build_pipeline_params( | ||
| req: CreatePipelineRequest, | ||
| ) -> Result<BacktestToolParams, (StatusCode, String)> { | ||
| if req.sweep_params.is_empty() { | ||
| return Err(( | ||
| StatusCode::BAD_REQUEST, | ||
| "sweep_params must be non-empty for pipeline execution".to_string(), | ||
| )); | ||
| } | ||
|
|
||
| let params = BacktestToolParams { | ||
| strategy: req.strategy, | ||
| mode: req.mode, | ||
| objective: req.objective, | ||
| params: req.params, | ||
| sweep_params: req.sweep_params, | ||
| max_evaluations: req.max_evaluations, | ||
| num_permutations: req.num_permutations, | ||
| thread_id: req.thread_id, | ||
| pipeline: true, | ||
| }; | ||
|
|
||
| params | ||
| .validate() | ||
| .map_err(|e| (StatusCode::BAD_REQUEST, format!("Validation error: {e}")))?; | ||
|
|
||
| Ok(params) | ||
| } | ||
|
|
||
| /// `POST /runs/pipeline` — run the full pipeline synchronously and return the result. | ||
| pub async fn create_pipeline( | ||
| State(state): State<AppState>, | ||
| Json(req): Json<CreatePipelineRequest>, | ||
| ) -> Result<Json<PipelineResponse>, (StatusCode, String)> { | ||
| let params = build_pipeline_params(req)?; | ||
|
|
||
| let result = crate::tools::backtest::execute(&state.server, params) | ||
| .await | ||
| .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; | ||
|
michaelchu marked this conversation as resolved.
michaelchu marked this conversation as resolved.
|
||
|
|
||
| // The pipeline path always returns BacktestToolResponse::Pipeline | ||
| match result { | ||
| crate::tools::backtest::BacktestToolResponse::Pipeline(response) => Ok(Json(*response)), | ||
| _ => Err(( | ||
| StatusCode::INTERNAL_SERVER_ERROR, | ||
| "Pipeline mode did not return a pipeline response".to_string(), | ||
| )), | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.