Exploring Greeks – Vega (ν) and RHO (ρ) with Python

Option Price with Volatility

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

# Function to calculate Black-Scholes option price for call and put options
def calculate_option_price(S, K, r, T, sigma, option_type):
    d1 = (np.log(S / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T))
    d2 = d1 - sigma * np.sqrt(T)
    if option_type == 'call':
        option_price = S * norm.cdf(d1) - K * np.exp(-r * T) * norm.cdf(d2)
    elif option_type == 'put':
        option_price = K * np.exp(-r * T) * norm.cdf(-d2) - S * norm.cdf(-d1)
    else:
        option_price = None
    return option_price

# Parameters
r = 0.05  # Risk-free rate
T = 1  # Time to expiry
volatility_range = [0.1, 0.15, 0.2, 0.25, 0.3]  # Different volatilities
S = 100  # Stock price
K_range = np.arange(80, 121, 5)  # Strike price range with intervals of 5

# Calculate option values for call and put options across strike prices and different volatilities
call_option_values = np.zeros((len(K_range), len(volatility_range)))
put_option_values = np.zeros((len(K_range), len(volatility_range)))

for i, K in enumerate(K_range):
    for j, volatility in enumerate(volatility_range):
        call_option_values[i, j] = calculate_option_price(S, K, r, T, volatility, 'call')
        put_option_values[i, j] = calculate_option_price(S, K, r, T, volatility, 'put')

# Plotting call option values across strike prices for different volatilities
plt.figure(figsize=(8, 6))
for i, volatility in enumerate(volatility_range):
    plt.plot(K_range, call_option_values[:, i], label=f'Volatility={volatility}', linestyle='-', marker='o')

plt.title('Call Option Value vs Strike Price')
plt.xlabel('Strike Price')
plt.ylabel('Call Option Value')
plt.legend(title='Volatility')
plt.grid(True)
plt.show()

# Plotting put option values across strike prices for different volatilities
plt.figure(figsize=(8, 6))
for i, volatility in enumerate(volatility_range):
    plt.plot(K_range, put_option_values[:, i], label=f'Volatility={volatility}', linestyle='-', marker='o')

plt.title('Put Option Value vs Strike Price')
plt.xlabel('Strike Price')
plt.ylabel('Put Option Value')
plt.legend(title='Volatility')
plt.grid(True)
plt.show()

Output


Option Price with Interest Rate (RHO (ρ))

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

# Function to calculate Black-Scholes option price for call and put options
def calculate_option_price(S, K, r, T, sigma, option_type):
    d1 = (np.log(S / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T))
    d2 = d1 - sigma * np.sqrt(T)
    if option_type == 'call':
        option_price = S * norm.cdf(d1) - K * np.exp(-r * T) * norm.cdf(d2)
    elif option_type == 'put':
        option_price = K * np.exp(-r * T) * norm.cdf(-d2) - S * norm.cdf(-d1)
    else:
        option_price = None
    return option_price

# Parameters
r = 0.05  # Risk-free rate
sigma = 0.2  # Volatility
T = 1  # Maturity
S = 100  # Current stock price
K_range = np.arange(80, 121, 1)  # Strike price range with intervals of 1
rho_values = [0.02, 0.04, 0.06, 0.08, 0.10]  # Rho values to analyze

# Calculate call and put option values for different Rho values
call_option_values = {rho: [] for rho in rho_values}
put_option_values = {rho: [] for rho in rho_values}

for rho in rho_values:
    for K in K_range:
        call_option_values[rho].append(calculate_option_price(S, K, r + rho, T, sigma, 'call'))
        put_option_values[rho].append(calculate_option_price(S, K, r + rho, T, sigma, 'put'))

# Plotting call option values for different Rho values
plt.figure(figsize=(8, 6))
for rho, values in call_option_values.items():
    plt.plot(K_range, values, label=f'Rho={rho:.2f}', linestyle='-', marker='o')

plt.title('Call Option Value vs Strike Price for Different Rho')
plt.xlabel('Strike Price')
plt.ylabel('Call Option Value')
plt.legend(title='Rho')
plt.grid(True)
plt.show()

# Plotting put option values for different Rho values
plt.figure(figsize=(8, 6))
for rho, values in put_option_values.items():
    plt.plot(K_range, values, label=f'Rho={rho:.2f}', linestyle='-', marker='o')

plt.title('Put Option Value vs Strike Price for Different Rho')
plt.xlabel('Strike Price')
plt.ylabel('Put Option Value')
plt.legend(title='Rho')
plt.grid(True)
plt.show()

Output