Skip to content

Commit

Permalink
Refactor get profit range (#42)
Browse files Browse the repository at this point in the history
* Update version

* Correct distributions in support.py

* Update test_core.py

* Black source

* Update CHANGELOG.md

* Update version to 1.3.3

* Updated CHANGELOG.md

* Update docstrings in support.py

* Update docstrings in engine.py and black-scholes.py

* Update docstrings in plot.py

* Update docstrings in utils.py

* Updated docstrings models.py

* Update CHANGELOG.MD, change functions in utils.py and update docstrings in utils.py and models.py

* Update docstrings in black-scholes.py

* Update docstrings in plot.py

* Update docstrings in models.py and comment unnecessary code

* Update docstrings in support.py

* Updated CHANGELOG.md

* Updated docstrings in black-scholes.py

* Black source

* Change version to 1.3.4

* Update .gitignore

* Add Rho calculation

* Update tests

* Update examples

* Black source

* Update library version

* Add Laplace distribution and Calendar Spread as tests

* Blacked source

* Changed some class names in models.py

* Added dict argument to get_pop()

* Black source

* Improve get_pop and engine.py

* Update examples

* Updated examples and blacked source

* Updated README.md

* Blacked source

* Update CHANGELOG.md

* Update README.md
  • Loading branch information
rgaveiga authored Jan 23, 2025
1 parent 00f5628 commit f05b0cc
Show file tree
Hide file tree
Showing 26 changed files with 3,214 additions and 2,816 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
.benchmarks
.mypy_cache
.pytest_cache
__pycache__
dist
run_check
examples/.ipynb_checkpoints
optionlab/__pycache__
tests/__pycache__
tests/.benchmarks
*.old
89 changes: 81 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,96 @@
# CHANGELOG

## 1.4.1 (2025-01-04)

- Removed a small bug in `create_price_seq` in support.py
- Improved the algorithm in `get_profit_range` in support.py, then renamed to `_get_profit_range`
- Created a helper function `_get_sign_changes` in support.py, called by `get_profit_range`
- Removed the fields `probability_of_profit_from_mc`, `average_profit_from_mc` and `average_loss_from_mc` from `Outputs` in models.py
- Created the fields `expected_profit` and `expected_loss` in `Outputs` in models.py
- Created a class `PoPOutputs` in models.py containing fields returned by `get_pop` in support.py
- Removed Laplace form `get_pop` in support.py
- Improved `get_pop` in support.py to return a `PoPOutputs` object with more information
- Added naked calls as an example of strategy
- Created a custom type `FloatOrNdarray` that can contain a float or a numpy.ndarray in models.py
- Created the helper functions `_get_pop_bs` and `get_pop_array` in support.py

## 1.4.0 (2025-01-01)

- Changed the class name `DistributionInputs` to `TheoreticalModelInputs` in models.py, to be more descriptive
- Changed the class name `DistributionBlackScholesInputs` to `BlackScholesModelInputs` in models.py
- Changed the class name `DistributionLaplaceInputs` to `LaplaceInputs` in models.py
- Changed the class name `DistributionArrayInputs` to `ArrayInputs` in models.py
- Changed literal `Distribution` to `TheoreticalModel`
- Moved `create_price_samples` from support.py to a new module price_array.py and renamed it to `create_price_array`
- Commented a code snippet in engine.py where terminal stock prices are created using `create_price_samples`, to be removed in a next version
- Allowed a dictionary as input for `create_price_array` in price_array.py
- Allowed a dictionary as input for `get_pop` in support.py

## 1.3.5 (2024-12-28)

- Created a base class `DistributionInputs`
- Changed the name of `ProbabilityOfProfitInputs` in models.py (and everywhere in the code) to `DistributionBlackScholesInputs`, which inherits from `DistributionInputs`
- Removed the `source` field from `DistributionBlackScholesInputs`
- Modified interest_rate: float = Field(0.0, ge=0.0) in `DistributionBlackScholesInputs` in models.py
- Modified volatility: float = Field(gt=0.0) in `DistributionInputs` in models.py
- Modified years_to_maturity: float = Field(ge=0.0) in `DistributionInputs` in models.py
- Created a class `DistributionLaplaceInputs` in models.py, which inherits from `DistributionInputs`
- Changed `years_to_maturity` field in `DistributionInputs` to `years_to_target_date`
- Refactored `create_price_samples` in support.py
- Added __hash__ = object.__hash__ in `DistributionBlackScholesInputs` and `DistributionLaplaceInputs` in models.py to allow their use in `create_price_samples` in support.py with caching
- Updated tests to reflect those changes
- Removed a deprecated class, `StrategyEngine`, commented in a previous version
- Added a test for Laplace distribution
- Added a test for Calendar Spread

## 1.3.4 (2024-12-20)

- Deleted `OptionInfo` class in models.py, because it is not necessary
- Deleted `return_in_the_domain_ratio` in `Outputs` in models.py
- Deleted `Country` in models.py, because it is not necessary
- Deleted source: Literal["array"] = "array" in `ProbabilityOfProfitArrayInputs` class in models.py, because it is not necessary
- Strike prices in black_scholes.py functions now can be provided also as numpy arrays and those functions return numpy arrays
- `BlackScholesInfo` fields in models.py now can be both float and numpy arrays
- Split `get_d1_d2` function in black_scholes.py into two functions, `get_d1` and `get_d2`
- Added the field `business_days_in_year` in `Inputs` class in models.py to allow market-dependent customization; also changed in engine.py
- Added Greek Rho calculation to black-scholes.py
- Added `call_rho` and `put_rho` fields to `BlackScholesInfo` in models.py
- Added `rho` field to `EngineData` in models.py
- Added `rho` field to `Outputs` in models.py
- Added `rho` data field in engine.py
- Added a `seed` argument to `create_price_samples` in support.py to make the generation of price samples deterministic
- Changed `array_prices` field to simply `array` in `Inputs` in models.py
- Changed and commented some tests in test_core.py

## 1.3.3 (2024-12-18)

- Updated docstrings to comply with reStructuredText (RST) standards
- Changed the `country` argument in `get_nonbusiness_days` in utils.py to accept a string
- Changed the `data` argument in `get_pl` and `pl_to_csv` in utils.py to accept an `Outputs` object instead of `EngineData`
- Commented 'source: Literal["array"] = "array"' in `ProbabilityOfProfitArrayInputs` class in models.py, because `source` is not necessary
- Commented `OptionInfo` class in models.py, because it is not used anywhere
- Commented `return_in_the_domain_ratio` in `Outputs` in models.py, because it is not necessary
- Commented `Country` in models.py, because it is not necessary
- Changed country: Country = "US" to country: str = "US" in models.py

## 1.3.2 (2024-11-30)

- Changed Laplace distribution implementation in `create_price_samples` and `get_pop` functions in support.py.
- Changed Laplace distribution implementation in `create_price_samples` and `get_pop` functions in support.py

## 1.3.1 (2024-09-27)

- discriminator="type" removed from strategy: list[StrategyLeg] = Field(..., min_length=1) in models.py, since
it was causing errors in new Pydantic versions.
- Changed StotckStrategy and OptionStrategy to Stock and Option in models.py, respectively.
- Changed BaseStrategy to BaseLeg in models.py.
- Changed Strategy to StrategyLeg in models.py.
- Removed premium field from Stock in models.py.
- Moved n field to BaseLeg in models.py.
- Changed `StotckStrategy` and `OptionStrategy` to `Stock` and `Option` in models.py, respectively.
- Changed `BaseStrategy` to `BaseLeg` in models.py
- Changed `Strategy` to `StrategyLeg` in models.py
- Removed `premium` field from `Stock` in models.py
- Moved `n` field to `BaseLeg` in models.py

## 1.3.0 (2024-09-13)

- Remove the deprecated `StrategyEngine` class (it remains commented in the code).
- Update the README.md file to reflect the current state of the library.
- Update the README.md file to reflect the current state of the library

## 1.2.1 (2024-06-03)

Expand All @@ -28,7 +101,7 @@ it was causing errors in new Pydantic versions.

## 1.2.0 (2024-03-31)

- Add functions to run engine.
- Add functions to run engine

## 1.1.0 (2024-03-24)

Expand Down
Loading

0 comments on commit f05b0cc

Please sign in to comment.