def getdailyadjclose(symbol: str, startdate: str, enddate: str) -> [float]: Utilities.verifydate(startdate) Utilities.verifydate(enddate) # bug: does not verify the date range matches. would require a more extensive cache system if symbol in __dailyadjcache.keys(): return __dailyadjcache[symbol] share = yf.Share(symbol) history = share.get_historical(startdate, enddate) history.reverse() adjclose = [float] for h in history: adjclose.append(float(h["Adj_Close"])) __dailyadjcache[symbol] = adjclose return adjclose
def main(): importfile = 'ex.json' if len(sys.argv) == 1 else sys.argv[1] portfolios = [] with open(importfile) as jsonfile: p = json.loads(jsonfile.read()) portfolios = Portfolio.getportfolios(p) profit = StockCalc.calculateprofit( portfolios, ("2016-01-01", Utilities.getformattedtoday())) StockCalc.printgraph(profit)
def clean(self) : self.df = self.df.replace('', np.nan) self.df = self.df.dropna(subset=['FacilityLatitude','FacilityLongitude']) if 'GEOJSON.COORDINATES' in self.df.columns : self.df = self.df.drop(['GEOJSON.COORDINATES'], axis=1) if 'GEOJSON.TYPE' in self.df.columns: self.df = self.df.drop(['GEOJSON.TYPE'], axis=1) # drop duplicates #print("dropping duplicates") self.df = Utilities.dedupe_by_distance(self.df, 1, 'FacilityLatitude', 'FacilityLongitude', 'LastUpdatedDate')
def clean(self): self.df = self.df.replace('', np.nan) self.df = self.df.dropna( subset=['FacilityLatitude', 'FacilityLongitude']) if 'GEOJSON.COORDINATES' in self.df.columns: self.df = self.df.drop(['GEOJSON.COORDINATES'], axis=1) if 'GEOJSON.TYPE' in self.df.columns: self.df = self.df.drop(['GEOJSON.TYPE'], axis=1) # drop duplicates #print("dropping duplicates") self.df = Utilities.dedupe_by_distance(self.df, 1, 'FacilityLatitude', 'FacilityLongitude', 'LastUpdatedDate')
def run_merge(self, df_sub, df_super): merge_idx = Utilities.get_merge_index(df_sub,df_super, 0.2) df_super = df_super.assign(merge_index=merge_idx.astype(int)) df_sub = df_sub[df_sub.columns[~df_sub.columns.isin(df_super.columns)]] merged = pd.merge(df_super, df_sub, how='left', left_on='merge_index', right_index = True) return merged
def testpreviousweekday(self): day = "2016-11-12" pv = Utilities.getpreviousweekday(day) self.assertEqual("2016-11-10", pv)
def multiarray(self): v1 = [5,5,5,5] v2 = [1,2,3,4] self.assertEqual([5,10,15,20], Utilities.multiplyarray(v1,v2))
def merge(self, dp: []): dps = [self.profitdelta] for cdp in dp: dps.append(cdp.profitdelta) self.profitdelta = Utilities.ziparrays(dps[1:])
def setdaterange(self, dr: (str, str)): dr1 = Utilities.verifydate(dr[0]) dr2 = Utilities.verifydate(dr[0]) self.daterange = (dr1, dr2)
def getdailyrevenue(symbol: str, stocks: int, startdate: str, enddate: str) -> [float]: adj = getdailyadjclose(symbol, startdate, enddate)[1:] v2 = Utilities.generatefullvector(stocks, len(adj))[0] return Utilities.multiplyarray(adj[1:], v2[0])