Skip to content

Commit

Permalink
feat: SABR model volatility and fitting
Browse files Browse the repository at this point in the history
  • Loading branch information
avhz authored and avhz committed Nov 24, 2024
1 parent 9fec79f commit 0851a88
Show file tree
Hide file tree
Showing 27 changed files with 448 additions and 169 deletions.
29 changes: 29 additions & 0 deletions book/src/Modules/autodiff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# `autodiff`

The `autodiff` module can be used to differentiate scalar output functions of the form:

\\[f : \mathbb{R}^n \rightarrow \mathbb{R} \\]


Simple expressions are differentiated as follows:

```rust,noplayground
{{#include ../../../examples/examples/autodiff.rs:simple_expressions}}
```

Block expressions are also supported:

```rust,noplayground
{{#include ../../../examples/examples/autodiff.rs:block_expressions}}
```

Closures and functions are also supported:

```rust,noplayground
{{#include ../../../examples/examples/autodiff.rs:closures}}
```

```rust,noplayground
{{#include ../../../examples/examples/autodiff.rs:functions}}
```

117 changes: 0 additions & 117 deletions book/src/Modules/autodiff/autodiff.md

This file was deleted.

1 change: 0 additions & 1 deletion book/src/Modules/cashflows/cashflows.md

This file was deleted.

9 changes: 9 additions & 0 deletions book/src/Modules/data/data.md → book/src/Modules/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ That is, anything that can be observed, either in markets or derived from market

Another form of data is contextual (or reference) data. These are things such as calendars and date conventions. While there are facilities to handle these data inside the `data` module, the underlying implementations are in other modules, such as the `time` module.

## Curves

Curves can be fit to market data. Here we include an example of a spot curve being fitted.

![`Spot curve`](../assets/spotcurve.png)

```rust
{{#include ../../../examples/examples/curves_spot.rs}}
```
9 changes: 0 additions & 9 deletions book/src/Modules/data/curves.md

This file was deleted.

1 change: 0 additions & 1 deletion book/src/Modules/error.md

This file was deleted.

29 changes: 29 additions & 0 deletions book/src/Modules/instruments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# `instruments`


## European Vanilla Options

To price a vanilla European option, we begin by defining the option itself:

```rust,noplayground
{{#include ../../../examples/examples/option_pricing_vanilla.rs:option_definition}}
```

Then we need to define a model to price the option with:

```rust,noplayground
{{#include ../../../examples/examples/option_pricing_vanilla.rs:model_definitions}}
```

Lastly, we construct an `AnalyticOptionPricer`, from which we can generate a report.
The report simply prints the option, model, price, and Greeks.

```rust,noplayground
{{#include ../../../examples/examples/option_pricing_vanilla.rs:option_pricing}}
```

The output will look something like this:

```rust,noplayground
{{#include ../../../examples/examples/option_pricing_vanilla.rs:output}}
```
1 change: 0 additions & 1 deletion book/src/Modules/instruments/instruments.md

This file was deleted.

22 changes: 0 additions & 22 deletions book/src/Modules/instruments/options.md

This file was deleted.

1 change: 0 additions & 1 deletion book/src/Modules/iso/iso.md

This file was deleted.

1 change: 0 additions & 1 deletion book/src/Modules/macros.md

This file was deleted.

13 changes: 13 additions & 0 deletions book/src/Modules/math.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# `math`

## Numerical Integration

Here we integrate the Gaussian density, which integrates to 1:

\\[
\int_{\mathbb{R}} \frac{1}{\sqrt{2 \pi}} e^{\left( -\frac{x^2}{2} \right)} dx = 1
\\]

```rust,noplayground
{{#include ../../../examples/examples/numerical_integration.rs:numerical_integration}}
```
1 change: 0 additions & 1 deletion book/src/Modules/math/math.md

This file was deleted.

1 change: 0 additions & 1 deletion book/src/Modules/ml/ml.md

This file was deleted.

1 change: 0 additions & 1 deletion book/src/Modules/models/models.md

This file was deleted.

1 change: 0 additions & 1 deletion book/src/Modules/portfolio/portfolio.md

This file was deleted.

11 changes: 11 additions & 0 deletions book/src/Modules/stochastics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `stochastics`

Many stochastic processes can be generated:

```rust,noplayground
{{#include ../../../examples/examples/stochastic_processes.rs:stochastic_processes}}
```

Paths can be plotted via the `plot_vector!` macro or `plotly`:

![Geometric Brownian Motion](../assets/gbm.png)
1 change: 0 additions & 1 deletion book/src/Modules/stochastics/stochastics.md

This file was deleted.

1 change: 0 additions & 1 deletion book/src/Modules/time/time.md

This file was deleted.

1 change: 0 additions & 1 deletion book/src/Modules/trading/trading.md

This file was deleted.

14 changes: 6 additions & 8 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@

# Modules

<!-- - [`autodiff`](./Modules/autodiff/autodiff.md)
- [`cashflows`](./Modules/cashflows/cashflows.md) -->

- [`data`](./Modules/data/data.md)
- [Curves](./Modules/data/curves.md)
- [`autodiff`](./Modules/autodiff.md)
- [`data`](./Modules/data.md)
- [`instruments`](./Modules/instruments.md)
- [`math`](./Modules/math.md)
- [`stochastics`](./Modules/stochastics.md)

<!-- - [`cashflows`](./Modules/cashflows/cashflows.md) -->
<!-- - [`error`](./Modules/error.md) -->
- [`instruments`](./Modules/instruments/instruments.md)
- [Options](./Modules/instruments/options.md)
<!-- - [`iso`](./Modules/iso/iso.md)
- [`macros`](./Modules/macros.md)
- [`math`](./Modules/math/math.md)
- [`ml`](./Modules/ml/ml.md)
- [`portfolio`](./Modules/portfolio/portfolio.md)
- [`stochastics`](./Modules/stochastics/stochastics.md)
- [`time`](./Modules/time/time.md)
- [`trading`](./Modules/trading/trading.md) -->

Expand Down
1 change: 1 addition & 0 deletions crates/RustQuant_instruments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ RustQuant_stochastics = { workspace = true }
RustQuant_iso = { workspace = true }

## External dependencies
argmin = { workspace = true }
time = { workspace = true }
derive_builder = { workspace = true }
errorfunctions = { workspace = true }
Expand Down
Loading

0 comments on commit 0851a88

Please sign in to comment.