PyQuant News 🐍 Profile picture
Feb 16, 2023 15 tweets 5 min read Read on X
Options models are wrong.

Implied volatility is not the same over the life of an option.

Prove it with volatility surfaces.

Here's how to do it in Python (step by step):
By reading this thread, you’ll be able to:

1. Get live options data
2. Analyze volatility skew
3. Analyze volatility structure
4. Build an implied volatility surface

But first, a primer on implied volatility…
If you’re not familiar with implied volatility:

• Market’s expectation of volatility
• Varies across strikes and expirations
• Where most quants and traders spend their time
• The input that sets model and market price equal

Let's build a volatility surface.
First, import the libraries you need.

yfinance gives you options data - including implied volatility.

Nothing fancy required.
yfinance returns options data for all strikes for a single expiration at a time.

It’s easier to work with all strikes and expirations at the same time.

Write a function to combine the expirations.
Since we only want to look at calls, filter them out of the DataFrame.

But first, call the function you just built to get the data.

Now you’re ready to look at the volatility skew.
Since the options are in a DataFrame, plotting data is easy.

Next, you can see what the skew looks like.
You’ll notice two things:

1. The data are messy
2. Implied volatility varies by strike

In particular it is lowest at the $400 strike, which is right around the stock price.

This is known as volatility smile.
Create a chart of the term structure by selecting a strike.

Plotting is easy with pandas.
Implied volatility decreases as the expiration dates get further out.

The market expectation of volatility is lower in the future than it is today.

Big economic news causes spikes in the term structure.

Finally, let’s put the two charts together and look at the surface.
Pivot the DataFrame to arrange strikes on the rows and expirations on the columns. Implied volatility will be in each cell.

Use meshgrid to get the surface coordinates.

Finally, plot the surface with plot_surface.

What do you get?
An implied volatility surface!

You can see that volatility is much higher at the close expirations and higher strikes.

Quants use this information to price exotic options and find market mispricings.
Quants use implied volatity surfaces to:

• Calibrate pricing models
• Find market mispricings
• Price exotic derivatives

You can build a volatility surface too:

1. Get live options data
2. Build skew and structure
3. Plot the implied volatility surface

All in Python.
If you want to come back to this thread later, click the link below and retweet the top tweet.

If you enjoy reading about Python and quant finance, follow me @pyquantnews for more.
If you want to dive deep with options, check out the 46-Page Ultimate Guide to Pricing Options and Implied Volatility With Python.

Here's why:

• Black-Scholes, the greeks, and implied volatility
• Jupyter Notebooks with the code
• Live options data

pyquantnews.gumroad.com/l/46-page-ulti…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with PyQuant News 🐍

PyQuant News 🐍 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @pyquantnews

May 8
I read the 161-page Financial Machine Learning paper.

It took me 3 days.

Here are the key topics (in 30 seconds): Image
Understanding Asset Prices

Prices as predictions, reflecting future payoffs and investor valuations.
Large Information Sets

The vast scope of information influencing market prices, highlights the need for complex models.
Read 11 tweets
May 4
There is $664,000,000,000 invested in factor strategies.

Factors can help you manage risk and amplify returns.

I spent 3 years figuring it out.

Now you can do it in 10 minutes.

Here’s how in Python.
By reading this thread, you’ll be able to:

• Download historic factor data
• Compute the sensitivities to the factors
• Figure out the risk contribution of the factors

But first…
A quick primer on factor investing:

• Used to target specific return drivers
• Helps manage risk outside diversification
• Important for active managers that get paid for performance

You can use the famous Fama-French 3-factor model for free.

Here’s how.
Read 13 tweets
May 3
7 of the best books on algorithmic trading with Python you can buy: Image
Trading Evolved by Andreas Clenow

Professional backtesting environment using Python, and provides strategies for trading both futures and equities.

• Professional backtesting with Python
• Source code and strategy explanation
• Focus on futures and equities trading Image
Algorithmic Trading with Interactive Brokers by Matthew Scarpino

Introduces readers to algorithmic trading through Interactive Brokers' Trader Workstation (TWS) programming interface.

• Guide to using IB TWS API
• Focuses on Python and C++
• No prior experience needed Image
Read 11 tweets
Apr 26
17 Python GitHub repos for quant finance:
OpenBB-finance: Investment Research for Everyone, Anywhere.

github.com/OpenBB-finance…
Read 19 tweets
Apr 13
Backtesting options strategies is impossible.

Why?

• Millions of contracts
• Weekly expirations
• Assignment if ITM

Not anymore.

Now, you can backtest options strategies in a few lines of code (link to free options data below).

Here’s how: Image
Optopsy is an analysis tool for options trading strategies.

• Generates strategies from raw historic data
• Uncover performance statistics for combos
• 12 strategies built in including strangles

We’ll use 5 years of historic options data on RUT for the analysis.

Let’s go!
First, import the libraries we need.

Optopsy is light with very few dependencies. Image
Read 6 tweets
Mar 14
OpenAI.

OpenBB.

LangChain.

Cutting-edge sentiment analysis using generative pre-trained transformers.

All in a few lines of Python.

Here's the code:
By reading this thread, you’ll use the OpenBB SDK to download news for a topic.

Then, you’ll build a prompt to predict the sentiment of a news headline.

You’ll bring it all together with LangChain.

Let's go!
You’ll need an OpenAI API key to run this code. Once you have it, create a .env file in your working directly. Add the following line:

OPENAI_API_KEY=YOUR_API_KEY

Once that's done, move on:
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(