-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT]: Add NNStopping
#81
Changes from 35 commits
eea3b1f
cfd5b45
2c516a3
1fe1d3f
3faa879
d346a80
f5c4fd5
ab340cf
e0d07fb
e670a5a
71ff37e
de266d2
a935123
71fe64c
d9d9f4c
425ab15
0ada89c
ab4be5a
31a64f1
a698b96
901470e
130cd20
cd1d23b
f5ed8e4
9656d8e
32a66cc
518a2f1
dc66a82
ee934ad
3fc048a
ce172b4
9ba1455
125182d
9534761
a7358f7
53cc92b
0f1c148
66372d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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", | ||
] |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||||||||||||||
# [The `NNStopping` algorithm](@id nn_stopping) | ||||||||||||||||||||
|
||||||||||||||||||||
```@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 | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a PIDE? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I see a difference? It just requires f = 0. That can be checked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I have a dispatch for HighDimPDE.jl/src/HighDimPDE.jl Lines 126 to 134 in a158d47
We can use that, with a kwarg for |
||||||||||||||||||||
``` | ||||||||||||||||||||
|
||||||||||||||||||||
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. |
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`, not 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. | ||
ChrisRackauckas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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` |
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) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We will need a breaking release. I'd suggest we do that after NNKolmogorov is in