/****************************************************************************** Author: Joaquín Béjar García Email: jb@taunais.com Date: 25/9/24 ******************************************************************************/ use optionstratlib::model::types::ExpirationDate; use optionstratlib::model::types::PositiveF64; use optionstratlib::pos; use optionstratlib::strategies::base::Strategies; use optionstratlib::strategies::bull_call_spread::BullCallSpread; use optionstratlib::utils::logger::setup_logger; use optionstratlib::visualization::utils::Graph; use std::error::Error; use tracing::info; fn main() -> Result<(), Box> { setup_logger(); let underlying_price = pos!(5781.88); let strategy = BullCallSpread::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()); info!("Max Loss: ${:0.2}", strategy.max_loss()); 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_call_spread_profit_loss_chart.png", 20, (1400, 933), )?; Ok(()) }