This file contains 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
from math import * | |
# Cumulative standard normal distribution | |
def cdf(x): | |
return (1.0 + erf(x / sqrt(2.0))) / 2.0 | |
# Intermediate calculation used by both the Bjerksund Stensland 1993 and 2002 approximations | |
def phi(s, t, gamma, h, i, r, a, v): | |
lambda1 = (-r + gamma * a + 0.5 * gamma * (gamma - 1) * v**2) * t | |
dd = -(log(s / h) + (a + (gamma - 0.5) * v**2) * t) / (v * sqrt(t)) |
This file contains 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
from math import * | |
# Cumulative standard normal distribution | |
def cdf(x): | |
return (1.0 + erf(x / sqrt(2.0))) / 2.0 | |
# Call Price based on Black Scholes Model | |
# Parameters | |
# underlying_price: Price of underlying asset | |
# exercise_price: Exercise price of the option |
This file contains 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
import re | |
from datetime import date | |
# Months Dictionary | |
MONTHS = {'enero': 1, 'febrero': 2, 'marzo': 3, 'abril': 4, 'mayo': 5, 'junio': 6, 'julio': 7, 'agosto': 8, 'septiembre': 9, 'octubre': 10, 'noviembre': 11, 'diciembre': 12} | |
# Function that converts thex date to python datetime | |
def get_date_from_text(text): | |
# Remove spaces to simplify the RegEx |
This file contains 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
import yfinance as yf | |
import math | |
stock = yf.Ticker("XOM") # Get ticker | |
expiration = stock.options[0] # Get next expiration date | |
opt = stock.option_chain(expiration) # Get the option chain | |
options = opt.calls # Get options | |
for idx_left_body, left_body in options.iterrows(): # Iterate over all options | |
left_wings = options[options['strike'] < left_body['strike']] # Get left wings |
This file contains 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
import yfinance as yf | |
import math | |
stock = yf.Ticker("MSFT") # Get ticker | |
expiration = stock.options[0] # Get next expiration date | |
opt = stock.option_chain(expiration) # Get the option chain | |
options = opt.puts # Get options | |
for idx_body, body in options.iterrows(): # Iterate over all options | |
left_wings = options[options['strike'] < body['strike']] # Get left wings |
This file contains 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
from yahoo_fin import stock_info as si | |
import time | |
# Settings | |
ticker = "MSFT" # Ticker to follow | |
portfolio_cash = 10000 # Starting cash | |
portfolio_stocks = 0 # Starting stocks | |
commisions = 0.005 # Commissions | |
# Function implemented |
This file contains 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
import yfinance as yf | |
import math | |
stock = yf.Ticker("AAPL") # Get ticker | |
expiration = stock.options[0] # Get next expiration date | |
opt = stock.option_chain(expiration) # Get the option chain | |
options = opt.calls # Get options | |
for idx_body, body in options.iterrows(): # Iterate over all options | |
left_wings = options[options['strike'] < body['strike']] # Get left wings |