Giter Site home page Giter Site logo

ml-quant's Introduction

Neural net to match volatility against Stochastic and Local Vol Models

Two loss functions: i) To have the output close to a known model (full computation graph is known) ii) To match SLV model (we don't know computation graph but neural net will find it eventually, hopefully) The first loss is our prior. This can be from the current state-of-the art known to us. The second loss tries to move our model towards the unknown model. First, we train with loss 1 to learn the prior compute graph. Then, with a lower learning rate loss 2 is used online.

In all the experiments, known model is Black Cubic while unknown model is Dupire LV/Heston SLV. But the code can be used for any prior/posterior.

Input is a coarse 2D grid of vol along strike and time (liquid instruments), while output is i) a much finer grid (calibrated vol surface) ii) a single point vol

Experiment 0 - Creating vol surface (ground-truth creation):

Quantlib and it's python hook are used for vol surface calculations. For Heston, vol is interpolated on liquid instruments along time axis and then these pseudo-liquid instruments are used for calibration. Once calibrated, black vols are implied from Heston prices. For local vol, black cubic is used as the underlying implied vol surface and dupire formula on the implied vols and it's derivatives is directly used. Black Cubic is a bicubic interpolation along strike and maturity axis. This tutorial is the starting point for Heston using quantlib-python. Note: We are simulating Dupire/Heston as unknown. Ideally, we obtain ground-truth data from an upstream application.

To test the vol models, run the following command. It will generate visualizations in ../exp/ directory:

python volmodel_test.py -data ..\data\vol_raw_data.csv -expID testVolModel

Vol Surface Img Ground truth is created by shifting the input vols and recalibrating the surfaces. Bivariate normal pdf with mean and correlation chosen uniformly randomly is added to input vols. Figure below shows samples from the created data post calibration.

python volmodel_create_gt.py -data ..\data\vol_raw_data.csv -volModel black_cubic

Ground truth data

Experiment 1 - Learning the prior:

NN Model is trained with full supervision on known model. After 25 epochs, avg error in vol prediction (on test set) is 0.291%

python nnmodel_basic.py -expID base_model -data ..\data\black_cubic_annot.h5 -train

Predicted Black Cubic

Experiment 2 - Learning the posterior:

NN Model is trained on 5% of data with weights pre-initialized to predict prior. Avg Error in vol prediction is 3.89% for Heston (on test set) and 4.09% for Dupire (on test set).
Dupire NN Prediction: Predicted Dupire Local Heston NN Prediction: Predicted Heston SLV

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.