Pricing Options in C using Python Wrappers
This project explores the Black-Scholes model for pricing European call and put options. Implemented in C, the project uses Python wrappers to make it easier for a user to try out.
You can modify parameters and see how volatility affects pricing.
But what are options?
Let's define what we're actually pricing.
- A call option gives the holder the right, but not the obligation, to buy an asset at a fixed price (called the strike price ) before or at a specified expiration date.
- A put option gives the holder the right to sell an asset at the strike price before or at expiration.
These options are financial contracts used for speculation or hedging.
In this case, we are using the Black-Scholes equation, which only concerns European Options. There are different types of options, such as American and Exotic options.
Where Does the Black-Scholes Equation Come From?
We assume that stock prices follow a geometric Brownian Motion:
This equation says that the change in the stock price over a small time has two parts:
- A deterministic trend (like expected return over time):
- A random component (fluctuations from market noise):
Here:
- = asset price
- = expected return
- = volatility
- = Wiener process (random noise)
We use Itô’s Lemma, which is a tool from stochastic calculus that tells us how a function of a stochastic process behaves. Stochastic means random.
Applying Itô’s Lemma to gives:
We now create a hedged portfolio by holding one option and shorting shares of stock. This eliminates the (random) term, making the portfolio risk-free over an infinitesimal time interval.
Since a risk-free portfolio should earn the risk-free interest rate , we equate the return of the portfolio to and arrive at the Black-Scholes Partial Differential Equation (PDE):
Solving this PDE under boundary conditions for a European call option gives the celebrated Black-Scholes equation:
where
And What About Put Options?
For a European put option, the solution to the same PDE leads to:
Where the terms are still:
This is derived using put-call parity and represents the fair value of a put option assuming no arbitrage, continuous hedging, and no early exercise (i.e., European style).