Skip to main content

rustyqlib/core/
data_models.rs

1use serde::{Deserialize, Serialize};
2use crate::core::curves::CurveInput;
3use crate::core::vols::VolInput;
4
5#[derive(Clone, Debug, Deserialize, Serialize)]
6#[serde(tag = "product_type", rename_all = "snake_case")]
7pub enum ProductData {
8    Option(EquityOptionData),
9    Future(EquityFutureData),
10    Forward(EquityForwardData),
11    RainbowOption(crate::equity::rainbow::RainbowOptionData),
12}
13
14#[derive(Clone, Debug, Deserialize, Serialize)]
15pub struct EquityInstrumentBase {
16    pub symbol: String,
17    pub currency: Option<String>,
18    pub exchange: Option<String>,
19    pub name: Option<String>,
20    pub cusip: Option<String>,
21    pub isin: Option<String>,
22    pub underlying_price: f64,
23    pub long_short: Option<i32>,
24    pub risk_free_rate: Option<f64>,
25    /// Continuous stock borrow (repo) cost; enters the carry like an
26    /// additional dividend yield (hard-to-borrow lowers the forward).
27    pub borrow_cost: Option<f64>,
28    pub settlement_type: Option<String>,
29}
30
31/// A discrete cash dividend: ex-date and amount per share.
32#[derive(Clone, Debug, Deserialize, Serialize)]
33pub struct CashDividendData {
34    pub date: String,
35    pub amount: f64,
36}
37
38
39#[derive(Clone, Debug, Deserialize, Serialize)]
40pub struct EquityFutureData {
41    #[serde(flatten)]
42    pub base: EquityInstrumentBase,
43    pub current_price: Option<f64>,
44    pub multiplier:Option<f64>,
45    pub entry_price:Option<f64>,
46    pub maturity: String,
47    pub dividend: Option<f64>,
48
49}
50#[derive(Clone, Debug, Deserialize, Serialize)]
51pub struct EquityForwardData {
52    #[serde(flatten)]
53    pub base: EquityInstrumentBase,
54    pub current_price: Option<f64>,
55    pub notional: Option<f64>,
56    pub entry_price:Option<f64>,
57    pub maturity: String,
58    pub dividend: Option<f64>,
59
60}
61
62#[derive(Clone, Debug, Deserialize, Serialize)]
63pub struct EquityOptionData {
64    #[serde(flatten)]
65    pub base: EquityInstrumentBase,
66    pub put_or_call: String, // "Call"/"Put"
67    pub payoff_type: String, // Vanilla/Barrier/Binary
68    /// Binary settlement: "cash" (default) or "asset".
69    pub binary_type: Option<String>,
70    /// Amount paid by a cash-or-nothing binary (default 1.0).
71    pub cash_amount: Option<f64>,
72    /// Barrier variant: "up_in" | "up_out" | "down_in" | "down_out".
73    pub barrier_type: Option<String>,
74    pub barrier_level: Option<f64>,
75    /// Asian averaging: "arithmetic" (default) | "geometric".
76    pub averaging_type: Option<String>,
77    /// Asian strike: "fixed" (default, average price) | "floating" (average strike).
78    pub asian_strike_type: Option<String>,
79    /// Forward-start: strike fixing date and strike as a fraction of the
80    /// fixing spot (default 1.0).
81    pub forward_start_date: Option<String>,
82    pub strike_fraction: Option<f64>,
83    /// Autocallable: early-redemption and knock-in protection levels
84    /// (absolute), per-period coupon (rebate), observation count, notional.
85    pub autocall_barrier: Option<f64>,
86    pub protection_barrier: Option<f64>,
87    pub autocall_coupon: Option<f64>,
88    pub autocall_observations: Option<usize>,
89    pub notional: Option<f64>,
90    /// Discrete cash dividends (ex-date + amount per share).
91    pub cash_dividends: Option<Vec<CashDividendData>>,
92    /// When set, the option is on a future (Black-76): "discounted"
93    /// (standard) or "margined" (futures-style). `underlying_price` is then
94    /// the futures price.
95    pub futures_settlement: Option<String>,
96    /// Strike; required for vanilla/binary/barrier/asian payoffs, unused
97    /// for forward-start and autocallable contracts.
98    pub strike_price: Option<f64>,
99    /// Constant volatility; the simple alternative to `vol_surface`.
100    pub volatility: Option<f64>,
101    pub maturity: String,
102    pub dividend: Option<f64>,
103    pub current_price: Option<f64>,
104    pub multiplier:Option<f64>,
105    pub entry_price:Option<f64>,
106    /// Monte Carlo path count (engine "MC" only).
107    pub simulation: Option<u64>,
108    /// MC time steps: 1 = terminal simulation; > 1 = path-wise stepping.
109    pub mc_time_steps: Option<usize>,
110    /// "exact" (default) | "euler" | "milstein"
111    pub mc_scheme: Option<String>,
112    /// "sobol" (default, low-discrepancy) | "pseudo" (seeded PCG64)
113    pub mc_sampler: Option<String>,
114    pub mc_seed: Option<u64>,
115    /// "gbm" (default, constant vol) | "local_vol" (Dupire from the
116    /// option's vol surface). Applies to the MonteCarlo and
117    /// FiniteDifference engines.
118    pub mc_model: Option<String>,
119    /// Finite difference grid nodes in spot (default 400).
120    pub fd_spot_steps: Option<usize>,
121    /// Finite difference time steps (default 400).
122    pub fd_time_steps: Option<usize>,
123    /// Heston parameters; required when `mc_model` is "heston".
124    pub heston: Option<crate::equity::heston::HestonParams>,
125    pub exercise_style: Option<String>, //European, American,
126    pub pricer:Option<String>,
127    /// Optional discount curve; when absent a flat curve is built from
128    /// `risk_free_rate` (which stays the simple way to specify a rate).
129    pub discount_curve: Option<CurveInput>,
130    /// Optional volatility surface; when absent a flat surface is built
131    /// from `volatility`. One of the two must be provided.
132    pub vol_surface: Option<VolInput>,
133}
134