financial-models-numerical-methods

Collection of notebooks about quantitative finance, with interactive python code.

https://github.com/cantaro86/financial-models-numerical-methods

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.1%) to scientific vocabulary

Keywords

american-options brownian-motion econometrics financial-engineering financial-mathematics fourier-inversion heston-model jump-diffusion-mertons-model jupyter-notebooks kalman-filter levy-processes linear-regression linear-systems-equations monte-carlo-methods option-pricing partial-differential-equations python quantitative-finance stochastic-differential-equations stochastic-processes
Last synced: 6 months ago · JSON representation ·

Repository

Collection of notebooks about quantitative finance, with interactive python code.

Basic Info
  • Host: GitHub
  • Owner: cantaro86
  • License: agpl-3.0
  • Language: Jupyter Notebook
  • Default Branch: master
  • Homepage:
  • Size: 23.3 MB
Statistics
  • Stars: 6,120
  • Watchers: 151
  • Forks: 1,114
  • Open Issues: 7
  • Releases: 0
Topics
american-options brownian-motion econometrics financial-engineering financial-mathematics fourier-inversion heston-model jump-diffusion-mertons-model jupyter-notebooks kalman-filter levy-processes linear-regression linear-systems-equations monte-carlo-methods option-pricing partial-differential-equations python quantitative-finance stochastic-differential-equations stochastic-processes
Created over 6 years ago · Last pushed over 1 year ago
Metadata Files
Readme Funding License Citation

README.md

Financial-Models-Numerical-Methods

This is a collection of Jupyter notebooks based on different topics in the area of quantitative finance.

Is this a tutorial?

Almost! :)

This is just a collection of topics and algorithms that in my opinion are interesting.

It contains several topics that are not so popular nowadays, but that can be very powerful. Usually, topics such as PDE methods, Lévy processes, Fourier methods or Kalman filter are not very popular among practitioners, who prefers to work with more standard tools.
The aim of these notebooks is to present these interesting topics, by showing their practical application through an interactive python implementation.

Who are these notebooks for?

Not for absolute beginners.

These topics require a basic knowledge in stochastic calculus, financial mathematics and statistics. A basic knowledge of python programming is also necessary.

In these notebooks I will not explain what is a call option, or what is a stochastic process, or a partial differential equation.
However, every time I will introduce a concept, I will also add a link to the corresponding wiki page or to a reference manual. In this way, the reader will be able to immediately understand what I am talking about.

These notes are for students in science, economics or finance who have followed at least one undergraduate course in financial mathematics and statistics.
Self-taught students or practicioners should have read at least an introductiory book on financial mathematics.

Why is it worth to read these notes?

First of all, this is not a book!
Every notebook is (almost) independent from the others. Therefore you can select only the notebook you are interested in!

diff - Every notebook contains python code ready to use!

It is not easy to find on internet examples of financial models implemented in python which are ready to use and well documented.
I think that beginners in quantitative finance will find these notebooks very useful!

Moreover, Jupyter notebooks are interactive i.e. you can run the code inside the notebook. This is probably the best way to study!

If you open a notebook with Github or NBviewer, sometimes mathematical formulas are not displayed correctly. For this reason, I suggest you to clone/download the repository.

Is this series of notebooks complete?

No!
I will upload more notebooks from time to time.

At the moment, I'm interested in the areas of stochastic processes, Kalman Filter, statistics and much more. I will add more interesting notebooks on these topics in the future.

If you have any kind of questions, or if you find some errors, or you have suggestions for improvements, feel free to contact me.

Contents

1.1) Black-Scholes numerical methods (lognormal distribution, change of measure, Monte Carlo, Binomial method).

1.2) SDE simulation and statistics (paths generation, Confidence intervals, Hypothesys testing, Geometric Brownian motion, Cox-Ingersoll-Ross process, Euler Maruyama method, parameters estimation)

1.3) Fourier inversion methods (inversion formula, numerical inversion, option pricing, FFT, Lewis formula)

1.4) SDE, Heston model (correlated Brownian motions, Heston paths, Heston distribution, characteristic function, option pricing)

1.5) SDE, Lévy processes (Merton, Variance Gamma, NIG, path generation, parameter estimation)

2.1) The Black-Scholes PDE (PDE discretization, Implicit method, sparse matrix tutorial)

2.2) Exotic options (Binary options, Barrier options, Asian options)

2.3) American options (PDE, Early exercise, Binomial method, Longstaff-Schwartz, Perpetual put)

3.1) Merton Jump-Diffusion PIDE (Implicit-Explicit discretization, discrete convolution, model limitations, Monte Carlo, Fourier inversion, semi-closed formula )

3.2) Variance Gamma PIDE (approximated jump-diffusion PIDE, Monte Carlo, Fourier inversion, Comparison with Black-Scholes)

3.3) Normal Inverse Gaussian PIDE (approximated jump-diffusion PIDE, Monte Carlo, Fourier inversion, properties of the Lévy measure)

4.1) Pricing with transaction costs (Davis-Panas-Zariphopoulou model, singular control problem, HJB variational inequality, indifference pricing, binomial tree, performances)

4.2) Volatility smile and model calibration (Volatility smile, root finder methods, calibration methods)

5.1) Linear regression and Kalman filter (market data cleaning, Linear regression methods, Kalman filter design, choice of parameters)

5.2) Kalman auto-correlation tracking - AR(1) process (Autoregressive process, estimation methods, Kalman filter, Kalman smoother, variable autocorrelation tracking)

5.3) Volatility tracking (Heston simulation, hypothesis testing, distribution fitting, estimation methods, GARCH(1,1), Kalman filter, Kalman smoother)

6.1) Ornstein-Uhlenbeck process and applications (parameters estimation, hitting time, Vasicek PDE, Kalman filter, trading strategy)

7.1) Classical MVO (mean variance optimization, quadratic programming, only long and long-short, closed formula)

A.1) Appendix: Linear equations (LU, Jacobi, Gauss-Seidel, SOR, Thomas)

A.2) Appendix: Code optimization (cython, C code)

A.3) Appendix: Review of Lévy processes theory (basic and important definitions, derivation of the pricing PIDE)

How to run the notebooks

Virtual environment:

Here I explain how to create a virtual environment with Anaconda and with the python module venv.

  • Option 1:

You can recreate my tested conda virtual environment with:

bash conda env create -f environment.yml pip install -e .

The first line recreates the virtual environment and installs all the packages.
With the second line we just install the local package FMNM.

  • Option 2:

If you want to create a new environment with the latest python version, you can do:

bash conda create -n FMNM python conda activate FMNM PACKAGES=$(tr '\n' ' ' < list_of_packages.txt | sed "s/arch/arch-py/g") conda install ${PACKAGES[@]} pip install -e .

where in the third line we replace the package name arch with the arch-py, which is the name used by conda.

  • Option 3:

If you prefer to create a venv that uses python 3.11.4, you can do it as follows:

bash python3.11.4 -m venv --prompt FMNM python-venv source python-venv/bin/activate python3 -m pip install --upgrade pip pip install --requirement requirements.txt pip install -e .

  • Option 4:

If you prefer to use the python version already installed in your system, you just need to run

bash pip install --requirement list_of_packages.txt pip install -e .

and then enter in the shell jupyter-notebook or jupyter-lab:

However, if you are using old versions, there could be compatibility problems.

Docker:

Here we run the notebooks with jupyterlab:

  • Option 1:

You can use docker-compose to build a container:

bash docker-compose up --build -d

And then stop the container with

bash docker-compose down

And open the browser at http://localhost:8888/lab

  • Option 2:

Alternatively, you can

bash docker build -t fmnm . docker run --rm -d -p 8888:8888 --name Numeric_Finance fmnm

Enjoy!

Owner

  • Name: Nicola Cantarutti
  • Login: cantaro86
  • Kind: user

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# https://bit.ly/cffinit

cff-version: 1.2.0
title: Financial Models Numerical Methods
message: '"If you use software from this repo, please cite it as below."'
type: software
authors:
  - given-names: >-
      Nicola Cantarutti
repository-code: 'https://github.com/cantaro86/Financial-Models-Numerical-Methods'
date-released: 2019-06-09

GitHub Events

Total
  • Issues event: 1
  • Watch event: 756
  • Issue comment event: 1
  • Push event: 1
  • Pull request review event: 1
  • Fork event: 141
Last Year
  • Issues event: 1
  • Watch event: 756
  • Issue comment event: 1
  • Push event: 1
  • Pull request review event: 1
  • Fork event: 141

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 74
  • Total Committers: 1
  • Avg Commits per committer: 74.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 4
  • Committers: 1
  • Avg Commits per committer: 4.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
canta86 n****i@g****m 74

Issues and Pull Requests

Last synced: 9 months ago

All Time
  • Total issues: 16
  • Total pull requests: 9
  • Average time to close issues: 3 months
  • Average time to close pull requests: 3 days
  • Total issue authors: 16
  • Total pull request authors: 3
  • Average comments per issue: 3.06
  • Average comments per pull request: 0.56
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 5
Past Year
  • Issues: 2
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 2
  • Pull request authors: 0
  • Average comments per issue: 6.5
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • cantaro86 (1)
  • Hans-han (1)
  • rishanb (1)
  • ArjunWhabi (1)
  • marcovth (1)
  • rsadr (1)
  • lachlansimpson (1)
  • Akshat111111 (1)
  • MMABK (1)
  • DavideBufalini (1)
  • eatonlin98 (1)
  • Foristkirito (1)
  • hardik-dev06 (1)
  • 1rdsk1 (1)
  • SimonBachhuber (1)
Pull Request Authors
  • Akshat111111 (4)
  • dependabot[bot] (4)
  • danlenny (3)
Top Labels
Issue Labels
enhancement (1) wontfix (1)
Pull Request Labels
dependencies (4)