1- //! Options pricing models.
1+ //! Module for various option pricing models.
2+ //!
3+ //! ## Supported models
4+ //!
5+ //! - [Black-Scholes Option Pricing Model](black_scholes/struct.BlackScholesOption.html)
6+ //! - [Binomial Option Pricing Model](binomial_tree/struct.BinomialTreeOption.html)
7+ //! - [Monte Carlo Option Pricing Model](monte_carlo/struct.MonteCarloOption.html)
8+ //!
9+ //! ## Greek calculations
10+ //!
11+ //! This module also provides implementations of the Greeks for each option pricing model.
12+ //! See the [Greeks](options/trait.Greeks.html) trait for more information.
213
314pub mod binomial_tree;
415pub mod black_scholes;
@@ -7,17 +18,16 @@ pub mod monte_carlo;
718
819pub use binomial_tree:: BinomialTreeOption ;
920pub use black_scholes:: BlackScholesOption ;
10- pub use greeks:: Greeks ;
1121pub use greeks:: OptionGreeks ;
1222pub use monte_carlo:: MonteCarloOption ;
13-
14- /// Enum representing the type of option.
15- # [ derive ( Clone , Copy ) ]
16- pub enum OptionType {
17- /// Call option
18- Call ,
19- /// Put option
20- Put ,
23+ /// Supertrait that combines OptionPricing and Greeks.
24+ pub trait Option : OptionPricing + Greeks {
25+ /// Get the style of the option.
26+ ///
27+ /// # Returns
28+ ///
29+ /// The style of the option.
30+ fn style ( & self ) -> & OptionStyle ;
2131}
2232
2333/// Trait for option pricing models.
@@ -44,9 +54,122 @@ pub trait OptionPricing {
4454 ///
4555 /// The implied volatility.
4656 fn implied_volatility ( & self , market_price : f64 , option_type : OptionType ) -> f64 ;
57+
58+ /// Calculate the payoff of the option at maturity.
59+ ///
60+ /// # Arguments
61+ ///
62+ /// * `underlying_price` - The price of the underlying asset at maturity.
63+ /// * `option_type` - The type of option (Call or Put).
64+ ///
65+ /// # Returns
66+ ///
67+ /// The payoff of the option.
68+ fn payoff ( & self , spot : f64 , option_type : OptionType ) -> f64 {
69+ match option_type {
70+ OptionType :: Call => ( spot - self . strike ( ) ) . max ( 0.0 ) ,
71+ OptionType :: Put => ( self . strike ( ) - spot) . max ( 0.0 ) ,
72+ }
73+ }
74+
75+ /// Get the strike price of the option.
76+ ///
77+ /// # Returns
78+ ///
79+ /// The strike price of the option.
80+ fn strike ( & self ) -> f64 ;
81+ }
82+
83+ /// Trait for calculating the Greeks of an option.
84+ pub trait Greeks {
85+ // First order Greeks
86+ /// Delta measures the rate of change of the option price with respect to changes in the price of the underlying asset.
87+ fn delta ( & self , option_type : OptionType ) -> f64 ;
88+ /// Gamma measures the rate of change of the option delta with respect to changes in the price of the underlying asset.
89+ fn gamma ( & self , option_type : OptionType ) -> f64 ;
90+ /// Theta measures the rate of change of the option price with respect to changes in time to maturity.
91+ fn theta ( & self , option_type : OptionType ) -> f64 ;
92+ /// Vega measures the rate of change of the option price with respect to changes in the volatility of the underlying asset.
93+ fn vega ( & self , option_type : OptionType ) -> f64 ;
94+ /// Rho measures the rate of change of the option price with respect to changes in the risk-free interest rate.
95+ fn rho ( & self , option_type : OptionType ) -> f64 ;
96+
97+ // Higher order Greeks
98+ /// Lambda measures the rate of change of the option delta with respect to changes in the risk-free interest rate.
99+ fn lambda ( & self , option_type : OptionType ) -> f64 {
100+ 0.0 // Placeholder value
101+ }
102+ /// Vanna measures the rate of change of the option delta with respect to changes in the volatility of the underlying asset.
103+ fn vanna ( & self , option_type : OptionType ) -> f64 {
104+ 0.0 // Placeholder value
105+ }
106+ /// Charm measures the rate of change of the option delta with respect to changes in time to maturity.
107+ fn charm ( & self , option_type : OptionType ) -> f64 {
108+ 0.0 // Placeholder value
109+ }
110+ /// Vomma measures the rate of change of the option vega with respect to changes in the volatility of the underlying asset.
111+ fn vomma ( & self , option_type : OptionType ) -> f64 {
112+ 0.0 // Placeholder value
113+ }
114+ /// Veta measures the rate of change of the option vega with respect to changes in time to maturity.
115+ fn veta ( & self , option_type : OptionType ) -> f64 {
116+ 0.0 // Placeholder value
117+ }
118+ /// Speed measures the rate of change of the option gamma with respect to changes in the price of the underlying asset.
119+ fn speed ( & self , option_type : OptionType ) -> f64 {
120+ 0.0 // Placeholder value
121+ }
122+ /// Zomma measures the rate of change of the option gamma with respect to changes in the volatility of the underlying asset.
123+ fn zomma ( & self , option_type : OptionType ) -> f64 {
124+ 0.0 // Placeholder value
125+ }
126+ /// Color measures the rate of change of the option gamma with respect to changes in time to maturity.
127+ fn color ( & self , option_type : OptionType ) -> f64 {
128+ 0.0 // Placeholder value
129+ }
130+ /// Ultima measures the rate of change of the option vomma with respect to changes in the volatility of the underlying asset.
131+ fn ultima ( & self , option_type : OptionType ) -> f64 {
132+ 0.0 // Placeholder value
133+ }
134+ }
135+
136+ /// Enum representing the type of option.
137+ #[ derive( Clone , Copy , Debug ) ]
138+ pub enum OptionType {
139+ /// Call option (gives the holder the right to buy the underlying asset)
140+ Call ,
141+ /// Put option (gives the holder the right to sell the underlying asset)
142+ Put ,
47143}
48144
49- /// A supertrait that combines OptionPricing and Greeks.
50- pub trait Option : OptionPricing + Greeks { }
145+ /// Enum representing the style of the option.
146+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
147+ pub enum OptionStyle {
148+ /// American option (can be exercised at any time)
149+ American ,
150+ /// European option (default, can be exercised only at expiration)
151+ European ,
152+ /// Bermudan option (can be exercised at specific dates)
153+ Bermudan ,
154+ /// Asian option (payoff depends on average price of underlying asset)
155+ Asian ,
156+ /// Barrier option (payoff depends on whether underlying asset crosses a barrier)
157+ Barrier ,
158+ /// Binary option (payout is fixed amount or nothing)
159+ Binary ,
160+ /// Digital option (payout is fixed amount or nothing; also known as cash-or-nothing or asset-or-nothing option)
161+ Digital ,
162+ /// Lookback option (payoff depends on extrema of underlying asset)
163+ Lookback ,
164+ }
51165
52- impl < T : OptionPricing + Greeks > Option for T { }
166+ impl Default for OptionStyle {
167+ /// Default option style is European.
168+ ///
169+ /// # Returns
170+ ///
171+ /// The default option style.
172+ fn default ( ) -> Self {
173+ OptionStyle :: European
174+ }
175+ }
0 commit comments