-
Notifications
You must be signed in to change notification settings - Fork 29
Feature/strike undelying price positivef64 #12
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
joaquinbejar
merged 29 commits into
main
from
feature/strike_undelying_price_positivef64
Oct 5, 2024
Merged
Feature/strike undelying price positivef64 #12
joaquinbejar
merged 29 commits into
main
from
feature/strike_undelying_price_positivef64
Oct 5, 2024
Conversation
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
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.
11 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
use PositiveF64 for Strikes and underlying prices