Last active
February 12, 2024 17:57
-
-
Save ShabbirHasan1/c5efadf11098dc4dfcd0479a5bd17b4d to your computer and use it in GitHub Desktop.
Example Usage of GetIVGreeks File and CalcIvGreeks Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| """ | |
| :description: Example Codes To Use The Python Class Which Calculate Options IV and Greeks | |
| :license: MIT. | |
| :author: Shabbir Hasan | |
| :created: On Thursday December 22, 2022 23:43:57 GMT+05:30 | |
| """ | |
| __author__ = "Shabbir Hasan aka DruneMoone" | |
| __webpage__ = "https://github.com/ShabbirHasan1" | |
| __license__ = "MIT" | |
| __version__ = "0.0.1" | |
| import pandas as pd | |
| from datetime import datetime as dt | |
| try: | |
| from GetIVGreeks import DayCountType, ExpType, TryMatchWith, CalcIvGreeks | |
| except ImportError: | |
| exec( | |
| __import__("requests") | |
| .get( | |
| "https://gist.githubusercontent.com/ShabbirHasan1" | |
| + "/7695687d87053c7e3df46810ab2e3046" | |
| + "/raw/30551841a3fd3641c8416266fd27c5254d2150b3" | |
| + "/GetIVGreeks.py" | |
| ) | |
| .text | |
| ) | |
| if __name__ == "__main__": | |
| print( | |
| "\n", | |
| "Get IV & Greeks Exactly As You", | |
| "Get in https://web.sensibull.com/option-chain", | |
| sep=" ", | |
| end="\n\n", | |
| ) | |
| IvGreeks = CalcIvGreeks( | |
| SpotPrice=17806.80, | |
| FuturePrice=17880.10, | |
| AtmStrike=17900.0, | |
| AtmStrikeCallPrice=114.95, | |
| AtmStrikePutPrice=134.0, | |
| ExpiryDateTime=dt(2022, 12, 29), | |
| ExpiryDateType=ExpType.MONTHLY, | |
| FromDateTime=dt(2022, 12, 23, 15, 30, 0), | |
| tryMatchWith=TryMatchWith.SENSIBULL, | |
| dayCountType=DayCountType.CALENDARDAYS, | |
| ) | |
| df = pd.DataFrame.from_records( | |
| [ | |
| IvGreeks.GetImpVolAndGreeks( | |
| StrikePrice=17500.0, | |
| StrikeCallPrice=407.75, | |
| StrikePutPrice=31.0, | |
| ), | |
| IvGreeks.GetImpVolAndGreeks( | |
| StrikePrice=17900.0, | |
| StrikeCallPrice=114.95, | |
| StrikePutPrice=134.0, | |
| ), | |
| IvGreeks.GetImpVolAndGreeks( | |
| StrikePrice=18500.0, | |
| StrikeCallPrice=5.50, | |
| StrikePutPrice=627.60, | |
| ), | |
| ] | |
| ) | |
| print(df, end="\n\n\n") | |
| print( | |
| "Get IV & Greeks Exactly As You", | |
| "Get in https://www.nseindia.com/option-chain", | |
| sep=" ", | |
| end="\n\n", | |
| ) | |
| IvGreeks = CalcIvGreeks( | |
| SpotPrice=17806.80, | |
| FuturePrice=17880.10, | |
| AtmStrike=17800.0, | |
| AtmStrikeCallPrice=174.65, | |
| AtmStrikePutPrice=92.50, | |
| ExpiryDateTime=dt(2022, 12, 29), | |
| ExpiryDateType=ExpType.MONTHLY, | |
| FromDateTime=dt(2022, 12, 23, 15, 30, 0), | |
| tryMatchWith=TryMatchWith.NSE, | |
| dayCountType=DayCountType.CALENDARDAYS, | |
| ) | |
| df = pd.DataFrame.from_records( | |
| [ | |
| IvGreeks.GetImpVolAndGreeks( | |
| StrikePrice=17500.0, | |
| StrikeCallPrice=407.75, | |
| StrikePutPrice=31.0, | |
| ), | |
| IvGreeks.GetImpVolAndGreeks( | |
| StrikePrice=17900.0, | |
| StrikeCallPrice=114.95, | |
| StrikePutPrice=134.0, | |
| ), | |
| IvGreeks.GetImpVolAndGreeks( | |
| StrikePrice=18500.0, | |
| StrikeCallPrice=5.50, | |
| StrikePutPrice=627.60, | |
| ), | |
| ] | |
| ) | |
| print(df, end="\n\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment