@@ -25,6 +25,8 @@ use crate::rates::deposits::Deposit;
2525use crate :: rates:: build_contracts:: { build_ir_contracts, build_ir_contracts_from_json, build_term_structure} ;
2626use crate :: equity:: build_contracts:: { build_eq_contracts_from_json} ;
2727use crate :: equity:: vol_surface:: VolSurface ;
28+ use crate :: equity:: handle_equity_contracts:: handle_equity_contract;
29+
2830use rayon:: prelude:: * ;
2931/// This function saves the output to a file and returns the path to the file.
3032pub fn save_to_file < ' a > ( output_folder : & ' a str , subfolder : & ' a str , filename : & ' a str , output : & ' a str ) -> String {
@@ -110,24 +112,18 @@ pub fn process_contract(data: &Contract) -> String {
110112 let ts = YieldTermStructure :: new ( date, rates) ;
111113
112114 if data. action =="PV" && data. asset =="EQ" {
113- //let market_data = data.market_data.clone().unwrap();
114- let option = EquityOption :: from_json ( & data) ;
115- let contract_output = ContractOutput { pv : option. npv ( ) , delta : option. delta ( ) , gamma : option. gamma ( ) ,
116- vega : option. vega ( ) , theta : option. theta ( ) , rho : option. rho ( ) , error : None } ;
117- println ! ( "Theoretical Price ${}" , contract_output. pv) ;
118- println ! ( "Delta ${}" , contract_output. delta) ;
119- let combined_ = CombinedContract {
120- contract : data. clone ( ) ,
121- output : contract_output
122- } ;
123- let output_json = serde_json:: to_string ( & combined_) . expect ( "Failed to generate output" ) ;
124- return output_json;
115+ return handle_equity_contract ( data) ;
116+
125117 }
126118 else if data. action =="PV" && data. asset =="CO" {
127119 let market_data = data. market_data . clone ( ) . unwrap ( ) ;
128120 let curr_quote = Quote :: new ( market_data. underlying_price ) ;
129121 let option_type = & market_data. option_type ;
130122 let side: trade:: OptionType ;
123+ let option_type = match & market_data. option_type {
124+ Some ( x) => x. clone ( ) ,
125+ None => "" . to_string ( ) ,
126+ } ;
131127 match option_type. trim ( ) {
132128 "C" | "c" | "Call" | "call" => side = trade:: OptionType :: Call ,
133129 "P" | "p" | "Put" | "put" => side = trade:: OptionType :: Put ,
@@ -146,7 +142,7 @@ pub fn process_contract(data: &Contract) -> String {
146142 option_type : side,
147143 transection : trade:: Transection :: Buy ,
148144 current_price : curr_quote,
149- strike_price : market_data. strike_price ,
145+ strike_price : market_data. strike_price . unwrap_or ( 0.0 ) ,
150146 volatility : vol. unwrap ( ) ,
151147 time_to_maturity : year_fraction,
152148 transection_price : 0.0 ,
0 commit comments