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
In [ ]:
!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
In [21]:
importpymongoimportdatetimefrompymongoimportMongoClientclient=MongoClient('mongodb://144.217.72.168: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))In [22]:
optionOut[22]:
[{'_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}]In [17]:
list(db.eod_stock_data.find({'ticker':'TSLA'}).sort([('date',pymongo.DESCENDING)]).limit(1))Out[17]:
[{'_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}]In [33]:
importopstratasopimportjsonIn [32]:
K=100#Excercise Price of the optionSt=119.77#current stock pricer=0.0425#risk free interest rate 4.25%t=11#time to expire in daysv=82.9#implied volatilitytype='c'#put or call optionbsm=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.