GithubHelp home page GithubHelp logo

pyfe / pyfeng Goto Github PK

View Code? Open in Web Editor NEW
140.0 6.0 70.0 3.41 MB

Python Financial ENGineering (PyFENG package in PyPI.org)

License: GNU General Public License v2.0

Python 100.00%
financial-engineering mathematical-finance quantitative-finance option-pricing derivatives black-scholes heston-model sabr-model bachelier-model

pyfeng's Introduction

PyFENG: [Py]thon [F]inancial [ENG]ineering

PyPI version Documentation Status Downloads

PyFENG provides an implementation of the standard financial engineering models for derivative pricing.

Implemented Models

  • Black-Scholes-Merton (BSM) and displaced BSM models:
    • Analytic option price, Greeks, and implied volatility.
  • Bachelier (Normal) model
    • Analytic option price, Greeks, and implied volatility.
  • Constant-elasticity-of-variance (CEV) model
    • Analytic option price, Greeks, and implied volatility.
  • Stochastic-alpha-beta-rho (SABR) model
    • Hagan's BSM vol approximation.
    • Choi & Wu's CEV vol approximation.
    • Analytic integral for the normal SABR.
    • Closed-form MC simulation for the normal SABR.
  • Hyperbolic normal stochastic volatility (NSVh) model
    • Analytic option pricing.
  • Heston model
    • FFT option pricing.
    • Almost exact MC simulation by Glasserman & Kim and Choi & Kwok.
  • Schobel-Zhu (OUSV) model
    • FFT option pricing.
    • Almost exact MC simulation by Choi
  • Rough volatility models
    • Rough Heston MC by Ma & Wu

About the Package

  • Uses numpy arrays as basic datatype so computations are naturally vectorized.
  • Purely Python without C/C++ extensisons.
  • Implemented with Python class.
  • Intended for academic use. By providing reference models, it saves researchers' time. See PyFENG for Papers in Related Projects below.

Installation

pip install pyfeng

For upgrade,

pip install pyfeng --upgrade

Code Snippets

In [1]:

import numpy as np
import pyfeng as pf
m = pf.Bsm(sigma=0.2, intr=0.05, divr=0.1)
m.price(strike=np.arange(80, 121, 10), spot=100, texp=1.2)

Out [1]:

array([15.71361973,  9.69250803,  5.52948546,  2.94558338,  1.48139131])

In [2]:

sigma = np.array([[0.2], [0.5]])
m = pf.Bsm(sigma, intr=0.05, divr=0.1) # sigma in axis=0
m.price(strike=[90, 95, 100], spot=100, texp=1.2, cp=[-1,1,1])

Out [2]:

array([[ 5.75927238,  7.38869609,  5.52948546],
       [16.812035  , 18.83878533, 17.10541288]])

Author

Related Projects

  • Commercial versions (implemented and optimized in C/C++) for some models are available. Email the author at [email protected].
  • PyFENG for Papers is a collection of Jupyter notebooks that reproduce the results of financial engineering research papers using PyFENG.
  • FER: Financial Engineering in R developed by the same author. Not all models in PyFENG are implemented in FER. FER is a subset of PyFENG.

pyfeng's People

Contributors

1901212564 avatar ahrmnd avatar charliescc avatar chenyingong avatar cy-wang15 avatar daifengqi avatar delia810 avatar feng-yuze avatar hejinzefinance avatar jaehyukchoi avatar jiangxunmu avatar jordanplatts avatar lantianxue avatar lililiyf avatar panyuli avatar rickchauyanchak avatar xueyanghu avatar zaynmalivski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pyfeng's Issues

Quadrature from moments

  • quadpypackage
  • Golub GH, Meurant GA (2010) Matrices, moments, and quadrature with applications. Princeton University Press, Princeton, N.J

`BsmDisp` bug

The disp() function should take forward, not spot.

OusvIft is not accurate.

The current docstring in OusvIft shows the exact values reported in Li & Wu (2019) Table 2 and 3. But the actual output is slightly different. We need to improve the implementation.

        >>> import pyfeng as pf
        >>> model = pf.OusvIft(0.2, mr=4, vov=0.1, rho=-0.7, intr=0.09531)
        >>> model.price(100, 100, texp=np.array([1, 5, 10]))
        array([13.21493, 40.79773, 62.76312])
        >>> model = pf.OusvIft(0.25, mr=8, vov=0.3, rho=-0.6, intr=0.09531)
        >>> model.price(np.array([90, 100, 110]), 100, texp=1)
        array([21.41873, 15.16798, 10.17448])

Actual results:

array([13.21341236, 40.78514465, 62.67427669])
array([21.41624282, 15.16575302, 10.17145969])

implied volatility problem

It seems that both impvol and impvol_naive return nan:

m = pf.Bsm(sigma=0.5, intr=0.05, divr=0.1)
print(m.impvol(100, 80, 19.4, 0.1, 1))

nan

Mgf2Mom improvement

  • Vectorize. MGF can return vectors
  • Intermediate results should use class variables

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.