Finance portfolio optimization using the Hamilton–Jacobi–Bellman (HJB) framework in higher dimensions, approximated via a forward simulation of stochastic wealth paths and (intended) forward–backward neural learning using stochastic paths instead of PDE grids.
This repo currently includes:
- Simulation of wealth under a learned/parameterized control ( pi(t,
$W_t$ ) ) - Brownian motion path generation
- Neural network scaffolding for ( pi(t, W_t) ) and ( Z(t, W_t) )
- A Merton benchmark closed-form control for reference
Note: The docs outline the full forward/backward/value-propagation + loss/training pipeline, but the executable code in this repo is presently focused on the forward simulation portion.
You model a risky asset investment with a portfolio control:
- ( \pi(t, W_t) ): fraction (or amount, depending on your interpretation) invested in the risky asset at time ( t ), given current wealth ( W_t )
- The wealth evolves using an Euler discretization of the controlled SDE: [ dW_t = r W_t,dt + \pi(t,W_t)(\mu - r),dt + \pi(t,W_t)\sigma,dB_t ]
- The neural network
pi_starprovides ( \pi(t, W_t) ) as a function of time and a Brownian state.
From md files/todo.md and md files/pipeline.md:
- Merton minimal benchmark solver/formula (
mertons_2D.py) - Forward stochastic differential equation written (first version) (
forward_simulation_equations.py) - Neural network definitions exist (
neural_networks.py) - Dummy/example data exists (
data_accumulation/data.md) - Pipeline “before training” is described and partially implemented
- Backward simulation / backward value propagation
- Terminal loss construction
- Training loop to learn the neural networks
- Benchmark comparison to quantify improvement vs. Merton
(See md files/pipeline.md and md files/intution_pipeline.md for the conceptual full pipeline.)
-
brownian_motion.py- Generates Brownian increments
dwand cumulative Brownian pathW
- Generates Brownian increments
-
forward_simulation_equations.pyforward_simulation(...): Euler simulation of wealth using a control modelpi_star
-
neural_networks.pypi_star: neural net mapping ((t, W)) → (\pi(t,W))Z_net: neural net mapping ((t, W)) → (Z(t,W)) (scaffold)
-
utility_function.py- Utility function helper (currently written as
Wealth**1-gamma/1-gamma)
- Utility function helper (currently written as
-
mertons_2D.py- Closed-form Merton allocation: [ \pi^* = \frac{\mu - r}{\gamma \sigma^2} ]
-
data_accumulation/data.md- Example parameters (mu, sigma, risk_free_rate, initial wealth, gamma)
-
test.py- Small sanity check / demonstration of the Merton formula
forward_simulation_equations.forward_simulation(model, dw, W, mu, sigma, w0, rate, T, num_steps):
- Create a time grid (t_0,\dots,t_N) with (N=\text{num_steps})
- Initialize
wealth_grid[:,0] = w0 - For each step (i):
- Evaluate control:
pi = model(t, W[:, i]) - Euler update:
drift = rate * W_t + pi * (mu - rate)diffusion = pi * sigma * dWW_{t+dt} = W_t + drift*dt + diffusion
- Evaluate control:
python test.pyRun the script entry inside forward_simulation_equations.py:
python forward_simulation_equations.pyThis uses:
model = pi_star()- a Brownian motion path with default example sizes
- example
mu,sigma,rate,w0taken fromdata_accumulation/data.mdvalues embedded in the script
- Forward pass: simulate many stochastic wealth paths under a control (\pi(t,W))
- Backward/value propagation (intended): use the terminal condition at (T) and propagate optimality information backward along the same simulated paths to learn what the control should have been.
md files/pipeline.md: complete pipeline description (conceptual checklist)md files/todo.md: current progress/next stepsmd files/intution_pipeline.md: intuition behind forward/backward propagation
See LICENSE.