Skip to content

Conversation

@joaquinbejar
Copy link
Owner

use PositiveF64 for Strikes and underlying prices

Updated the calculate_price_range function to use the PositiveF64 type for start_price, end_price, and step parameters. This ensures that only positive floating-point numbers are used, improving the function's robustness and preventing potential runtime errors.
Refactored code to use the `pos!` macro for strike and underlying prices within test option creation. This change ensures consistency and potentially improves readability by centralizing the conversion logic for price values. Additionally, it aids in maintaining clean and more manageable code.
Changed underlying_price and strike_price parameters from f64 to PositiveF64 in option creation functions. Added helper macro pos! to maintain consistency and safety in the codebase. Furthermore, introduced a new function create_sample_option_simplest_strike to simplify strike price handling.
Enhanced the PositiveF64 type with various arithmetic operations and trait implementations, significantly boosting its versatility. Introduced macros for easier creation and adjusted existing option payoff calculations to leverage these improvements. This refactor improves code readability and maintainability.
Updated methods and data structures to use PositiveF64 instead of f64 for break-even points, ensuring all newly added break-even points are valid and positive. This change aims to improve the reliability and accuracy of calculations throughout the trading strategy module.
Updated the `calculate_axis_range` function to accept generic types for the x-axis data, allowing greater flexibility in the types of data it can process. Adjusted related function signatures and implemented necessary conversions to accommodate the changes.
This commit refactors the `Options` struct and associated methods to use `PositiveF64` instead of `f64` for fields that must always be positive. It also includes updates to tests and validation logic to ensure compliance with the new type constraints.
Refactor the `Position` struct to leverage `PositiveF64` for strike and underlying prices. This ensures type safety by preventing negative values for these fields. The change propagates through various methods, tests, and helper functions to maintain compatibility.
Replace `f64` fields in PayoffInfo with `PositiveF64` and update their default values from `ZERO` to `PZERO`. This change ensures that the `spot` and `strike` values always represent non-negative numbers.
Replaced floating-point types with PositiveF64 for asset and strike fields in BinomialPricingParams struct. Updated related function implementations and tests to ensure consistent usage of PositiveF64 for better type safety and input validation.
Implement subtraction operation to allow PositiveF64 type to be subtracted by f64. This enables more arithmetic manipulation of PositiveF64 values, enhancing the type's flexibility.
Updated the `IronCondor` struct to use the `PositiveF64` type for strike prices and other numeric parameters. This change ensures type safety and avoids potential runtime errors associated with negative values. Added necessary adjustments and helper functions to support the new PositiveF64 type throughout the implementation and tests.
Refactored the OptionData struct to use PositiveF64 type for the strike_price field. Updated related methods and tests to accommodate this change. Introduced a FromStr implementation for PositiveF64 to support parsing from string.
Updated the Range variant in OptimizationCriteria to use PositiveF64 for better type safety and to prevent potential negative values, ensuring more robust and correct optimization criteria handling.
Replaced the `underlying_price` field in `OptionChain` with the `PositiveF64` type for ensuring positive values. This change includes updates to the constructor, parsing logic, and all relevant tests to accommodate the new type.
Modified the BullCallSpread struct to use PositiveF64 for strike prices and other relevant fields. Updated method signatures and body implementations to reflect this change, improving type safety. Commented out incomplete break-even point handling for further review.
Adjusted various fields and functions within CallButterfly to utilize the PositiveF64 type where negative values are not appropriate. This includes underlying_price, strike prices, break-even points, and related calculations to improve type safety and ensure logical correctness.
Updated various fields and methods to use the PositiveF64 type instead of raw f64 for price-related data in the CustomStrategy struct. This ensures only positive float values are allowed, improving code safety and correctness.
Refactor `PoorMansCoveredCall` to ensure all critical fields like `underlying_price`, `long_call_strike`, `short_call_strike`, and `break_even_points` use the `PositiveF64` type. This change improves type safety by ensuring these values are always positive. Additionally, adjust related functions to work with the new type constraints.
This refactor involves changing several fields and function parameters in the ShortStrangle and LongStrangle structures to use the PositiveF64 type instead of f64. This ensures that only positive values are allowed for prices and strikes, enhancing the robustness and safety of these components.
Implemented the Profit trait for various strategies and consolidated profit calculations. Adjusted associated data types and removed redundant methods, improving the consistency and maintainability of the code.
Removed the `FloatLike` trait and its implementations, along with the `decimal.rs` module, to simplify the codebase. Updated visualization utilities and calculation functions to directly use `f64` and minimize redundancy.
Enhanced tests to better manage potential panic scenarios when assigning invalid values by isolating them in closures. Also, re-enabled and validated various time value calculations and payoff scenarios, ensuring accuracy and consistency with Black-Scholes evaluations.
Incorporated logging with tracing to capture spot and strike values during standard_payoff calculation for better debugging. Added comprehensive unit tests to verify the correctness of payoffs for European-style call and put options in various market conditions (in the money, at the money, out of the money).
Implemented a function `positive_f64_to_f64` to convert a vector of `PositiveF64` to `f64`. Added unit tests to ensure the function works with non-empty vectors, single elements, and handles invalid `PositiveF64` creation appropriately.
Refactor `PositiveF64` usage across the codebase for consistency, including updating methods to use `PositiveF64` type and implementing precision handling in `fmt::Display` and `fmt::Debug` traits. Adjust test cases to validate new behavior and update strategy logic to ensure break-even points are correctly computed and pushed.
Remove commented-out code from `utils.rs` and `base.rs` to enhance readability. Implement default behaviors for strategy methods in the `Strategies` trait, ensuring methods that are not applicable for certain strategies raise appropriate errors or return consistent values.
Updated the bull call spread strategy to calculate break-even using max profit, and adjusted tests accordingly. Enhanced the chart with additional points and vertical lines for better visual representation of profit/loss scenarios. Also, optimized imports and constants usage.
This commit standardizes code formatting across multiple files and tidies up the import statements by removing unnecessary ones and reordering them for better readability. These changes improve code consistency and maintainability.
@codecov
Copy link

codecov bot commented Oct 5, 2024

Codecov Report

Attention: Patch coverage is 54.08805% with 146 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/strategies/base.rs 0.00% 29 Missing ⚠️
src/strategies/bull_call_spread.rs 28.94% 27 Missing ⚠️
src/model/types.rs 62.68% 25 Missing ⚠️
src/strategies/strangle.rs 48.00% 13 Missing ⚠️
src/visualization/utils.rs 20.00% 12 Missing ⚠️
src/model/position.rs 52.63% 9 Missing ⚠️
src/strategies/call_butterfly.rs 50.00% 9 Missing ⚠️
src/strategies/poor_mans_covered_call.rs 0.00% 5 Missing ⚠️
src/model/chain.rs 33.33% 4 Missing ⚠️
src/model/option.rs 60.00% 4 Missing ⚠️
... and 4 more
Files with missing lines Coverage Δ
src/greeks/equations.rs 97.27% <100.00%> (+0.21%) ⬆️
src/greeks/utils.rs 100.00% <100.00%> (+1.96%) ⬆️
src/model/format.rs 89.72% <ø> (ø)
src/model/utils.rs 100.00% <100.00%> (ø)
src/pnl/utils.rs 0.00% <ø> (ø)
src/pricing/binomial_model.rs 90.76% <100.00%> (+0.14%) ⬆️
src/pricing/black_scholes_model.rs 61.11% <100.00%> (ø)
src/pricing/monte_carlo.rs 100.00% <100.00%> (ø)
src/pricing/telegraph.rs 100.00% <100.00%> (ø)
src/pricing/utils.rs 97.91% <100.00%> (ø)
... and 16 more

@joaquinbejar joaquinbejar merged commit d895cbb into main Oct 5, 2024
@joaquinbejar joaquinbejar deleted the feature/strike_undelying_price_positivef64 branch October 6, 2024 08:50
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.

2 participants