-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from ashutosh-b-b/bb/nn_stopping
[FEAT]: Add `NNStopping`
- Loading branch information
Showing
26 changed files
with
825 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
pages = [ | ||
"Home" => "index.md", | ||
"Getting started" => "getting_started.md", | ||
"Problems" => "problems.md", | ||
"Solver Algorithms" => ["MLP.md", | ||
"DeepSplitting.md", | ||
"DeepBSDE.md"], | ||
"DeepBSDE.md", | ||
"NNStopping.md"], | ||
"Tutorials" => [ | ||
"tutorials/deepsplitting.md", | ||
"tutorials/deepbsde.md", | ||
"tutorials/mlp.md", | ||
"tutorials/nnstopping.md", | ||
], | ||
"Feynman Kac formula" => "Feynman_Kac.md", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# [The `NNStopping` algorithm](@id nn_stopping) | ||
|
||
### Problems Supported: | ||
1. [`ParabolicPDEProblem`](@ref) | ||
|
||
```@autodocs | ||
Modules = [HighDimPDE] | ||
Pages = ["NNStopping.jl"] | ||
``` | ||
## The general idea 💡 | ||
|
||
Similar to DeepSplitting and DeepBSDE, NNStopping evaluates the PDE as a Stochastic Differential Equation. Consider an Obstacle PDE of the form: | ||
```math | ||
max\lbrace\partial_t u(t,x) + \mu(t, x) \nabla_x u(t,x) + \frac{1}{2} \sigma^2(t, x) \Delta_x u(t,x) , g(t,x) - u(t,x)\rbrace | ||
``` | ||
|
||
Such PDEs are commonly used as representations for the dynamics of stock prices that can be exercised before maturity, such as American Options. | ||
|
||
Using the Feynman-Kac formula, the underlying SDE will be: | ||
|
||
```math | ||
dX_{t}=\mu(X,t)dt + \sigma(X,t)\ dW_{t}^{Q} | ||
``` | ||
|
||
The payoff of the option would then be: | ||
|
||
```math | ||
sup\lbrace\mathbb{E}[g(X_\tau, \tau)]\rbrace | ||
``` | ||
Where τ is the stopping (exercising) time. The goal is to retrieve both the optimal exercising strategy (τ) and the payoff. | ||
|
||
We approximate each stopping decision with a neural network architecture, inorder to maximise the expected payoff. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
```@docs | ||
PIDEProblem | ||
ParabolicPDEProblem | ||
``` | ||
|
||
!!! note | ||
While choosing to define a PDE using `PIDEProblem`, note that the function being integrated `f` is a function of `f(x, y, v_x, v_y, ∇v_x, ∇v_y)` out of which `y` is the integrating variable and `x` is constant throughout the integration. | ||
If a PDE has no integral and the non linear term `f` is just evaluated as `f(x, v_x, ∇v_x)` then we suggest using `ParabolicPDEProblem` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# `NNStopping` | ||
|
||
## Solving for optimal strategy and expected payoff of a Bermudan Max-Call option | ||
|
||
We will calculate optimal strategy for Bermudan Max-Call option with following drift, diffusion and payoff: | ||
```math | ||
μ(x) =(r − δ) x, σ(x) = β diag(x1, ... , xd),\\ | ||
g(t, x) = e^{-rt}max\lbrace max\lbrace x1, ... , xd \rbrace − K, 0\rbrace | ||
``` | ||
We define the parameters, drift function and the diffusion function for the dynamics of the option. | ||
```julia | ||
d = 3 # Number of assets in the stock | ||
r = 0.05 # interest rate | ||
beta = 0.2 # volatility | ||
T = 3 # maturity | ||
u0 = fill(90.0, d) # initial stock value | ||
delta = 0.1 # delta | ||
f(du, u, p, t) = du .= (r - delta) * u # drift | ||
sigma(du, u, p, t) = du .= beta * u # diffusion | ||
tspan = (0.0, T) | ||
N = 9 # discretization parameter | ||
dt = T / (N) | ||
K = 100.00 # strike price | ||
|
||
# payoff function | ||
function g(x, t) | ||
return exp(-r * t) * (max(maximum(x) - K, 0)) | ||
end | ||
|
||
``` | ||
We then define a `PIDEProblem` with no non linear term: | ||
```julia | ||
prob = PIDEProblem(f, sigma, u0, tspan; payoff = g) | ||
``` | ||
!!! note | ||
We provide the payoff function with a keyword argument `payoff` | ||
|
||
And now we define our models: | ||
```julia | ||
models = [Chain(Dense(d + 1, 32, tanh), BatchNorm(32, tanh), Dense(32, 1, sigmoid)) | ||
for i in 1:N] | ||
``` | ||
!!! note | ||
The number of models should be equal to the time discritization. | ||
|
||
And finally we define our optimizer and algorithm, and call `solve`: | ||
```julia | ||
opt = Flux.Optimisers.Adam(0.01) | ||
alg = NNStopping(models, opt) | ||
|
||
sol = solve(prob, alg, SRIW1(); dt = dt, trajectories = 1000, maxiters = 1000, verbose = true) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.