✨ Visual Editor

close

palette Canvas & Background

Gradient:arrow_forward
Text Color:
135Β°

style Card Style

40px
16px

text_fields Typography

16px
PyQuant News 🐍
@pyquantnews
Calculating the theta for American options is hard.

It’s the "time decay" of an option's value.

And it’s critical for traders to understand.

The good news?

We have QuantLib to do it for us.

Here’s how:
PyQuant News 🐍
@pyquantnews
Options theta represents the sensitivity of the option's price to the passage of time.

Theta is a critical concept for options traders to understand.

If you're long theta erodes value.

If you're short, theta makes you money.

Let's go:
PyQuant News 🐍
@pyquantnews
We’ll start with importing NumPy for some math, OpenBB for data, and QuantLib to calculate theta.
Thread image
PyQuant News 🐍
@pyquantnews
Using OpenBB, grab the options chains to find at-the-money (ATM) strikes, expirations, and historical price data.
Thread image
PyQuant News 🐍
@pyquantnews
We use pandas to find the strike price that’s closest to the last traded price.

Then we find the last closing price and the annualized volatility.

Finally, we hard code the dividend yield, risk-free rate, and set the evaluation date to today.
Thread image
PyQuant News 🐍
@pyquantnews
Now we'll create the QuantLib handles to set the underlying price, yield term structure for the risk free rate and dividend, and the volatility term structure.
Thread image
PyQuant News 🐍
@pyquantnews
We can now build the Black-Scholes-Merton process which models the dynamics of the underlying asset.

Using the Black-Scholes-Merton process, we can build our option pricer.
Thread image
PyQuant News 🐍
@pyquantnews
While this example values a plain vanilla option using constant volatility, QuantLib supports many features to better reflect reality.

Try using a BlackVarianceCurveΒ if you want to specify the at-the-money volatility with respect to time.
Generated by Thread Navigator
100%
view_carousel Carousel Studio NEW
Press ⌘ + S to quick-export