Skip to content

Instantly share code, notes, and snippets.

@shashankvemuri
shashankvemuri / sma_deviation.py
Created March 7, 2023 16:08
A program that uses historical stock price data to calculate percentage deviation of a stock price from a simple moving average
import yfinance as yf
import datetime as dt
from pandas_datareader import data as pdr
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as mticker
yf.pdr_override()
sma = 50
limit = 30
@shashankvemuri
shashankvemuri / all.py
Last active January 24, 2024 00:01
all the code
import numpy as np
import warnings
from pandas_datareader import data as pdr
import yfinance as yf
import datetime as dt
from yahoo_fin import stock_info as si
import pandas as pd
pd.set_option('display.max_rows', None)
warnings.filterwarnings("ignore")
yf.pdr_override()
@shashankvemuri
shashankvemuri / top_correlations.py
Created September 13, 2020 19:27
top absolute correlations
def get_top_abs_correlations(df):
au_corr = df.corr().abs().unstack()
labels_to_drop = get_redundant_pairs(df)
au_corr = au_corr.drop(labels=labels_to_drop).sort_values(ascending=False)
return au_corr
print("\nTop Absolute Correlations")
print(get_top_abs_correlations(stocks_returns))
@shashankvemuri
shashankvemuri / functions.py
Last active September 15, 2020 02:18
functions
def get_redundant_pairs(df):
pairs_to_drop = set()
cols = df.columns
for i in range(0, df.shape[1]):
for j in range(0, i+1):
pairs_to_drop.add((cols[i], cols[j]))
return pairs_to_drop
def get_top_abs_correlations(df):
au_corr = df.corr().abs().unstack()
@shashankvemuri
shashankvemuri / correlation.py
Created September 13, 2020 19:25
correlation
dataset = pdr.get_data_yahoo(tickers, start, end)['Adj Close']
stocks_returns = np.log(dataset/dataset.shift(1))
print('\nCorrelation Matrix')
corr_matrix = stocks_returns.corr()
print (corr_matrix)
@shashankvemuri
shashankvemuri / intro.py
Last active September 15, 2020 02:17
Intro
import numpy as np
import warnings
from pandas_datareader import data as pdr
import yfinance as yf
import datetime as dt
from yahoo_fin import stock_info as si
import pandas as pd
pd.set_option('display.max_rows', None)
warnings.filterwarnings("ignore")
yf.pdr_override()
@shashankvemuri
shashankvemuri / code.py
Last active January 16, 2024 19:40
code
# Importing necessary libraries
import time
import pandas as pd
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from pandas_datareader import data as pdr
import yfinance as yf
@shashankvemuri
shashankvemuri / all.py
Created August 16, 2020 20:58
all of the code
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup as soup
from urllib.request import Request, urlopen
pd.set_option('display.max_colwidth', 25)
# Input
symbol = input('Enter a ticker: ')
print ('Getting data for ' + symbol + '...\n')
def get_fundamentals():
try:
# Find fundamentals table
fundamentals = pd.read_html(str(html), attrs = {'class': 'snapshot-table2'})[0]
# Clean up fundamentals dataframe
fundamentals.columns = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11']
colOne = []
colLength = len(fundamentals)
for k in np.arange(0, colLength, 2):
@shashankvemuri
shashankvemuri / start.py
Created August 16, 2020 20:57
Start of code
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup as soup
from urllib.request import Request, urlopen
pd.set_option('display.max_colwidth', 25)
# Input
symbol = input('Enter a ticker: ')
print ('Getting data for ' + symbol + '...\n')