-
-
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 3 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 |
---|---|---|
@@ -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 | ||
``` | ||
|
||
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(\tau, X_\tau)]\rbrace | ||
``` | ||
Where τ is the stopping (exercising) time. The goal is to retrive 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,50 @@ | ||||||||
## 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(t, x) | ||||||||
return exp(-r * t) * (max(maximum(x) - K, 0)) | ||||||||
end | ||||||||
|
||||||||
``` | ||||||||
We then define a `SDEProblem`: | ||||||||
```julia | ||||||||
prob = SDEProblem(f, sigma, u0, tspan; payoff = g) | ||||||||
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. It is valid. We pick the payoff and redefine the SDEProblem to simulate: HighDimPDE.jl/src/NNStopping.jl Lines 26 to 28 in 2c516a3
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. No, that does not match the interface. We should throw an error in SciMLBase if that's done. I'll add that error soon to catch this better, but that means we need to make sure this satisfies a real interface. But since it's a package about solving PDEs, we should have the description in the PDE form. 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. In that case, I ll pick up the dispatch from the NNKolmogorov PR and put it here. 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. BTW, we can't simulate the SDE with this kwarg. But we can still construct it. The check should be at the construction level. 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. |
||||||||
``` | ||||||||
!!! 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.
Is this a PIDE?
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.
Technically no. Its an obstacle PDE with non linear term
f
= 0: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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I have a dispatch for
f = 0
in the NNKolmogorov PR:
HighDimPDE.jl/src/HighDimPDE.jl
Lines 126 to 134 in a158d47
We can use that, with a kwarg for
g
. How does that sound?