Skip to content

fix(examples): shrink simulation grids (#385, #386)#392

Merged
joaquinbejar merged 1 commit into
mainfrom
issue-385-386-example-fixes
Apr 20, 2026
Merged

fix(examples): shrink simulation grids (#385, #386)#392
joaquinbejar merged 1 commit into
mainfrom
issue-385-386-example-fixes

Conversation

@joaquinbejar
Copy link
Copy Markdown
Owner

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:

  • `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:

Closes #385 and #386 (fast-path for every failing / timing-out example caught by the runner).

Test plan

  • Every listed example binary runs in `debug` mode under ~5–10 s with exit code 0.
  • `cargo build --all-features` / `cargo clippy --all-targets --all-features -- -D warnings` / `cargo fmt --all --check` clean.
  • `cargo test --lib --all-features` — 3760 passed, 0 failed.

…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).
@joaquinbejar joaquinbejar requested a review from Copilot April 20, 2026 05:54
@joaquinbejar joaquinbejar merged commit d9b0587 into main Apr 20, 2026
13 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to examples_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);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day);
let dt = convert_time_frame(Positive::ONE, &TimeFrame::Hour, &TimeFrame::Day);

Copilot uses AI. Check for mistakes.
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);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day);
let dt = convert_time_frame(Positive::ONE, &TimeFrame::Hour, &TimeFrame::Day);

Copilot uses AI. Check for mistakes.
Comment on lines +123 to 127
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)?;

Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
// 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);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
let dt = convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day);
let dt = convert_time_frame(Positive::ONE, &TimeFrame::Hour, &TimeFrame::Day);

Copilot uses AI. Check for mistakes.
},
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),
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
dt: convert_time_frame(Positive::ONE / days, &TimeFrame::Hour, &TimeFrame::Day),
dt: convert_time_frame(Positive::ONE, &TimeFrame::Hour, &TimeFrame::Day),

Copilot uses AI. Check for mistakes.
joaquinbejar added a commit that referenced this pull request Apr 20, 2026
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
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

joaquinbejar added a commit that referenced this pull request Apr 20, 2026
* 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.
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.

examples: missing data fixtures (17 failing)

2 participants