@@ -21,6 +21,7 @@ use crate::metrics::{
2121 TimeDecayCurve , TimeDecaySurface , VannaVolgaSurface , VolatilitySensitivityCurve ,
2222 VolatilitySensitivitySurface , VolatilitySkewCurve , VolumeProfileCurve , VolumeProfileSurface ,
2323} ;
24+ use crate :: model:: decimal:: d_add;
2425use crate :: model:: {
2526 BasicAxisTypes , ExpirationDate , OptionStyle , OptionType , Options , Position , Side ,
2627} ;
@@ -1941,7 +1942,11 @@ impl OptionChain {
19411942 pub fn gamma_exposure ( & self ) -> Result < Decimal , ChainError > {
19421943 let mut gamma_exposure = Decimal :: ZERO ;
19431944 for option in & self . options {
1944- gamma_exposure += option. gamma . unwrap_or ( Decimal :: ZERO ) ;
1945+ gamma_exposure = d_add (
1946+ gamma_exposure,
1947+ option. gamma . unwrap_or ( Decimal :: ZERO ) ,
1948+ "chains::gamma_exposure" ,
1949+ ) ?;
19451950 }
19461951 Ok ( gamma_exposure)
19471952 }
@@ -1968,8 +1973,16 @@ impl OptionChain {
19681973 pub fn delta_exposure ( & self ) -> Result < Decimal , ChainError > {
19691974 let mut delta_exposure = Decimal :: ZERO ;
19701975 for option in & self . options {
1971- delta_exposure += option. delta_call . unwrap_or ( Decimal :: ZERO ) ;
1972- delta_exposure += option. delta_put . unwrap_or ( Decimal :: ZERO ) ;
1976+ delta_exposure = d_add (
1977+ delta_exposure,
1978+ option. delta_call . unwrap_or ( Decimal :: ZERO ) ,
1979+ "chains::delta_exposure::call" ,
1980+ ) ?;
1981+ delta_exposure = d_add (
1982+ delta_exposure,
1983+ option. delta_put . unwrap_or ( Decimal :: ZERO ) ,
1984+ "chains::delta_exposure::put" ,
1985+ ) ?;
19731986 }
19741987 Ok ( delta_exposure)
19751988 }
@@ -1999,11 +2012,11 @@ impl OptionChain {
19992012 let vega = option_data
20002013 . get_option ( Side :: Long , OptionStyle :: Call ) ?
20012014 . vega ( ) ?;
2002- vega_exposure += vega;
2015+ vega_exposure = d_add ( vega_exposure , vega, "chains::vega_exposure::call" ) ? ;
20032016 let vega = option_data
20042017 . get_option ( Side :: Long , OptionStyle :: Put ) ?
20052018 . vega ( ) ?;
2006- vega_exposure += vega;
2019+ vega_exposure = d_add ( vega_exposure , vega, "chains::vega_exposure::put" ) ? ;
20072020 }
20082021 Ok ( vega_exposure)
20092022 }
@@ -2033,11 +2046,11 @@ impl OptionChain {
20332046 let theta = option_data
20342047 . get_option ( Side :: Long , OptionStyle :: Call ) ?
20352048 . theta ( ) ?;
2036- theta_exposure += theta;
2049+ theta_exposure = d_add ( theta_exposure , theta, "chains::theta_exposure::call" ) ? ;
20372050 let theta = option_data
20382051 . get_option ( Side :: Long , OptionStyle :: Put ) ?
20392052 . theta ( ) ?;
2040- theta_exposure += theta;
2053+ theta_exposure = d_add ( theta_exposure , theta, "chains::theta_exposure::put" ) ? ;
20412054 }
20422055 Ok ( theta_exposure)
20432056 }
@@ -2067,11 +2080,11 @@ impl OptionChain {
20672080 let vanna = option_data
20682081 . get_option ( Side :: Long , OptionStyle :: Call ) ?
20692082 . vanna ( ) ?;
2070- vanna_exposure += vanna;
2083+ vanna_exposure = d_add ( vanna_exposure , vanna, "chains::vanna_exposure::call" ) ? ;
20712084 let vanna = option_data
20722085 . get_option ( Side :: Long , OptionStyle :: Put ) ?
20732086 . vanna ( ) ?;
2074- vanna_exposure += vanna;
2087+ vanna_exposure = d_add ( vanna_exposure , vanna, "chains::vanna_exposure::put" ) ? ;
20752088 }
20762089 Ok ( vanna_exposure)
20772090 }
@@ -2100,11 +2113,11 @@ impl OptionChain {
21002113 let vomma = option_data
21012114 . get_option ( Side :: Long , OptionStyle :: Call ) ?
21022115 . vomma ( ) ?;
2103- vomma_exposure += vomma;
2116+ vomma_exposure = d_add ( vomma_exposure , vomma, "chains::vomma_exposure::call" ) ? ;
21042117 let vomma = option_data
21052118 . get_option ( Side :: Long , OptionStyle :: Put ) ?
21062119 . vomma ( ) ?;
2107- vomma_exposure += vomma;
2120+ vomma_exposure = d_add ( vomma_exposure , vomma, "chains::vomma_exposure::put" ) ? ;
21082121 }
21092122 Ok ( vomma_exposure)
21102123 }
@@ -2133,11 +2146,11 @@ impl OptionChain {
21332146 let veta = option_data
21342147 . get_option ( Side :: Long , OptionStyle :: Call ) ?
21352148 . veta ( ) ?;
2136- veta_exposure += veta;
2149+ veta_exposure = d_add ( veta_exposure , veta, "chains::veta_exposure::call" ) ? ;
21372150 let veta = option_data
21382151 . get_option ( Side :: Long , OptionStyle :: Put ) ?
21392152 . veta ( ) ?;
2140- veta_exposure += veta;
2153+ veta_exposure = d_add ( veta_exposure , veta, "chains::veta_exposure::put" ) ? ;
21412154 }
21422155 Ok ( veta_exposure)
21432156 }
@@ -2167,11 +2180,11 @@ impl OptionChain {
21672180 let charm = option_data
21682181 . get_option ( Side :: Long , OptionStyle :: Call ) ?
21692182 . charm ( ) ?;
2170- charm_exposure += charm;
2183+ charm_exposure = d_add ( charm_exposure , charm, "chains::charm_exposure::call" ) ? ;
21712184 let charm = option_data
21722185 . get_option ( Side :: Long , OptionStyle :: Put ) ?
21732186 . charm ( ) ?;
2174- charm_exposure += charm;
2187+ charm_exposure = d_add ( charm_exposure , charm, "chains::charm_exposure::put" ) ? ;
21752188 }
21762189 Ok ( charm_exposure)
21772190 }
@@ -2201,11 +2214,11 @@ impl OptionChain {
22012214 let color = option_data
22022215 . get_option ( Side :: Long , OptionStyle :: Call ) ?
22032216 . color ( ) ?;
2204- color_exposure += color;
2217+ color_exposure = d_add ( color_exposure , color, "chains::color_exposure::call" ) ? ;
22052218 let color = option_data
22062219 . get_option ( Side :: Long , OptionStyle :: Put ) ?
22072220 . color ( ) ?;
2208- color_exposure += color;
2221+ color_exposure = d_add ( color_exposure , color, "chains::color_exposure::put" ) ? ;
22092222 }
22102223 Ok ( color_exposure)
22112224 }
0 commit comments