Technology

Options Pricing with Python

2025-05-13 03:40:24


Although C++ is the primary language commonly used for pricing options, the team decided to use Python entirely for learning purposes. This not only provides an opportunity for the team to practice their Python skills but also allows for easy integration of the library with the website.

This library is temporarily named PyQuant, which currently has limited functionality, consisting of two main parts:

  • Closed-form Solutions for Vanilla Call/Put and Digital Options
  • Basic Monte Carlo calculator for pricing Double-Digitals and Power Options


In the future, there will be additional financial options with closed formulas to be used for result verification. However, for now, the team is primarily focused on developing the Monte Carlo solver.



Calculation using the closed formula

The closed-form calculation relies on two statistical functions:

  • Normal Probability Density Function (NPDF)
  • Cumulative Normal Distribution Function (CNDF)


You can see the numerical approximation method of CNDF in [1]. Once you have the NPDF and CNDF, you can calculate the prices of Vanilla Call and Put options, as well as various Greek values, such as:

  • Delta
  • Gamma
  • Rho
  • Vega
  • Theta


Additionally, the closing formula can also be used to calculate the price of Digital Options.



Monte Carlo method calculations

The Monte Carlo approach works differently. The library will have a module that stores pay-off objects for each type of option, such as Call, Put, Forward, Digital Call, etc. Another module stores the option objects, which for Vanilla Options require specifying the expiration time and pay-off structure. The strike price is stored in the pay-off object for flexibility in code reuse.

The final module is the Monte Carlo Engine, which calculates numerous stock price paths according to the Geometric Brownian Motion process and uses these to estimate the expected payoff of the option. This return will be discounted using the risk-free rate to obtain the present value of the option.



Efficiency and improvement guidelines

In the current stage Re-running the Monte Carlo simulator every time there is a change in the input data takes a lot of computation time. There are two improvement approaches:

  • Use SciPy, which is a scientific library for Python that has various optimization strategies. Read the article "Performance Python" and you might be surprised by the performance compared to C++.
  • Write a specific C++ library and call it from Python. Although this method is faster, it contradicts the goal of having a pricing library written entirely in Python.



Reference: Options Pricing in Python

From https://www.quantstart.com/articles/Options-Pricing-in-Python/

Leave a comment :