pub struct VolSurface { /* private fields */ }Expand description
A canonical Black volatility surface anchored at reference_date.
Implementations§
Source§impl VolSurface
impl VolSurface
Sourcepub fn flat(
vol: f64,
reference_date: NaiveDate,
day_count: DayCountConvention,
) -> Result<Self, VolError>
pub fn flat( vol: f64, reference_date: NaiveDate, day_count: DayCountConvention, ) -> Result<Self, VolError>
Constant volatility for all strikes and expiries.
Examples found in repository?
34fn main() {
35 common::title("LOCAL VOLATILITY — quotes -> implied surface -> Dupire -> reprice");
36
37 let maturities = [
38 (NaiveDate::from_ymd_opt(2026, 7, 2).unwrap(), 0.23),
39 (NaiveDate::from_ymd_opt(2027, 1, 1).unwrap(), 0.25),
40 ];
41
42 common::section("Step 1: generate market quotes from a known skew");
43 println!(" sigma(K, T) = base(T) - 0.001 * (K - 100)");
44 let mut quotes = Vec::new();
45 for (maturity, base_vol) in maturities {
46 let t = (maturity - asof()).num_days() as f64 / 365.0;
47 for i in 0..13 {
48 let strike = 70.0 + 5.0 * i as f64;
49 let vol = true_vol(strike, base_vol);
50 let price = bs_price(SPOT, strike, RATE, 0.0, vol, t, PutOrCall::Call);
51 let mut option = EquityOptionBuilder::new()
52 .spot(SPOT)
53 .strike(strike)
54 .flat_vol(0.2) // placeholder: the solve does not use it
55 .flat_rate(RATE)
56 .valuation_date(asof())
57 .maturity_date(maturity)
58 .vanilla(PutOrCall::Call)
59 .build();
60 option.base.current_price = Quote::new(price);
61 quotes.push(Box::new(option));
62 }
63 }
64 println!(" {} quotes across {} expiries", quotes.len(), maturities.len());
65
66 common::section("Step 2: back out implied vols and build the surface");
67 let surface = build_implied_vol_surface("es).expect("calibration failed");
68 println!("{surface}");
69
70 common::section("Step 3: check the surface recovers the input smile");
71 for (t, base_vol) in [(182.0 / 365.0, 0.23), (1.0, 0.25)] {
72 for strike in [70.0, 85.0, 100.0, 115.0, 130.0] {
73 let recovered = surface.vol(strike, SPOT, t);
74 common::check(
75 &format!("T={t:.3} K={strike}"),
76 recovered,
77 true_vol(strike, base_vol),
78 1e-6,
79 );
80 }
81 }
82
83 common::section("Step 4: Dupire local volatility from that surface");
84 let curve =
85 YieldCurve::flat(RATE, asof(), DayCountConvention::Act365, Compounding::Continuous).unwrap();
86 let lv = LocalVol::new(&surface, &curve, SPOT, 0.0, 0.0);
87 println!(" {:>8} {:>12} {:>12} {:>12}", "level", "t=0.25", "t=0.50", "t=1.00");
88 for level in [70.0, 85.0, 100.0, 115.0, 130.0] {
89 println!(
90 " {level:>8.1} {:>12.4} {:>12.4} {:>12.4}",
91 lv.vol(level, 0.25),
92 lv.vol(level, 0.50),
93 lv.vol(level, 1.00)
94 );
95 }
96 common::note("local vol is steeper in strike than implied vol (the 'twice the slope' rule)");
97 common::note("the far wings are noisy: Dupire takes numerical derivatives of a");
98 common::note("piecewise-linear surface with flat extrapolation — trust the interior.");
99
100 common::section("Step 5: reprice the calibrating vanillas through local vol MC");
101 common::table_header();
102 for strike in [90.0, 100.0, 110.0] {
103 let expected = bs_price(SPOT, strike, RATE, 0.0, true_vol(strike, 0.25), 1.0, PutOrCall::Call);
104 common::row(
105 &format!("local vol MC, K={strike}"),
106 &EquityOptionBuilder::new()
107 .spot(SPOT)
108 .strike(strike)
109 .vol_surface(surface.clone())
110 .flat_rate(RATE)
111 .valuation_date(asof())
112 .maturity_date(NaiveDate::from_ymd_opt(2027, 1, 1).unwrap())
113 .vanilla(PutOrCall::Call)
114 .engine(Engine::MonteCarlo)
115 .model(McModel::LocalVol)
116 .paths(50_000)
117 .build(),
118 );
119 println!("{:<34} {expected:>12.6} <- Black-Scholes target at the quoted smile vol", "");
120 }
121
122 common::section("Local vol on the finite difference engine (no sampling noise)");
123 common::table_header();
124 for strike in [90.0, 100.0, 110.0] {
125 common::row(
126 &format!("local vol FD, K={strike}"),
127 &EquityOptionBuilder::new()
128 .spot(SPOT)
129 .strike(strike)
130 .vol_surface(surface.clone())
131 .flat_rate(RATE)
132 .valuation_date(asof())
133 .maturity_date(NaiveDate::from_ymd_opt(2027, 1, 1).unwrap())
134 .vanilla(PutOrCall::Call)
135 .engine(Engine::FiniteDifference)
136 .model(McModel::LocalVol)
137 .build(),
138 );
139 }
140
141 common::section("Sanity: a flat surface must give flat local vol");
142 let flat = VolSurface::flat(0.25, asof(), DayCountConvention::Act365).unwrap();
143 let flat_lv = LocalVol::new(&flat, &curve, SPOT, 0.0, 0.0);
144 for (level, t) in [(70.0, 0.25), (100.0, 1.0), (130.0, 2.0)] {
145 common::check(&format!("sigma_loc({level}, {t})"), flat_lv.vol(level, t), 0.25, 1e-6);
146 }
147
148 common::section("Term structure: local vol is the forward variance");
149 let term = VolSurface::from_strike_smiles(
150 &[Tenor::YearFraction(0.5), Tenor::YearFraction(1.0)],
151 &[vec![(100.0, 0.20)], vec![(100.0, 0.25)]],
152 asof(),
153 DayCountConvention::Act365,
154 )
155 .unwrap();
156 let term_lv = LocalVol::new(&term, &curve, SPOT, 0.0, 0.0);
157 // (0.25^2 * 1 - 0.20^2 * 0.5) / 0.5 = 0.085
158 common::check(
159 "sigma_loc between pillars = sqrt(fwd variance)",
160 term_lv.vol(100.0, 0.75),
161 0.085_f64.sqrt(),
162 1e-3,
163 );
164 println!();
165}Sourcepub fn from_strike_grid(
expiries: &[Tenor],
strikes: &[f64],
vols: &[Vec<f64>],
reference_date: NaiveDate,
day_count: DayCountConvention,
) -> Result<Self, VolError>
pub fn from_strike_grid( expiries: &[Tenor], strikes: &[f64], vols: &[Vec<f64>], reference_date: NaiveDate, day_count: DayCountConvention, ) -> Result<Self, VolError>
Absolute strike x expiry grid.
Examples found in repository?
50fn skewed_surface() -> VolSurface {
51 VolSurface::from_strike_grid(
52 &[Tenor::YearFraction(0.25), Tenor::YearFraction(0.5), Tenor::YearFraction(1.0)],
53 &[60.0, 70.0, 85.0, 100.0, 115.0, 130.0],
54 &[
55 vec![0.42, 0.38, 0.33, 0.29, 0.27, 0.26],
56 vec![0.41, 0.37, 0.33, 0.30, 0.28, 0.27],
57 vec![0.40, 0.37, 0.33, 0.30, 0.29, 0.28],
58 ],
59 asof(),
60 DayCountConvention::Act365,
61 )
62 .unwrap()
63}More examples
40fn main() {
41 common::title("BARRIER OPTIONS — S=100 K=100 sigma=30% r=5% q=2% T=1y");
42
43 common::section("All eight types, analytic (Reiner-Rubinstein)");
44 common::table_header();
45 for (dir, knock, pc, level) in [
46 (BarrierDirection::Down, KnockType::In, PutOrCall::Call, 90.0),
47 (BarrierDirection::Down, KnockType::Out, PutOrCall::Call, 90.0),
48 (BarrierDirection::Down, KnockType::In, PutOrCall::Put, 90.0),
49 (BarrierDirection::Down, KnockType::Out, PutOrCall::Put, 90.0),
50 (BarrierDirection::Up, KnockType::In, PutOrCall::Call, 120.0),
51 (BarrierDirection::Up, KnockType::Out, PutOrCall::Call, 120.0),
52 (BarrierDirection::Up, KnockType::In, PutOrCall::Put, 120.0),
53 (BarrierDirection::Up, KnockType::Out, PutOrCall::Put, 120.0),
54 ] {
55 common::row(
56 &format!("{dir:?}-and-{knock:?} {pc:?} H={level}"),
57 &base().barrier(pc, dir, knock, level).engine(Engine::BlackScholes).build(),
58 );
59 }
60
61 common::section("Engine comparison: down-and-out call, H=90");
62 common::table_header();
63 for (label, engine) in [
64 ("Analytical (Reiner-Rubinstein)", Engine::BlackScholes),
65 ("Finite difference (absorbing)", Engine::FiniteDifference),
66 ("Monte Carlo (Brownian bridge)", Engine::MonteCarlo),
67 ("Binomial (unsupported)", Engine::Binomial),
68 ] {
69 common::row(
70 label,
71 &base()
72 .barrier(PutOrCall::Call, BarrierDirection::Down, KnockType::Out, 90.0)
73 .engine(engine)
74 .build(),
75 );
76 }
77 common::note("MC applies a bridge crossing correction, so monitoring is effectively continuous");
78
79 common::section("In-out parity: KI + KO = vanilla");
80 let vanilla = base().vanilla(PutOrCall::Call).engine(Engine::BlackScholes).build();
81 for level in [80.0, 90.0, 99.0] {
82 let ki = base()
83 .barrier(PutOrCall::Call, BarrierDirection::Down, KnockType::In, level)
84 .engine(Engine::BlackScholes)
85 .build();
86 let ko = base()
87 .barrier(PutOrCall::Call, BarrierDirection::Down, KnockType::Out, level)
88 .engine(Engine::BlackScholes)
89 .build();
90 common::check(
91 &format!("H={level}: KI + KO"),
92 ki.npv() + ko.npv(),
93 vanilla.npv(),
94 1e-10,
95 );
96 }
97
98 common::section("Limits");
99 common::check(
100 "far barrier: KO call -> vanilla",
101 barrier_price(SPOT, STRIKE, 1e-4, RATE, DIV, VOL, 1.0, BarrierDirection::Down, KnockType::Out, PutOrCall::Call),
102 vanilla.npv(),
103 1e-9,
104 );
105 common::check(
106 "up-and-out call with K >= H is worthless",
107 barrier_price(SPOT, 110.0, 105.0, RATE, DIV, VOL, 1.0, BarrierDirection::Up, KnockType::Out, PutOrCall::Call),
108 0.0,
109 1e-12,
110 );
111 common::check(
112 "spot at barrier: KO = 0",
113 base()
114 .barrier(PutOrCall::Call, BarrierDirection::Down, KnockType::Out, SPOT)
115 .engine(Engine::BlackScholes)
116 .build()
117 .npv(),
118 0.0,
119 1e-12,
120 );
121
122 common::section("Barrier level sweep: down-and-out call");
123 common::table_header();
124 for level in [50.0, 70.0, 85.0, 95.0, 99.0] {
125 common::row(
126 &format!("H={level}"),
127 &base()
128 .barrier(PutOrCall::Call, BarrierDirection::Down, KnockType::Out, level)
129 .engine(Engine::BlackScholes)
130 .build(),
131 );
132 }
133 common::note("value decreases as the barrier approaches spot; delta can exceed 1 near it");
134
135 common::section("Smile matters: down-and-out call under local vol");
136 let skewed = VolSurface::from_strike_grid(
137 &[Tenor::YearFraction(0.5), Tenor::YearFraction(1.0), Tenor::YearFraction(2.0)],
138 &[70.0, 85.0, 100.0, 115.0, 130.0],
139 &[
140 vec![0.38, 0.34, 0.30, 0.28, 0.27],
141 vec![0.37, 0.34, 0.30, 0.29, 0.28],
142 vec![0.36, 0.33, 0.30, 0.29, 0.28],
143 ],
144 asof(),
145 DayCountConvention::Act365,
146 )
147 .unwrap();
148 common::table_header();
149 common::row(
150 "GBM (flat 30%)",
151 &base()
152 .barrier(PutOrCall::Call, BarrierDirection::Down, KnockType::Out, 90.0)
153 .engine(Engine::MonteCarlo)
154 .paths(50_000)
155 .build(),
156 );
157 common::row(
158 "Local vol (skewed surface)",
159 &base()
160 .vol_surface(skewed)
161 .barrier(PutOrCall::Call, BarrierDirection::Down, KnockType::Out, 90.0)
162 .engine(Engine::MonteCarlo)
163 .model(McModel::LocalVol)
164 .paths(50_000)
165 .build(),
166 );
167 common::note("downside skew raises the knock-out probability, lowering the price");
168 println!();
169}Sourcepub fn from_moneyness_grid(
expiries: &[Tenor],
moneyness: &[f64],
vols: &[Vec<f64>],
reference_date: NaiveDate,
day_count: DayCountConvention,
) -> Result<Self, VolError>
pub fn from_moneyness_grid( expiries: &[Tenor], moneyness: &[f64], vols: &[Vec<f64>], reference_date: NaiveDate, day_count: DayCountConvention, ) -> Result<Self, VolError>
Forward moneyness (K/F) x expiry grid.
Sourcepub fn from_delta_grid(
expiries: &[Tenor],
deltas: &[f64],
vols: &[Vec<f64>],
reference_date: NaiveDate,
day_count: DayCountConvention,
) -> Result<Self, VolError>
pub fn from_delta_grid( expiries: &[Tenor], deltas: &[f64], vols: &[Vec<f64>], reference_date: NaiveDate, day_count: DayCountConvention, ) -> Result<Self, VolError>
Forward call delta x expiry grid (FX convention). Each pillar is
converted to log-moneyness with its own quoted vol:
ln(K/F) = 0.5*sigma^2*t - sigma*sqrt(t)*inv_N(delta).
Sourcepub fn from_strike_smiles(
expiries: &[Tenor],
smiles: &[Vec<(f64, f64)>],
reference_date: NaiveDate,
day_count: DayCountConvention,
) -> Result<Self, VolError>
pub fn from_strike_smiles( expiries: &[Tenor], smiles: &[Vec<(f64, f64)>], reference_date: NaiveDate, day_count: DayCountConvention, ) -> Result<Self, VolError>
Per-expiry smiles on absolute strikes, where each expiry may have its
own strike list (as quoted option chains do): smiles[i] is a list of
(strike, vol) points for expiries[i], sorted by strike.
Examples found in repository?
34fn main() {
35 common::title("LOCAL VOLATILITY — quotes -> implied surface -> Dupire -> reprice");
36
37 let maturities = [
38 (NaiveDate::from_ymd_opt(2026, 7, 2).unwrap(), 0.23),
39 (NaiveDate::from_ymd_opt(2027, 1, 1).unwrap(), 0.25),
40 ];
41
42 common::section("Step 1: generate market quotes from a known skew");
43 println!(" sigma(K, T) = base(T) - 0.001 * (K - 100)");
44 let mut quotes = Vec::new();
45 for (maturity, base_vol) in maturities {
46 let t = (maturity - asof()).num_days() as f64 / 365.0;
47 for i in 0..13 {
48 let strike = 70.0 + 5.0 * i as f64;
49 let vol = true_vol(strike, base_vol);
50 let price = bs_price(SPOT, strike, RATE, 0.0, vol, t, PutOrCall::Call);
51 let mut option = EquityOptionBuilder::new()
52 .spot(SPOT)
53 .strike(strike)
54 .flat_vol(0.2) // placeholder: the solve does not use it
55 .flat_rate(RATE)
56 .valuation_date(asof())
57 .maturity_date(maturity)
58 .vanilla(PutOrCall::Call)
59 .build();
60 option.base.current_price = Quote::new(price);
61 quotes.push(Box::new(option));
62 }
63 }
64 println!(" {} quotes across {} expiries", quotes.len(), maturities.len());
65
66 common::section("Step 2: back out implied vols and build the surface");
67 let surface = build_implied_vol_surface("es).expect("calibration failed");
68 println!("{surface}");
69
70 common::section("Step 3: check the surface recovers the input smile");
71 for (t, base_vol) in [(182.0 / 365.0, 0.23), (1.0, 0.25)] {
72 for strike in [70.0, 85.0, 100.0, 115.0, 130.0] {
73 let recovered = surface.vol(strike, SPOT, t);
74 common::check(
75 &format!("T={t:.3} K={strike}"),
76 recovered,
77 true_vol(strike, base_vol),
78 1e-6,
79 );
80 }
81 }
82
83 common::section("Step 4: Dupire local volatility from that surface");
84 let curve =
85 YieldCurve::flat(RATE, asof(), DayCountConvention::Act365, Compounding::Continuous).unwrap();
86 let lv = LocalVol::new(&surface, &curve, SPOT, 0.0, 0.0);
87 println!(" {:>8} {:>12} {:>12} {:>12}", "level", "t=0.25", "t=0.50", "t=1.00");
88 for level in [70.0, 85.0, 100.0, 115.0, 130.0] {
89 println!(
90 " {level:>8.1} {:>12.4} {:>12.4} {:>12.4}",
91 lv.vol(level, 0.25),
92 lv.vol(level, 0.50),
93 lv.vol(level, 1.00)
94 );
95 }
96 common::note("local vol is steeper in strike than implied vol (the 'twice the slope' rule)");
97 common::note("the far wings are noisy: Dupire takes numerical derivatives of a");
98 common::note("piecewise-linear surface with flat extrapolation — trust the interior.");
99
100 common::section("Step 5: reprice the calibrating vanillas through local vol MC");
101 common::table_header();
102 for strike in [90.0, 100.0, 110.0] {
103 let expected = bs_price(SPOT, strike, RATE, 0.0, true_vol(strike, 0.25), 1.0, PutOrCall::Call);
104 common::row(
105 &format!("local vol MC, K={strike}"),
106 &EquityOptionBuilder::new()
107 .spot(SPOT)
108 .strike(strike)
109 .vol_surface(surface.clone())
110 .flat_rate(RATE)
111 .valuation_date(asof())
112 .maturity_date(NaiveDate::from_ymd_opt(2027, 1, 1).unwrap())
113 .vanilla(PutOrCall::Call)
114 .engine(Engine::MonteCarlo)
115 .model(McModel::LocalVol)
116 .paths(50_000)
117 .build(),
118 );
119 println!("{:<34} {expected:>12.6} <- Black-Scholes target at the quoted smile vol", "");
120 }
121
122 common::section("Local vol on the finite difference engine (no sampling noise)");
123 common::table_header();
124 for strike in [90.0, 100.0, 110.0] {
125 common::row(
126 &format!("local vol FD, K={strike}"),
127 &EquityOptionBuilder::new()
128 .spot(SPOT)
129 .strike(strike)
130 .vol_surface(surface.clone())
131 .flat_rate(RATE)
132 .valuation_date(asof())
133 .maturity_date(NaiveDate::from_ymd_opt(2027, 1, 1).unwrap())
134 .vanilla(PutOrCall::Call)
135 .engine(Engine::FiniteDifference)
136 .model(McModel::LocalVol)
137 .build(),
138 );
139 }
140
141 common::section("Sanity: a flat surface must give flat local vol");
142 let flat = VolSurface::flat(0.25, asof(), DayCountConvention::Act365).unwrap();
143 let flat_lv = LocalVol::new(&flat, &curve, SPOT, 0.0, 0.0);
144 for (level, t) in [(70.0, 0.25), (100.0, 1.0), (130.0, 2.0)] {
145 common::check(&format!("sigma_loc({level}, {t})"), flat_lv.vol(level, t), 0.25, 1e-6);
146 }
147
148 common::section("Term structure: local vol is the forward variance");
149 let term = VolSurface::from_strike_smiles(
150 &[Tenor::YearFraction(0.5), Tenor::YearFraction(1.0)],
151 &[vec![(100.0, 0.20)], vec![(100.0, 0.25)]],
152 asof(),
153 DayCountConvention::Act365,
154 )
155 .unwrap();
156 let term_lv = LocalVol::new(&term, &curve, SPOT, 0.0, 0.0);
157 // (0.25^2 * 1 - 0.20^2 * 0.5) / 0.5 = 0.085
158 common::check(
159 "sigma_loc between pillars = sqrt(fwd variance)",
160 term_lv.vol(100.0, 0.75),
161 0.085_f64.sqrt(),
162 1e-3,
163 );
164 println!();
165}Sourcepub fn from_input(
input: &VolInput,
reference_date: NaiveDate,
) -> Result<Self, VolError>
pub fn from_input( input: &VolInput, reference_date: NaiveDate, ) -> Result<Self, VolError>
Build from a deserialized VolInput, anchored at reference_date.
Sourcepub fn vol(&self, strike: f64, forward: f64, t: f64) -> f64
pub fn vol(&self, strike: f64, forward: f64, t: f64) -> f64
Black volatility for an option with the given absolute strike,
forward price of the underlying at expiry, and year fraction t.
Strike dimension: linear in vol, flat wings. Time dimension: linear in total variance at the fixed smile coordinate, flat vol before the first and after the last expiry pillar.
Examples found in repository?
34fn main() {
35 common::title("LOCAL VOLATILITY — quotes -> implied surface -> Dupire -> reprice");
36
37 let maturities = [
38 (NaiveDate::from_ymd_opt(2026, 7, 2).unwrap(), 0.23),
39 (NaiveDate::from_ymd_opt(2027, 1, 1).unwrap(), 0.25),
40 ];
41
42 common::section("Step 1: generate market quotes from a known skew");
43 println!(" sigma(K, T) = base(T) - 0.001 * (K - 100)");
44 let mut quotes = Vec::new();
45 for (maturity, base_vol) in maturities {
46 let t = (maturity - asof()).num_days() as f64 / 365.0;
47 for i in 0..13 {
48 let strike = 70.0 + 5.0 * i as f64;
49 let vol = true_vol(strike, base_vol);
50 let price = bs_price(SPOT, strike, RATE, 0.0, vol, t, PutOrCall::Call);
51 let mut option = EquityOptionBuilder::new()
52 .spot(SPOT)
53 .strike(strike)
54 .flat_vol(0.2) // placeholder: the solve does not use it
55 .flat_rate(RATE)
56 .valuation_date(asof())
57 .maturity_date(maturity)
58 .vanilla(PutOrCall::Call)
59 .build();
60 option.base.current_price = Quote::new(price);
61 quotes.push(Box::new(option));
62 }
63 }
64 println!(" {} quotes across {} expiries", quotes.len(), maturities.len());
65
66 common::section("Step 2: back out implied vols and build the surface");
67 let surface = build_implied_vol_surface("es).expect("calibration failed");
68 println!("{surface}");
69
70 common::section("Step 3: check the surface recovers the input smile");
71 for (t, base_vol) in [(182.0 / 365.0, 0.23), (1.0, 0.25)] {
72 for strike in [70.0, 85.0, 100.0, 115.0, 130.0] {
73 let recovered = surface.vol(strike, SPOT, t);
74 common::check(
75 &format!("T={t:.3} K={strike}"),
76 recovered,
77 true_vol(strike, base_vol),
78 1e-6,
79 );
80 }
81 }
82
83 common::section("Step 4: Dupire local volatility from that surface");
84 let curve =
85 YieldCurve::flat(RATE, asof(), DayCountConvention::Act365, Compounding::Continuous).unwrap();
86 let lv = LocalVol::new(&surface, &curve, SPOT, 0.0, 0.0);
87 println!(" {:>8} {:>12} {:>12} {:>12}", "level", "t=0.25", "t=0.50", "t=1.00");
88 for level in [70.0, 85.0, 100.0, 115.0, 130.0] {
89 println!(
90 " {level:>8.1} {:>12.4} {:>12.4} {:>12.4}",
91 lv.vol(level, 0.25),
92 lv.vol(level, 0.50),
93 lv.vol(level, 1.00)
94 );
95 }
96 common::note("local vol is steeper in strike than implied vol (the 'twice the slope' rule)");
97 common::note("the far wings are noisy: Dupire takes numerical derivatives of a");
98 common::note("piecewise-linear surface with flat extrapolation — trust the interior.");
99
100 common::section("Step 5: reprice the calibrating vanillas through local vol MC");
101 common::table_header();
102 for strike in [90.0, 100.0, 110.0] {
103 let expected = bs_price(SPOT, strike, RATE, 0.0, true_vol(strike, 0.25), 1.0, PutOrCall::Call);
104 common::row(
105 &format!("local vol MC, K={strike}"),
106 &EquityOptionBuilder::new()
107 .spot(SPOT)
108 .strike(strike)
109 .vol_surface(surface.clone())
110 .flat_rate(RATE)
111 .valuation_date(asof())
112 .maturity_date(NaiveDate::from_ymd_opt(2027, 1, 1).unwrap())
113 .vanilla(PutOrCall::Call)
114 .engine(Engine::MonteCarlo)
115 .model(McModel::LocalVol)
116 .paths(50_000)
117 .build(),
118 );
119 println!("{:<34} {expected:>12.6} <- Black-Scholes target at the quoted smile vol", "");
120 }
121
122 common::section("Local vol on the finite difference engine (no sampling noise)");
123 common::table_header();
124 for strike in [90.0, 100.0, 110.0] {
125 common::row(
126 &format!("local vol FD, K={strike}"),
127 &EquityOptionBuilder::new()
128 .spot(SPOT)
129 .strike(strike)
130 .vol_surface(surface.clone())
131 .flat_rate(RATE)
132 .valuation_date(asof())
133 .maturity_date(NaiveDate::from_ymd_opt(2027, 1, 1).unwrap())
134 .vanilla(PutOrCall::Call)
135 .engine(Engine::FiniteDifference)
136 .model(McModel::LocalVol)
137 .build(),
138 );
139 }
140
141 common::section("Sanity: a flat surface must give flat local vol");
142 let flat = VolSurface::flat(0.25, asof(), DayCountConvention::Act365).unwrap();
143 let flat_lv = LocalVol::new(&flat, &curve, SPOT, 0.0, 0.0);
144 for (level, t) in [(70.0, 0.25), (100.0, 1.0), (130.0, 2.0)] {
145 common::check(&format!("sigma_loc({level}, {t})"), flat_lv.vol(level, t), 0.25, 1e-6);
146 }
147
148 common::section("Term structure: local vol is the forward variance");
149 let term = VolSurface::from_strike_smiles(
150 &[Tenor::YearFraction(0.5), Tenor::YearFraction(1.0)],
151 &[vec![(100.0, 0.20)], vec![(100.0, 0.25)]],
152 asof(),
153 DayCountConvention::Act365,
154 )
155 .unwrap();
156 let term_lv = LocalVol::new(&term, &curve, SPOT, 0.0, 0.0);
157 // (0.25^2 * 1 - 0.20^2 * 0.5) / 0.5 = 0.085
158 common::check(
159 "sigma_loc between pillars = sqrt(fwd variance)",
160 term_lv.vol(100.0, 0.75),
161 0.085_f64.sqrt(),
162 1e-3,
163 );
164 println!();
165}pub fn reference_date(&self) -> NaiveDate
pub fn day_count(&self) -> DayCountConvention
Sourcepub fn expiry_times(&self) -> &[f64]
pub fn expiry_times(&self) -> &[f64]
Expiry pillar times (empty for a flat surface).
Trait Implementations§
Source§impl Clone for VolSurface
impl Clone for VolSurface
Source§fn clone(&self) -> VolSurface
fn clone(&self) -> VolSurface
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more