项目作者: jkirkby3

项目描述 :
Vanilla and exotic option pricing library to support quantitative R&D. Focus on pricing interesting/useful models and contracts (including and beyond Black-Scholes), as well as calibration of financial models to market data.
高级语言: Python
项目地址: git://github.com/jkirkby3/fypy.git
创建时间: 2021-04-24T18:46:26Z
项目社区:https://github.com/jkirkby3/fypy

开源协议:MIT License

下载


FyPy

Vanilla and exotic option pricing library to support quantitative R&D. Focus on pricing interesting/useful models
and contracts (including and beyond Black-Scholes), as well as calibration of financial models to market data.

This library is under active development, although the currently posted features are relatively stable.

Currently Supported

Models

  • Black-Scholes
  • Jump Diffusions: Merton, Kou (Double Exponential)
  • Levy: (VG, NIG, CGMY/KoBoL, MJD, Kou, Tempered-Stable, Bilateral Gamma, etc)
  • Stochastic Volatility: Heston
  • SVJ: Bates, Heston + Double Expo Jumps
  • SLV: SABR

Pricing Methods

  • Analytical: closed form pricing when available, e.g. Black Scholes
  • Fourier: PROJ (Frame Projection), Lewis, Gil-Peleaz, Carr-Madan, Hilbert Transform
  • More in progress (PDE, Monte Carlo, etc) …

Model Calibration

  • Levy Model Calibration (VG, NIG, CGMY, MJD, Kou, Tempered-Stable, Bilateral Gamma, etc)
  • Heston Stochastic Volatility Model Calibration
  • Stochastic Volatility with Jumps Model Calibration
  • SABR Model calibration

Contract types supported (single underlying):

  • European Options
  • Barrier Options (Single/Double barrier, and rebates)
  • Asian Options (Discrete/Continuous)
  • Discrete Variance Swaps, Variance/Volatility Options
  • Bermudan/American early-exercise Options
  • Parisian Options (Cumulative and resetting Parisian barrier options)
  • Cliquets/Equity Indexed Annuities (Additive/Multiplicative)
  • Step (Soft Barrier) Options
  • Lookback/Hindsight Options
  • Fader/Range-Accrual Options

Coming Soon !

  • More Exotic Option Pricing
  • Models: Stochastic Volatility, Stochastic Local Vol
  • Additional pricing methods, such as Mellin Series, PDE, Monte Carlo, etc.
  • Regime Switching Calibration
  • Many of the exotic pricing algorithms will be translated into python from:
    https://github.com/jkirkby3/PROJ_Option_Pricing_Matlab

User installation

pip install git+https://github.com/jkirkby3/fypy.git

Dependencies

fypy requires:

  • Python (>= 3.7)
  • NumPy (tested with 1.20.2)
  • py_lets_be_rational (implied volatility)

Source code

You can check the latest sources with the command

  1. git clone https://github.com/jkirkby3/fypy.git

Test Suite

You can run the full test suite with this command,

  1. python tests/test_runner.py

Example: Price Variance Gamma / Black-Scholes Models with PROJ (Fourier) Method

  1. """
  2. This example shows how to price using a Fourier pricing method (PROJ)
  3. We include two examples: 1) Black Scholes 2) Variance Gamma
  4. """
  5. from fypy.pricing.fourier.ProjEuropeanPricer import ProjEuropeanPricer
  6. from fypy.model.levy.BlackScholes import *
  7. from fypy.model.levy.VarianceGamma import *
  8. from fypy.termstructures.DiscountCurve import DiscountCurve_ConstRate
  9. from fypy.termstructures.EquityForward import EquityForward
  10. from fypy.volatility.implied.ImpliedVolCalculator import ImpliedVolCalculator_Black76
  11. import matplotlib.pyplot as plt
  12. # ============================
  13. # Set Common Parameters
  14. # ============================
  15. S0 = 100 # Initial stock price
  16. r = 0.01 # Interest rate
  17. q = 0.03 # Dividend yield
  18. T = 1 # Time to maturity of option
  19. # ============================
  20. # Set Term Structures
  21. # ============================
  22. disc_curve = DiscountCurve_ConstRate(rate=r)
  23. div_disc = DiscountCurve_ConstRate(rate=q)
  24. fwd = EquityForward(S0=S0, discount=disc_curve, divDiscount=div_disc)
  25. # ============================
  26. # Create Black-Scholes Model
  27. # ============================
  28. model = BlackScholes(sigma=0.2, forwardCurve=fwd, discountCurve=fwd.discountCurve)
  29. pricer = ProjEuropeanPricer(model=model, N=2 ** 10)
  30. # Price a set of strikes
  31. strikes = np.arange(50, 150, 1)
  32. prices = pricer.price_strikes(T=T, K=strikes, is_calls=np.ones(len(strikes), dtype=bool))
  33. # Plot
  34. plt.plot(strikes, prices, label='Black Scholes')
  35. # ============================
  36. # Create Variance Gamma Model
  37. # ============================
  38. model = VarianceGamma(sigma=0.2, theta=0.1, nu=0.8, forwardCurve=fwd, discountCurve=fwd.discountCurve)
  39. pricer = ProjEuropeanPricer(model=model, N=2 ** 10)
  40. # Price a set of strikes
  41. strikes = np.arange(50, 150, 1)
  42. is_calls = np.ones(len(strikes), dtype=bool)
  43. prices = pricer.price_strikes(T=T, K=strikes, is_calls=is_calls)
  44. # Plot
  45. plt.plot(strikes, prices, label='Variance Gamma')
  46. plt.legend()
  47. plt.xlabel(r'strike, $K$')
  48. plt.ylabel('price')
  49. plt.show()
  50. # Compute Implied Volatilities
  51. ivc = ImpliedVolCalculator_Black76(disc_curve=disc_curve, fwd_curve=fwd)
  52. vols = ivc.imply_vols(strikes=strikes, prices=prices, is_calls=is_calls, ttm=T)
  53. # Plot Implied Vols
  54. plt.plot(strikes, vols, label='Variance Gamma')
  55. plt.legend()
  56. plt.xlabel(r'strike, $K$')
  57. plt.ylabel('implied vol')
  58. plt.show()