The vega of an option is expressed as a percentage, and it represents the change in the option's price for a 1% change in the implied volatility of the underlying asset. For example, if an option has a vega of 0.20, this means that the price of the option is expected to increase by $0.20 for every 1% increase in the implied volatility of the underlying asset.
We will be using following modules to do this excercise.
- pymongo (assuming mongodb is already installed)
- opstrat Python library to calculate option geeks using Black Scholes
!pip install opstrat
For this excercise let us look at Tesla options. We will caculate the Options geek for the following option contract...
- Todays date is Jan 9, 2023
- TSLA Jan 20 2023 100 Call
import pymongo
import datetime
from pymongo import MongoClient
client = MongoClient('mongodb://localhost:27017')
db = client['stocktwits']
expirationDate = datetime.datetime.strptime("2023-01-20","%Y-%m-%d")
option = list(db.tdameritrade.find({'contractName':'TSLA',\
'strike':100.0,\
'option_type':'call',\
'expirationDate':expirationDate},\
{'bid':1,'ask':1,'last':1,'daysToExpiration':1,\
'description':1,'strike':1,'volatility':1})\
.sort([('added',pymongo.DESCENDING)]).limit(1))
option
[{'_id': ObjectId('63bc57d6458ed2500e7cef5d'), 'description': 'TSLA Jan 20 2023 100 Call', 'bid': 20.7, 'ask': 20.9, 'last': 20.5, 'volatility': 82.941, 'vega': 0.037, 'daysToExpiration': 11, 'strike': 100.0}]
list(db.eod_stock_data.find({'ticker':'TSLA'}).sort([('date',pymongo.DESCENDING)]).limit(1))
[{'_id': ObjectId('63bc91a3275fc68177ad4212'), 'date': datetime.datetime(2023, 1, 9, 0, 0), 'open': 118.96, 'high': 123.52, 'low': 117.11, 'close': 119.77, 'adjusted_close': 119.77, 'volume': 188448460, 'ticker': 'TSLA', 'perchange': 5.93}]
import opstrat as op
import json
K = 100 #Excercise Price of the option
St = 119.77 #current stock price
r = 0.0425 #risk free interest rate 4.25%
t = 11 #time to expire in days
v = 82.9 #implied volatility
type = 'c' #put or call option
bsm=op.black_scholes(K=K, St=St, r=r, t=t,
v=v, type='c')
print(json.dumps(bsm,indent=2))
{ "value": { "option value": 98.8702676900665, "intrinsic value": 98.87, "time value": 0.00026769006649374205 }, "greeks": { "delta": 1.0, "gamma": 1.0670964994225347e-34, "theta": -2.4335304744443113e-05, "vega": 3.8243193031313692e-34, "rho": 0.006298549463267629 } }
As we can see above, the above code outputs not only vega but all the option Geeks.
Related Notebooks
- Plot Stock Options Vega Implied Volatility Using Python Matplotlib
- Calculate Stock Options Max Pain Using Data From Yahoo Finance With Python
- Calculate Implied Volatility of Stock Option Using Python
- Stock Sentiment Analysis Using Autoencoders
- Stock Charts Detection Using Image Classification Model ResNet
- Stock Tweets Text Analysis Using Pandas NLTK and WordCloud
- Crawl Websites Using Python
- Understanding Logistic Regression Using Python
- Understanding Word Embeddings Using Spacy Python