Algorithmic Portfolio Hedging. Python and Black-Scholes Pricing for... | by Roman Paolucci | Towards Data Science

Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seeking professional advice. See our Reader Terms for details.
Equities that have a very straightforward exposure to idiosyncratic and systematic risk. Options, on the other hand, have exposure to not only the underlying asset, but also interest rates, time, and volatility. These exposures are inputs to the Black-Scholes option pricing model(see Deriving the Black-Scholes Model). Since these inputs affect the value of the option in question, the partial derivative of the function can tell us how the option value changes when one of these exposures changes holding the others constant. Let’s first discuss all of the partial derivatives of this option pricing model, then code an algorithmic hedging system using Python.
Using a Taylor series expansion we can derive all of the greeks. The greeks tell us how we can expect an option or portfolio of options to change when a change occurs in one or more of the option exposures. Something important to note is that all first-order approximations are linear, and the option pricing function is non-linear. This means the more the underlying parameter deviates from the initial partial-derivative calculation the less accurate it will be. This is why the greeks are updated, generally, in real-time, so we can constantly have a new set of expectations for option or portfolio value when something changes (for more see Option Greeks in Python).
Note: In the following scenarios we are generally considering calls and puts, some more advanced spreads may be long or short with different exposure parity.
The first-order partial-derivative with respect to the underlying asset of the Black-Scholes equation is known as delta. Delta refers to how the option value changes when there is a change in the underlying asset price. Multiplying delta by a +-$1 change in the underlying asset, holding all other parameters constant, will give you the new value of the option. Delta will be positive for long call and short put positions, negative for short call and long put positions.
The second-order partial-derivative with respect to the underlying asset of the Black-Scholes equation is known as gamma. Gamma refers to how the option’s delta changes when there is a change in the underlying asset price. Multiplying gamma by a +-$1 change in the underlying asset, holding all other parameters constant, will give you the new value of the option’s delta. Essentially, gamma is telling us the rate of change of delta given a +-1 change in the underlying asset price. Gamma is always positive for long positions and negative for short positions.
The first-order partial-derivative with respect to the underlying asset volatility of the Black-Scholes equation is known as vega. Vega refers to how the option value changes when there is a change in the underlying asset volatility. Multiplying vega by a +-1% change in the underlying asset volatility, holding all other parameters constant, will give you the new value of the option. Vega will be positive for long positions and negative for short positions.
The first-order partial-derivative with respect to the time until option expiration of the Black-Scholes equation is known as theta. Theta refers to how the option value changes as time passes. Generally annualized, theta refers to the change in the value of an option when a single day passes. Theta will be positive for short positions and negative for long positions.
The first-order partial-derivative with respect to the risk-free rate of the Black-Scholes equation is known as rho. Rho refers to how the option value changes as the interest rate changes. Multiplying rho by a +-1% change in the interest rate, holding all other parameters constant, will give you the new value of the option. Rho will be positive for long call and short put positions and negative for short call and long put positions.
A colleague currently has a short position in 1000 NVDA calls, she wants to hedge her exposure to changes in volatility, movements in the underlying asset, and the speed of movements in the underlying asset. You’re on the risk-management desk and offer to construct a dynamic hedge to be rebalanced daily (more on this later). How can we neutralize her exposure to the option’s vega, delta, and gamma?
We can use the first week of linear algebra to help us construct a solution.
The first thing to realize is that to neutralize exposure to greeks we are going to need offsetting positions in other options. There are three greeks to neutralize, so we need three options to create three equations of greeks and weights with three unknowns (the weights in the other tradable options). However, the trick here is realizing that the partial derivative of the underlying asset with respect to itself is just 1, this means the underlying asset has a delta of 1 and all other greek values are 0. This means we can construct a portfolio of two tradable options, find appropriate weights to neutralize the greeks, then take an offsetting position in the underlying asset — effectively neutralizing exposure to all three greeks.
Consider the following code that models European calls and puts...
For the case above consider the following conditions...
short 1000 NVDA calls@545
NVDA price $543
NVDA implied volatility 53% (see What is Implied Volatility?)
1 month until option expiration
30 day LIBOR rate 1.5%
Using these inputs we can find the theoretical value of our colleague’s option position...
32264.05329034736
This means our colleague would have collected a $32264.05 premium for the sale of the options.
What about the greeks? To find our colleague’s position in the greeks we can just print them and multiply by the position...
-523.8788365375873-6.3495209433350475-815.5392717775394
This means the net portfolio delta, gamma, and vega are...
Delta: -523.88
Gamma: -6.35
Vega: -815.54
Now let’s consider two more tradable call options, all the other parameters are the same but the two strike prices are 550 and 555...
0.499915336667297540.0060590783186479280.77823450993103740.476168747972244070.0057712647027199880.741267420785845
Call Option A:
Delta: 0.49991
Gamma: 0.00605
Vega: 0.77823
Call Option B:
Delta: 0.47616
Gamma: 0.00577
Vega: 0.74126
Underlying Asset (NVDA Stock):
Delta: 1
Gamma: 0
Vega: 0
Using a combination of these assets we can neutralize our portfolio’s exposure to delta, gamma, and vega. The question is how? The answer: linear algebra.
The greeks we are interested in neutralizing in the current portfolio can be expressed as a vector...
The goal is to find the weights of the three assets we are capable of trading to neutralize these values. First, we will look to neutralize gamma and vega, then using the underlying asset, we will neutralize delta...
This means by inverting the matrix containing the greek values for the tradable options we can find the appropriate weights...
We can do this using Python...
Note: Though we have a short position in the original option we multiply by a positive 1000 as we want to invert the matrix to a positive gamma, vega position
[[-1850.    25.] [ 1950.   -25.]]
We have effectively found the inverse of the matrix, the dot product will be the resulting weights for both tradable options...
[[ 8641.86804927] [-8006.91595494]]
Using these weights we will have effectively neutralized our exposure to gamma and vega...
[[ 0.] [-0.]]
Now that the exposure to gamma and vega is neutralized we need to neutralize our new exposure to delta. To find our new exposure, we take the sum-product of all option positions in our portfolio with their respective deltas...
[[-46.] [  0.] [ -0.]]
After multiplying our new options positions by the original greeks we find that our net delta position is -46. This means by purchasing 46 shares of the underlying asset (NVDA) we will have a delta, gamma, and vega neutral portfolio. This means the value of our option portfolio will not change when there are changes in the underlying asset price, underlying asset volatility, or the speed in which the underlying asset price changes. The code laid out herein can be implemented directly into a live trading system (see Algorithmic Trading System Development or Algorithmic Trading with Python)
-1000 NVDA Calls
8641 Call A Options
-8006 Call B Options
46 Shares of NVDA
Check out some of my other articles to learn more about options, theoretical pricing, and volatility trading...
Volatility Trading 101
Risk-Neutral Portfolio Management
Deriving the Black-Scholes Model
Black-Scholes Algorithmic Delta Hedging