Skip to content

Commit 605db7c

Browse files
avhzavhz
avhz
authored and
avhz
committed
docs(book): add EuropeanVanillaOption pricing
1 parent 04d5cbc commit 605db7c

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

book/src/Modules/data/curves.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ Curves can be fit to market data. Here we include an example of a spot curve bei
55
![`Spot curve`](../../assets/spotcurve.png)
66

77
```rust
8-
{{#include ../../../../examples/curves_spot.rs}}
8+
{{#include ../../../../examples/examples/curves_spot.rs}}
99
```
10-
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Options
2+
3+
## European Vanilla Options
4+
5+
To price a vanilla European option, we begin by defining the option itself:
6+
7+
```rust,noplayground
8+
{{#include ../../../../examples/examples/option_pricing_vanilla.rs:option_definition}}
9+
```
10+
11+
Then we need to define a model to price the option with:
12+
13+
```rust,noplayground
14+
{{#include ../../../../examples/examples/option_pricing_vanilla.rs:model_definitions}}
15+
```
16+
17+
Lastly, we construct an `AnalyticOptionPricer`, from which we can generate a report.
18+
The report simply prints the option, model, price, and Greeks.
19+
20+
```rust,noplayground
21+
{{#include ../../../../examples/examples/option_pricing_vanilla.rs:option_pricing}}
22+
```

book/src/SUMMARY.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
- [`data`](./Modules/data/data.md)
1515
- [Curves](./Modules/data/curves.md)
1616

17-
<!-- - [`error`](./Modules/error.md)
17+
<!-- - [`error`](./Modules/error.md) -->
1818
- [`instruments`](./Modules/instruments/instruments.md)
19-
- [`iso`](./Modules/iso/iso.md)
19+
- [Options](./Modules/instruments/options.md)
20+
<!-- - [`iso`](./Modules/iso/iso.md)
2021
- [`macros`](./Modules/macros.md)
2122
- [`math`](./Modules/math/math.md)
2223
- [`ml`](./Modules/ml/ml.md)
23-
- [`models`](./Modules/models/models.md)
2424
- [`portfolio`](./Modules/portfolio/portfolio.md)
2525
- [`stochastics`](./Modules/stochastics/stochastics.md)
2626
- [`time`](./Modules/time/time.md)

examples/examples/option_pricing_vanilla.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,33 @@ use time::macros::date;
22
use RustQuant::instruments::*;
33

44
fn main() -> Result<(), Box<dyn std::error::Error>> {
5+
// ANCHOR: option_definition
56
// Define the option contract.
67
let option = EuropeanVanillaOptionBuilder::default()
78
.strike(100.0)
89
.expiry(date!(2025 - 12 - 31))
910
.type_flag(TypeFlag::Call)
1011
.build()?;
12+
// ANCHOR_END: option_definition
1113

14+
// ANCHOR: model_definitions
1215
// Define some models to price the option.
1316
let bs73 = BlackScholes73::new(100., 0.05, 0.2);
1417
let m73 = Merton73::new(100., 0.05, 0.03, 0.2);
1518
let b76 = Black76::new(100., 0.05, 0.2);
1619
let a82 = Asay82::new(100., 0.2);
1720
let gk83 = GarmanKohlhagen83::new(100., 0.05, 0.03, 0.2);
21+
// ANCHOR_END: model_definitions
1822

23+
// ANCHOR: option_pricing
1924
// Print the option price and greeks.
2025
// There are more greeks available, but these are the most common.
21-
AnalyticOptionPricer::new(option.clone(), bs73.clone()).report();
22-
AnalyticOptionPricer::new(option.clone(), m73.clone()).report();
23-
AnalyticOptionPricer::new(option.clone(), b76.clone()).report();
24-
AnalyticOptionPricer::new(option.clone(), a82.clone()).report();
25-
AnalyticOptionPricer::new(option.clone(), gk83.clone()).report();
26+
AnalyticOptionPricer::new(option.clone(), bs73).report();
27+
AnalyticOptionPricer::new(option.clone(), m73).report();
28+
AnalyticOptionPricer::new(option.clone(), b76).report();
29+
AnalyticOptionPricer::new(option.clone(), a82).report();
30+
AnalyticOptionPricer::new(option.clone(), gk83).report();
31+
// ANCHOR_END: option_pricing
2632

2733
Ok(())
2834
}

0 commit comments

Comments
 (0)