def reload_session(): session = db.create_session(autoflush=False)
import pandas as pd import numpy as np from zipdl.data import db from zipdl.data import models as m from pandas_datareader import data as pdr import fix_yahoo_finance as yf yf.pdr_override() import quandl import os quandl.ApiConfig.api_key = os.environ['QUANDL-APICONFIG'] from zipdl.utils import utils UNIVERSE = pd.read_csv('condensed_universe.csv') session = db.create_session(autoflush=False) def safe_pdr_get(ticker, start=None, end=None): tries = 0 data = quandl.get_table('WIKI/PRICES', qopts={'columns': ['date', 'close']}, ticker=ticker, date={ 'gte': start, 'lte': end }) data = data.set_index('date')['close'] return data no_shares = 0 for ticker in UNIVERSE:
import numpy as np import pandas as pd import pandas_datareader as pdr import fix_yahoo_finance as yf from zipdl.data import db from zipdl.data import models from datetime import datetime, date import datetime as dt yf.pdr_override() session = db.create_session() #==================UTILS=================== def strings_to_date(mydict, str_format): origlen = len(mydict.keys()) for key in list(mydict.keys()): mydict[datetime.strptime(key, str_format)] = mydict[key] del mydict[key] assert origlen == len(mydict.keys()) def dates_to_string(mydict): origlen = len(mydict.keys()) for key in list(mydict.keys()): if type(key) is not str: try: mydict[date.strftime(key, '%Y-%m-%d')] = mydict[key] except: try: