Skip to content

Commit

Permalink
serialize vol term structure
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthqs committed Oct 28, 2023
1 parent aa9a5a8 commit 458ba18
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions derivatives/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion derivatives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ rand = "0.8.4"
rand_distr = "0.4.3"
probability = "0.18.0"
libm = "0.2.1"
chrono = "0.4.22"
chrono = {version = "0.4.22",features = ["serde"]}
csv = "1.1"
rand_chacha = "0.3.1"
rand_pcg = " 0.3.1"
Expand Down
2 changes: 0 additions & 2 deletions derivatives/src/equity/vanila_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ impl EquityOption {
}
}
option.set_risk_free_rate();
println!("{:?}", option);
//option.volatility = option.imp_vol(option.current_price.value);
return Box::new(option);
}
}
3 changes: 2 additions & 1 deletion derivatives/src/equity/vol_surface.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};
use crate::rates::utils::{DayCountConvention};
use chrono::{NaiveDate};
#[derive(Clone,Debug)]
#[derive(Clone,Debug,Serialize,Deserialize)]
pub struct VolSurface{
pub term_structure: BTreeMap<NaiveDate, Vec<(f64,f64)>>,
pub spot: f64,
Expand Down
2 changes: 1 addition & 1 deletion derivatives/src/rates/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn adjust_for_weekend(mut date: NaiveDate) -> NaiveDate {
}
date
}
#[derive(Clone,Debug)]
#[derive(Clone,Debug,Serialize,Deserialize)]
pub enum DayCountConvention{
Act365,
Act360,
Expand Down
7 changes: 5 additions & 2 deletions derivatives/src/utils/parse_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ pub fn build_curve(mut file: &mut File,output_filename: &str)->() {
if !vol_dir.exists() {
let _ = fs::create_dir(vol_dir);
}
dir.push("vol_surface.csv");
dir.push("vol_surface.json");
//Todo write Vol Surface to file
println!("{:?}",vol_surface);

let mut file = File::create(dir).expect("Failed to create file");
let mut output: String = String::new();
let serialized_vol_surface = serde_json::to_string(&vol_surface).unwrap();
file.write_all(serialized_vol_surface.as_bytes()).expect("Failed to write to file");

}
else if list_contracts.asset=="CO"{
Expand Down

0 comments on commit 458ba18

Please sign in to comment.