NbShare
  • Nbshare Notebooks

  • Table of Contents

  • Python Utilities

    • How To Install Jupyter Notebook
    • How to Upgrade Python Pip
    • How To Use Python Pip
  • Python

    • Python Datetime
    • Python Dictionary
    • Python Generators
    • Python Iterators and Generators
    • Python Lambda
    • Python Sort List
    • String And Literal In Python 3
    • Strftime and Strptime In Python
    • Python Tkinter
    • Python Underscore
    • Python Yield
  • Pandas

    • Aggregating and Grouping
    • DataFrame to CSV
    • DF to Numpy Array
    • Drop Columns of DF
    • Handle Json Data
    • Iterate Over Rows of DataFrame
    • Merge and Join DataFrame
    • Pivot Tables
    • Python List to DataFrame
    • Rename Columns of DataFrame
    • Select Rows and Columns Using iloc, loc and ix
    • Sort DataFrame
  • PySpark

    • Data Analysis With Pyspark
    • Read CSV
    • RDD Basics
  • Data Science

    • Confusion Matrix
    • Decision Tree Regression
    • Logistic Regression
    • Regularization Techniques
    • SVM Sklearn
    • Time Series Analysis Using ARIMA
  • Machine Learning

    • How To Code RNN and LSTM Neural Networks in Python
    • PyTorch Beginner Tutorial Tensors
    • Rectified Linear Unit For Artificial Neural Networks Part 1 Regression
    • Stock Sentiment Analysis Using Autoencoders
  • Natural Language
    Processing

    • Opinion Mining Aspect Level Sentiment Analysis
    • Sentiment Analysis using Autoencoders
    • Understanding Autoencoders With Examples
    • Word Embeddings Transformers In SVM Classifier
  • R

    • DataFrame to CSV
    • How to Create DataFrame in R
    • How To Use Grep In R
    • How To Use R Dplyr Package
    • Introduction To R DataFrames
    • Tidy Data In R
  • A.I. News
NbShare Notebooks
  • Publish Your Post On nbshare.io

  • R Python Pandas Data Science Excel NLP Numpy Pyspark Finance

Demystifying Stock Options Vega Using Python

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.

  1. pymongo (assuming mongodb is already installed)
  2. 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...

  1. Todays date is Jan 9, 2023
  2. TSLA Jan 20 2023 100 Call
In [21]:
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))
In [22]:
option
Out[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]:
import opstrat as op
import json
In [32]:
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

Register

User Already registered.


Login

Login

We didn't find you! Please Register

Wrong Password!


Register
    Top Notebooks:
  • Data Analysis With Pyspark Dataframe
  • Strftime and Strptime In Python
  • Python If Not
  • Python Is Integer
  • Dictionaries in Python
  • How To install Python3.9 With Conda
  • String And Literal In Python 3
  • Privacy Policy
©