fix(examples): shrink simulation grids (#385, #386)#392
Conversation
…de (#385, #386) The simulation-heavy demo binaries used a minute-level grid (10 080 steps × 100 simulations, 43 200 steps for the chain walker) that was fine as a benchmark but blew past the example-runner's 25 s debug-mode budget. Drop to an hourly grid with a tenth of the simulation count — the code paths (Simulate trait, random-walk-of-OptionChain, position simulator) are exercised end-to-end, just on a proportionate dataset. Affected binaries: - examples_simulation::long_call_strategy_simulation - examples_simulation::short_put_strategy_simulation - examples_simulation::position_simulator - examples_simulation::strategy_simulator - examples_simulation::random_walk_chain Also cut the `examples_volatility::test` brute-force scan from 1 000 000 to 10 000 iterations; the example is meant to demo the Black-Scholes error landscape, not to run a local benchmark. And apply cargo-fmt to `examples_chain::async_chain_ops` after its tempdir rewrite in #388. Closes #385 and #386 (fast-path for every failing/timing-out example caught by the runner).
There was a problem hiding this comment.
Pull request overview
Reduces runtime of several example binaries so they complete within CI’s debug-mode time budget, while still exercising the same end-to-end simulation/volatility code paths.
Changes:
- Shrink simulation grids in
examples_simulation(minute → hour resolution, fewer sims/steps). - Reduce brute-force iteration count in
examples_volatility::test(1,000,000 → 10,000). - Apply
cargo fmt-style formatting toexamples_chain::async_chain_ops.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/examples_volatility/src/bin/test.rs | Lowers demo loop iterations to avoid timeouts. |
| examples/examples_simulation/src/bin/strategy_simulator.rs | Uses hourly grid and smaller simulator size for faster runs. |
| examples/examples_simulation/src/bin/short_put_strategy_simulation.rs | Reduces simulation count/steps and switches to hourly grid. |
| examples/examples_simulation/src/bin/random_walk_chain.rs | Reduces walk length and switches to hourly grid. |
| examples/examples_simulation/src/bin/position_simulator.rs | Uses hourly grid and smaller simulator size for faster runs. |
| examples/examples_simulation/src/bin/long_call_strategy_simulation.rs | Reduces simulation count/steps and switches to hourly grid. |
| examples/examples_chain/src/bin/async_chain_ops.rs | Formatting-only changes to logging output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let days = pos_or_panic!(7.0); | ||
| let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Minute, &TimeFrame::Day); | ||
| let volatility_dt = volatility_for_dt(iv, dt, TimeFrame::Minute, TimeFrame::Day)?; | ||
| let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day); |
There was a problem hiding this comment.
dt is being computed as Positive::ONE / days converted from hours to days, which makes the per-step time increment depend on the total horizon (for 7 days this yields 1/(7*24) day ≈ 8.6 minutes). Since Xstep advances by 1 hour and n_steps = 7*24, dt should represent a 1-hour step (e.g., convert 1 hour to days or years) so the stochastic process scale matches the grid/expiration.
| let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day); | |
| let dt = convert_time_frame(Positive::ONE, &TimeFrame::Hour, &TimeFrame::Day); |
| let days = pos_or_panic!(7.0); | ||
| let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Minute, &TimeFrame::Day); | ||
| let volatility_dt = volatility_for_dt(iv, dt, TimeFrame::Minute, TimeFrame::Day)?; | ||
| let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day); |
There was a problem hiding this comment.
dt is computed as (1/days) hours converted to days, which yields a step size smaller than 1 hour (e.g., for 7 days: 1/168 day). Because Xstep uses a 1-hour TimeFrame::Hour step and n_steps = 7*24, the random-walk dt should reflect a single 1-hour increment (convert 1 hour to the chosen base unit) to keep the diffusion scaling consistent with the grid.
| let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day); | |
| let dt = convert_time_frame(Positive::ONE, &TimeFrame::Hour, &TimeFrame::Day); |
| let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day); | ||
|
|
||
| // Adjust volatility for the specific dt in the random walk | ||
| let volatility_dt = | ||
| volatility_for_dt(implied_volatility, dt, TimeFrame::Minute, TimeFrame::Day)?; | ||
| let volatility_dt = volatility_for_dt(implied_volatility, dt, TimeFrame::Hour, TimeFrame::Day)?; | ||
|
|
There was a problem hiding this comment.
dt is derived from Positive::ONE / days in hours, which makes the per-step time increment depend on the total horizon (7 days -> 1/168 day). With Xstep advancing by 1 hour and n_steps = 7*24, dt should represent a single 1-hour step (convert 1 hour to the base unit) so the simulated volatility/drift scale matches the hourly grid.
| // Create WalkParams for the Simulator | ||
| let walker = Box::new(Walker); | ||
| let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Minute, &TimeFrame::Day); | ||
| let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day); |
There was a problem hiding this comment.
dt is computed as (1/days) hours converted to days, which makes each step smaller than 1 hour (7 days -> 1/168 day). Since the walk grid is hourly (Xstep uses TimeFrame::Hour with step size 1 and n_steps = 7*24), dt should reflect a 1-hour increment (converted to the chosen base unit) so diffusion scaling matches the grid/expiration.
| let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day); | |
| let dt = convert_time_frame(Positive::ONE, &TimeFrame::Hour, &TimeFrame::Day); |
| }, | ||
| walk_type: WalkType::GeometricBrownian { | ||
| dt: convert_time_frame(Positive::ONE / days, &TimeFrame::Minute, &TimeFrame::Day), | ||
| dt: convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day), |
There was a problem hiding this comment.
dt is currently computed as (1/days) hours converted to days (for 2 days -> 1/48 day = 0.5 hour), but Xstep advances by 1 hour and n_steps = 2*24. dt should represent the per-step increment (1 hour converted to the base unit) so the random walk’s volatility scaling matches the stated 1-hour grid.
| dt: convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day), | |
| dt: convert_time_frame(Positive::ONE, &TimeFrame::Hour, &TimeFrame::Day), |
Bump version to `0.16.3` and document the example-runtime fixes that landed in #392. Tag + GitHub release + `make publish` follow immediately after merge.
Codecov Report✅ All modified and coverable lines are covered by tests. 🚀 New features to boost your workflow:
|
* release(0.16.3): bump + CHANGELOG for #385/#386 example-grid fixes Bump version to `0.16.3` and document the example-runtime fixes that landed in #392. Tag + GitHub release + `make publish` follow immediately after merge. * feat(logging): replace `println!` with `tracing::info!` in unified_pricing example - Added `setup_logger` to initialize logging. - Replaced all `println!` calls with `info!` for structured logging. * feat(logging): replace `println!` with `tracing::info!` in delta_neutral and async_chain_ops - Added `setup_logger` to initialize logging in `async_chain_ops`. - Replaced all `println!` calls with `info!` to ensure structured logging consistency. * feat(logging): replace `println!` with `tracing::{info, error}` in async_ohlcv example - Added `setup_logger` to initialize structured logging. - Replaced all `println!` calls with `info!` and `error!` where appropriate for logging consistency. * feat(logging): integrate `tracing` in cliquet_example for structured logging - Added `setup_logger` to enable structured logging. - Replaced `println!` and `eprintln!` calls with `tracing::{info, error}` for consistency. * feat(logging): replace `println!` with `tracing::info!` across examples and metrics - Updated code to use `tracing::info!` for structured logging consistency. - Replaced `println!` calls in `volatility_smile`, `implied_volatility`, `risk_reversal`, and other affected modules. - Ensures uniform logging practices across all examples and libraries.
Summary
Example binaries that previously timed out in the runner used a minute-level grid (10 080 steps × 100 simulations, 43 200 for the chain walker) that was fine as a benchmark but blew past the 25 s debug-mode budget.
Drop to an hourly grid with a tenth of the simulation count — every code path (Simulate trait, random-walk-of-OptionChain, position simulator, Heston / custom / Brownian walk params) is still exercised end-to-end, just on a proportionate dataset.
Affected binaries:
Also:
Closes #385 and #386 (fast-path for every failing / timing-out example caught by the runner).
Test plan