Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4813e04
Bump version to 0.2.3
joaquinbejar Nov 30, 2024
7b024c7
Add probability analysis for option strategies
joaquinbejar Nov 30, 2024
b547fb4
Reorganize module imports for clarity and readability
joaquinbejar Dec 1, 2024
3d5d406
Refactor ProfitRange::new function calls
joaquinbejar Dec 1, 2024
093e044
Rename and enhance `assert_decimal_relative_eq` macro
joaquinbejar Dec 1, 2024
2d19d42
Refactor code by removing unnecessary line breaks.
joaquinbejar Dec 1, 2024
734be0d
Add default probability analysis behavior and testing
joaquinbejar Dec 1, 2024
f2f0dce
Refactor project structure for improved organization.
joaquinbejar Dec 1, 2024
754c2f3
Make utility and probabilities modules public.
joaquinbejar Dec 2, 2024
6cc692a
Add probability analysis to strangle strategies
joaquinbejar Dec 2, 2024
27b3fb8
Merge pull request #39 from joaquinbejar/feature/#36-Implement-Succes…
joaquinbejar Dec 2, 2024
ec0ed11
Add long and short straddle P&L charts; optimize strangle.rs
joaquinbejar Dec 4, 2024
3296d3d
Merge pull request #40 from joaquinbejar/feature/#26-Implement-Stradd…
joaquinbejar Dec 4, 2024
8d82152
Add new strategy scripts and profit/loss graph files
joaquinbejar Dec 5, 2024
bf732a0
Add bull put and bear call spread strategy modules
joaquinbejar Dec 5, 2024
0fc09a0
Organize module imports in mod.rs.
joaquinbejar Dec 6, 2024
0ce7fbc
Refactor strategy functions to return Result type
joaquinbejar Dec 6, 2024
622f25e
Make `OptionData` struct public
joaquinbejar Dec 6, 2024
a063cf2
Make OptimizationCriteria enum public
joaquinbejar Dec 6, 2024
fb3a3d5
Add Optimizable trait usage and remove unused methods
joaquinbejar Dec 6, 2024
7f4b096
Refactor max_profit and max_loss to return Result types.
joaquinbejar Dec 6, 2024
beeb46d
Refactor strangle strategies for error handling
joaquinbejar Dec 6, 2024
d5ef113
Add error handling for profit and loss calculations
joaquinbejar Dec 6, 2024
1e7c591
Refactor profit and loss functions to return Result type
joaquinbejar Dec 6, 2024
4602a2c
Add error handling to call butterfly strategy calculations
joaquinbejar Dec 6, 2024
74118aa
Handle potential errors in BullCallSpread calculations
joaquinbejar Dec 6, 2024
f41ec6c
Implement Bear Call Spread Strategy with Visualization
joaquinbejar Dec 6, 2024
a3060fa
Merge pull request #43 from joaquinbejar/feature/#41-Bear-Call-Spread…
joaquinbejar Dec 6, 2024
a2488ec
Remove expiration date check in bear call spread strategy
joaquinbejar Dec 6, 2024
1abc957
Implement Bull Put Spread strategy with validation and tests
joaquinbejar Dec 6, 2024
4d84be2
Merge pull request #44 from joaquinbejar/feature/#42-Bull-Put-Spread-…
joaquinbejar Dec 6, 2024
dee692a
Refactor option validity check
joaquinbejar Dec 6, 2024
f3394b3
Simplify option validation logic
joaquinbejar Dec 6, 2024
ce5c012
Enhance Bull Call Spread Strategy implementation
joaquinbejar Dec 6, 2024
685aff9
Merge pull request #45 from joaquinbejar/feature/#17-Implement-Bull-C…
joaquinbejar Dec 6, 2024
c26d822
Add script to detect and process Spanish comments
joaquinbejar Dec 6, 2024
2e7f353
Remove inline comments from strategies and tests
joaquinbejar Dec 6, 2024
c29a5b1
Remove trailing whitespace across codebase
joaquinbejar Dec 6, 2024
37fe6b1
Remove trailing whitespace in bull_put_spread.rs
joaquinbejar Dec 6, 2024
737c047
Add bear put spread strategy with optimization
joaquinbejar Dec 6, 2024
d4fd34e
Merge pull request #46 from joaquinbejar/feature/#16-Implement-Bear-P…
joaquinbejar Dec 6, 2024
75efbd1
Update strategies to handle potential None values.
joaquinbejar Dec 6, 2024
b811c0e
Organize import statements in strategy examples.
joaquinbejar Dec 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# will have compiled files and executables
debug/
target/
**/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
**/Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
Expand Down
18 changes: 16 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "optionstratlib"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
authors = ["Joaquin Bejar <[email protected]>"]
description = "OptionStratLib is a comprehensive Rust library for options trading and strategy development across multiple asset classes."
Expand All @@ -11,6 +11,7 @@ homepage = "https://github.com/joaquinbejar/OptionStratLib"
keywords = ["finance", "options", "trading"]
categories = ["finance", "data-structures"]


include = [
"src/**/*.rs",
"Cargo.toml",
Expand All @@ -29,7 +30,7 @@ include = [
chrono = "0.4.38"
approx = "0.5.1"
plotters = "0.3.7"
statrs = "0.17.1"
statrs = "0.18.0"
rand = "0.8.5"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
Expand All @@ -48,3 +49,16 @@ path = "tests/unit/mod.rs"
name = "optionstratlib"
path = "src/lib.rs"

[workspace]
members = [
"examples/examples_simulation",
"examples/examples_strategies_best",
"examples/examples_strategies",
"examples/examples_visualization",
"examples/examples_chain",
"examples/examples_volatility",
]

[workspace.dependencies]
optionstratlib = { path = "." }
tracing = "0.1.41"
Binary file modified Draws/Simulation/option_chain_from_random_walk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Draws/Strategy/bull_call_spread_profit_loss_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Draws/Strategy/iron_condor_profit_loss_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Draws/Strategy/short_strangle_delta_profit_loss_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Draws/Strategy/short_strangle_profit_loss_chart_best_area.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[![Coverage](https://img.shields.io/codecov/c/github/joaquinbejar/OptionStratLib)](https://codecov.io/gh/joaquinbejar/OptionStratLib)
[![Dependencies](https://img.shields.io/librariesio/github/joaquinbejar/OptionStratLib)](https://libraries.io/github/joaquinbejar/OptionStratLib)

# OptionStratLib v0.2.2: Financial Options Library
# OptionStratLib v0.2.3: Financial Options Library

## Table of Contents
1. [Introduction](#introduction)
Expand Down
9 changes: 9 additions & 0 deletions examples/examples_chain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "examples_chain"
version = "0.1.0"
edition = "2021"

[dependencies]
optionstratlib = { path = "../.." }
tracing = "0.1.41"

File renamed without changes.
9 changes: 9 additions & 0 deletions examples/examples_simulation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "examples_simulation"
version = "0.1.0"
edition = "2021"

[dependencies]
optionstratlib = { path = "../.." }
tracing = "0.1.41"

File renamed without changes.
9 changes: 9 additions & 0 deletions examples/examples_strategies/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "examples_strategies"
version = "0.1.0"
edition = "2021"

[dependencies]
optionstratlib = { path = "../.." }
tracing = "0.1.41"
chrono = "0.4.38"
62 changes: 62 additions & 0 deletions examples/examples_strategies/src/bin/strategy_bear_call_spread.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/******************************************************************************
Author: Joaquín Béjar García
Email: [email protected]
Date: 25/9/24
******************************************************************************/
use optionstratlib::model::types::PositiveF64;
use optionstratlib::model::types::{ExpirationDate, PZERO};
use optionstratlib::pos;
use optionstratlib::strategies::base::Strategies;
use optionstratlib::strategies::bear_call_spread::BearCallSpread;
use optionstratlib::utils::logger::setup_logger;
use optionstratlib::visualization::utils::Graph;
use std::error::Error;
use tracing::info;

fn main() -> Result<(), Box<dyn Error>> {
setup_logger();

let underlying_price = pos!(5781.88);

let strategy = BearCallSpread::new(
"SP500".to_string(),
underlying_price, // underlying_price
pos!(5750.0), // long_strike_itm
pos!(5820.0), // short_strike
ExpirationDate::Days(2.0),
0.18, // implied_volatility
0.05, // risk_free_rate
0.0, // dividend_yield
pos!(2.0), // long quantity
85.04, // premium_long
29.85, // premium_short
0.78, // open_fee_long
0.78, // open_fee_long
0.73, // close_fee_long
0.73, // close_fee_short
);

let price_range = strategy.best_range_to_show(pos!(1.0)).unwrap();

info!("Title: {}", strategy.title());
info!("Break Even Points: {:?}", strategy.break_even_points);
info!(
"Net Premium Received: ${:.2}",
strategy.net_premium_received()
);
info!("Max Profit: ${:.2}", strategy.max_profit().unwrap_or(PZERO));
info!("Max Loss: ${:0.2}", strategy.max_loss().unwrap_or(PZERO));
info!("Total Fees: ${:.2}", strategy.fees());
info!("Profit Area: {:.2}%", strategy.profit_area());
info!("Profit Ratio: {:.2}%", strategy.profit_ratio());

// Generate the profit/loss graph
strategy.graph(
&price_range,
"Draws/Strategy/bear_call_spread_profit_loss_chart.png",
20,
(1400, 933),
)?;

Ok(())
}
62 changes: 62 additions & 0 deletions examples/examples_strategies/src/bin/strategy_bear_put_spread.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/******************************************************************************
Author: Joaquín Béjar García
Email: [email protected]
Date: 25/9/24
******************************************************************************/
use optionstratlib::model::types::PositiveF64;
use optionstratlib::model::types::{ExpirationDate, PZERO};
use optionstratlib::pos;
use optionstratlib::strategies::base::Strategies;
use optionstratlib::strategies::bear_put_spread::BearPutSpread;
use optionstratlib::utils::logger::setup_logger;
use optionstratlib::visualization::utils::Graph;
use std::error::Error;
use tracing::info;

fn main() -> Result<(), Box<dyn Error>> {
setup_logger();

let underlying_price = pos!(5781.88);

let strategy = BearPutSpread::new(
"SP500".to_string(),
underlying_price, // underlying_price
pos!(5850.0), // long_strike
pos!(5720.0), // short_strike
ExpirationDate::Days(2.0),
0.18, // implied_volatility
0.05, // risk_free_rate
0.0, // dividend_yield
pos!(2.0), // long quantity
85.04, // premium_long
29.85, // premium_short
0.78, // open_fee_long
0.78, // open_fee_long
0.73, // close_fee_long
0.73, // close_fee_short
);

let price_range = strategy.best_range_to_show(pos!(1.0)).unwrap();

info!("Title: {}", strategy.title());
info!("Break Even Points: {:?}", strategy.break_even_points);
info!(
"Net Premium Received: ${:.2}",
strategy.net_premium_received()
);
info!("Max Profit: ${:.2}", strategy.max_profit().unwrap_or(PZERO));
info!("Max Loss: ${:0.2}", strategy.max_loss().unwrap_or(PZERO));
info!("Total Fees: ${:.2}", strategy.fees());
info!("Profit Area: {:.2}%", strategy.profit_area());
info!("Profit Ratio: {:.2}%", strategy.profit_ratio());

// Generate the profit/loss graph
strategy.graph(
&price_range,
"Draws/Strategy/bear_put_spread_profit_loss_chart.png",
20,
(1400, 933),
)?;

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Email: [email protected]
Date: 25/9/24
******************************************************************************/
use optionstratlib::model::types::ExpirationDate;
use optionstratlib::model::types::PositiveF64;
use optionstratlib::model::types::{ExpirationDate, PZERO};
use optionstratlib::pos;
use optionstratlib::strategies::base::Strategies;
use optionstratlib::strategies::bull_call_spread::BullCallSpread;
Expand Down Expand Up @@ -44,8 +44,8 @@ fn main() -> Result<(), Box<dyn Error>> {
"Net Premium Received: ${:.2}",
strategy.net_premium_received()
);
info!("Max Profit: ${:.2}", strategy.max_profit());
info!("Max Loss: ${:0.2}", strategy.max_loss());
info!("Max Profit: ${:.2}", strategy.max_profit().unwrap_or(PZERO));
info!("Max Loss: ${:0.2}", strategy.max_loss().unwrap_or(PZERO));
info!("Total Fees: ${:.2}", strategy.fees());
info!("Profit Area: {:.2}%", strategy.profit_area());
info!("Profit Ratio: {:.2}%", strategy.profit_ratio());
Expand Down
62 changes: 62 additions & 0 deletions examples/examples_strategies/src/bin/strategy_bull_put_spread.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/******************************************************************************
Author: Joaquín Béjar García
Email: [email protected]
Date: 25/9/24
******************************************************************************/
use optionstratlib::model::types::PositiveF64;
use optionstratlib::model::types::{ExpirationDate, PZERO};
use optionstratlib::pos;
use optionstratlib::strategies::base::Strategies;
use optionstratlib::strategies::bull_put_spread::BullPutSpread;
use optionstratlib::utils::logger::setup_logger;
use optionstratlib::visualization::utils::Graph;
use std::error::Error;
use tracing::info;

fn main() -> Result<(), Box<dyn Error>> {
setup_logger();

let underlying_price = pos!(5781.88);

let strategy = BullPutSpread::new(
"SP500".to_string(),
underlying_price, // underlying_price
pos!(5750.0), // long_strike_itm
pos!(5920.0), // short_strike
ExpirationDate::Days(2.0),
0.18, // implied_volatility
0.05, // risk_free_rate
0.0, // dividend_yield
pos!(2.0), // long quantity
15.04, // premium_long
89.85, // premium_short
0.78, // open_fee_long
0.78, // open_fee_long
0.73, // close_fee_long
0.73, // close_fee_short
);

let price_range = strategy.best_range_to_show(pos!(1.0)).unwrap();

info!("Title: {}", strategy.title());
info!("Break Even Points: {:?}", strategy.break_even_points);
info!(
"Net Premium Received: ${:.2}",
strategy.net_premium_received()
);
info!("Max Profit: ${:.2}", strategy.max_profit().unwrap_or(PZERO));
info!("Max Loss: ${:0.2}", strategy.max_loss().unwrap_or(PZERO));
info!("Total Fees: ${:.2}", strategy.fees());
info!("Profit Area: {:.2}%", strategy.profit_area());
info!("Profit Ratio: {:.2}%", strategy.profit_ratio());

// Generate the profit/loss graph
strategy.graph(
&price_range,
"Draws/Strategy/bull_put_spread_profit_loss_chart.png",
20,
(1400, 933),
)?;

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Email: [email protected]
Date: 25/9/24
******************************************************************************/
use optionstratlib::model::types::ExpirationDate;
use optionstratlib::model::types::PositiveF64;
use optionstratlib::model::types::{ExpirationDate, PZERO};
use optionstratlib::pos;
use optionstratlib::strategies::base::Strategies;
use optionstratlib::strategies::call_butterfly::CallButterfly;
Expand Down Expand Up @@ -48,8 +48,8 @@ fn main() -> Result<(), Box<dyn Error>> {
"Net Premium Received: ${:.2}",
strategy.net_premium_received()
);
info!("Max Profit: ${:.2}", strategy.max_profit());
info!("Max Loss: ${:0.2}", strategy.max_loss());
info!("Max Profit: ${:.2}", strategy.max_profit().unwrap_or(PZERO));
info!("Max Loss: ${:0.2}", strategy.max_loss().unwrap_or(PZERO));
info!("Total Fees: ${:.2}", strategy.fees());
info!(
"Range of Profit: ${:.2} {:.2}%",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Email: [email protected]
Date: 20/8/24
******************************************************************************/
use optionstratlib::model::types::ExpirationDate;
use optionstratlib::model::types::PositiveF64;
use optionstratlib::model::types::{ExpirationDate, PZERO};
use optionstratlib::pos;
use optionstratlib::strategies::base::Strategies;
use optionstratlib::strategies::bull_call_spread::BullCallSpread;
Expand Down Expand Up @@ -38,8 +38,8 @@ fn main() -> Result<(), Box<dyn Error>> {
info!("Title: {}", strategy.title());
info!("Break Even {:?}", strategy.break_even());
info!("Net Premium Received: {}", strategy.net_premium_received());
info!("Max Profit: {}", strategy.max_profit());
info!("Max Loss: {}", strategy.max_loss());
info!("Max Profit: {}", strategy.max_profit().unwrap_or(PZERO));
info!("Max Loss: {}", strategy.max_loss().unwrap_or(PZERO));
info!("Total Cost: {}", strategy.total_cost());

// Generate the intrinsic value graph
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use optionstratlib::model::types::ExpirationDate;
use optionstratlib::model::types::PositiveF64;
use optionstratlib::model::types::{ExpirationDate, PZERO};
use optionstratlib::pos;
use optionstratlib::strategies::base::Strategies;
use optionstratlib::strategies::iron_condor::IronCondor;
Expand Down Expand Up @@ -42,8 +42,8 @@ fn main() -> Result<(), Box<dyn Error>> {
"Net Premium Received: ${:.2}",
strategy.net_premium_received()
);
info!("Max Profit: ${:.2}", strategy.max_profit());
info!("Max Loss: ${:.2}", strategy.max_loss());
info!("Max Profit: ${:.2}", strategy.max_profit().unwrap_or(PZERO));
info!("Max Loss: ${:.2}", strategy.max_loss().unwrap_or(PZERO));
info!("Total Fees: ${:.2}", strategy.fees());
info!(
"Range of Profit: ${:.2} {:.2}%",
Expand Down
Loading
Loading