Created
May 11, 2021 16:03
-
-
Save fnneves/c3b284ac77ddd4b694964f2f00ffcd82 to your computer and use it in GitHub Desktop.
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
import pandas as pd | |
from glob import glob | |
from time import strftime, sleep | |
import numpy as np | |
from datetime import datetime | |
from pandas_datareader import data as pdr | |
from pandas.tseries.offsets import BDay | |
import yfinance as yf | |
yf.pdr_override() | |
# simple function to make headers nicer | |
def clean_header(df): | |
df.columns = df.columns.str.strip().str.lower().str.replace('.', '').str.replace('(', '').str.replace(')', '').str.replace(' ', '_').str.replace('_/_', '/') | |
# timestamp for file names | |
def get_now(): | |
now = datetime.now().strftime('%Y-%m-%d_%Hh%Mm') | |
return now | |
last_file = glob('../inputs/transactions_all/transactions*.xlsx')[-1] # path to file in the folder | |
print(last_file[-(len(last_file))+(last_file.rfind('/')+1):]) | |
all_transactions = pd.read_excel(last_file) | |
all_transactions.date = pd.to_datetime(all_transactions.date, format='%d/%m/%Y') | |
all_tickers = list(all_transactions['ticker'].unique()) | |
# some tickers may have been delisted. need to blacklist them here | |
blacklist = ['VSLR', 'HTZ'] | |
filt_tickers = [tick for tick in all_tickers if tick not in blacklist] | |
print('You traded {} different stocks'.format(len(all_tickers))) | |
# all transactions without the delisted stocks | |
final_filtered = all_transactions[~all_transactions.ticker.isin(blacklist)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment