Commit 0c12afd
authored
Multiple example binaries panicked mid-optimizer-scan with
`Positive invariant broken` because strategy P&L and break-even
expressions crossed the `Positive` boundary with an unchecked
`Add<Decimal>` / `Sub<Positive>`:
- `CallButterfly::update_break_even_points`: `strike ± profit/qty`
replaced by `Positive::new_decimal(..)` on the underlying `Decimal`
sum; out-of-range candidates are dropped cleanly instead of
panicking.
- `CallButterfly::get_profit_area`: `be[1] - be[0]` and
`short_high_strike - short_low_strike` lowered to `Decimal` first
then wrapped; non-positive widths fall back to `Positive::ZERO`.
- `LongButterflySpread::update_break_even_points`: same `Positive
± Decimal` guard.
- `BullPutSpread::get_max_loss`: width computed as `Decimal`,
wrapped with `Positive::new_decimal(..).map_err` instead of
`Positive - Positive`; inverted-strike candidates return a typed
`MaxLossError` instead of panicking.
Unblocks the following example binaries mid-optimizer-scan:
`strategy_call_butterfly_best_{area,ratio}`,
`strategy_long_butterfly_spread_best_{area,ratio}`,
`strategy_call_butterfly_delta`,
`strategy_bull_put_spread_extended_delta`.
Closes #387.
1 parent 594164b commit 0c12afd
3 files changed
Lines changed: 45 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
| |||
612 | 611 | | |
613 | 612 | | |
614 | 613 | | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
620 | 619 | | |
621 | | - | |
| 620 | + | |
622 | 621 | | |
623 | | - | |
624 | | - | |
625 | | - | |
| 622 | + | |
626 | 623 | | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
627 | 632 | | |
628 | 633 | | |
629 | 634 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
390 | 391 | | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
397 | 399 | | |
398 | 400 | | |
399 | 401 | | |
| |||
722 | 724 | | |
723 | 725 | | |
724 | 726 | | |
725 | | - | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
726 | 731 | | |
727 | | - | |
728 | | - | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
729 | 736 | | |
730 | 737 | | |
731 | 738 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
382 | | - | |
383 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
384 | 386 | | |
385 | 387 | | |
386 | 388 | | |
387 | | - | |
388 | | - | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
389 | 393 | | |
390 | 394 | | |
391 | 395 | | |
| |||
0 commit comments