Skip to main content

Python Financial Engineering

Project description

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 pyfe@eml.cc.
  • 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfeng-0.3.6.tar.gz (251.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfeng-0.3.6-py3-none-any.whl (250.2 kB view details)

Uploaded Python 3

File details

Details for the file pyfeng-0.3.6.tar.gz.

File metadata

  • Download URL: pyfeng-0.3.6.tar.gz
  • Upload date:
  • Size: 251.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyfeng-0.3.6.tar.gz
Algorithm Hash digest
SHA256 4306d25a1a8bc5a649f4f6a729e4b21016466378e2b3a8342b5b03e88b46c346
MD5 1b9131313bb967df394963a770dd0a75
BLAKE2b-256 74a02ff4bbb7c51125491f9ed78f2eded6aabbd6e10412961e82e81202eeeeb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfeng-0.3.6.tar.gz:

Publisher: publish.yml on PyFE/PyFENG

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyfeng-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: pyfeng-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 250.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyfeng-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0e882d65b385983994abb2331ae01cffaa824a8f53f52ace9633ce0814be953f
MD5 98e1f8609e29abe1521a47eddea31e11
BLAKE2b-256 4984317296b25c85141f680b25c60388e51a5a13aa84cd9b54e8294c68a9567e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfeng-0.3.6-py3-none-any.whl:

Publisher: publish.yml on PyFE/PyFENG

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page