Skip to content

Commit daa08eb

Browse files
committed
added equity forward
1 parent 806e384 commit daa08eb

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

src/core/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ impl EngineType {
3939
#[derive(Clone,Debug,Deserialize,Serialize)]
4040
pub struct MarketData {
4141
pub underlying_price:f64,
42-
pub option_type:String,
43-
pub strike_price:f64,
42+
pub option_type:Option<String>,
43+
pub strike_price:Option<f64>,
4444
pub volatility:Option<f64>,
4545
pub option_price:Option<f64>,
4646
pub risk_free_rate:Option<f64>,

src/equity/equity_forward.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use chrono::NaiveDate;
2+
use crate::core::quotes::Quote;
3+
use crate::equity::utils::LongShort;
4+
pub struct EquityForward {
5+
pub underlying_price: Quote,
6+
pub forward_price: Quote,
7+
pub risk_free_rate: f64,
8+
pub dividend_yield: f64,
9+
pub maturity_date: NaiveDate,
10+
pub valuation_date: NaiveDate,
11+
pub long_short:LongShort,
12+
pub notional:f64
13+
}
14+

src/equity/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ pub mod finite_difference;
1010
pub mod binary_option;
1111
mod equity_future;
1212
pub mod handle_equity_contracts;
13+
mod equity_forward;

src/equity/utils.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ pub enum Engine{
1212
Binomial,
1313
FiniteDifference
1414
}
15-
15+
pub enum LongShort{
16+
LONG,
17+
SHORT
18+
}
1619
#[derive(Deserialize, Debug)]
1720
#[serde(rename_all = "snake_case")]
1821
pub enum PayoffType {

src/equity/vanila_option.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,16 @@ impl EquityOption{
7979
}
8080
}
8181
impl EquityOption {
82-
//pub fn new(x:T)->Self{
83-
//
84-
//}
82+
8583
pub fn from_json(data: &Contract) -> Box<EquityOption> {
8684
let payoff_type = data.payoff_type.as_ref().unwrap().parse::<PayoffType>();
8785
let market_data = data.market_data.as_ref().unwrap();
88-
let option_type = &market_data.option_type;
86+
//let option_type = &market_data.option_type;
8987
let side: OptionType;
88+
let option_type = match &market_data.option_type {
89+
Some(x) => x.clone(),
90+
None => "".to_string(),
91+
};
9092
match option_type.trim() {
9193
"C" | "c" | "Call" | "call" => side = OptionType::Call,
9294
"P" | "p" | "Put" | "put" => side = OptionType::Put,
@@ -130,7 +132,7 @@ impl EquityOption {
130132
transection: Transection::Buy,
131133
underlying_price: underlying_quote,
132134
current_price: option_price,
133-
strike_price: market_data.strike_price,
135+
strike_price: market_data.strike_price.unwrap_or(0.0),
134136
volatility: volatility,
135137
maturity_date: future_date,
136138
risk_free_rate: risk_free_rate.unwrap_or(0.0),

src/utils/parse_json.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ pub fn process_contract(data: &Contract) -> String {
120120
let curr_quote = Quote::new( market_data.underlying_price);
121121
let option_type = &market_data.option_type;
122122
let side: trade::OptionType;
123+
let option_type = match &market_data.option_type {
124+
Some(x) => x.clone(),
125+
None => "".to_string(),
126+
};
123127
match option_type.trim() {
124128
"C" | "c" | "Call" | "call" => side = trade::OptionType::Call,
125129
"P" | "p" | "Put" | "put" => side = trade:: OptionType::Put,
@@ -138,7 +142,7 @@ pub fn process_contract(data: &Contract) -> String {
138142
option_type: side,
139143
transection: trade::Transection::Buy,
140144
current_price: curr_quote,
141-
strike_price: market_data.strike_price,
145+
strike_price: market_data.strike_price.unwrap_or(0.0),
142146
volatility: vol.unwrap(),
143147
time_to_maturity: year_fraction,
144148
transection_price: 0.0,

0 commit comments

Comments
 (0)