def hq_test(symbol): df = hqu.pdtick(symbol) hqu.pdAddCols(df) # hq_high_low(df, nDays=10) results = [] hq_llbcp(symbol, df, results) print(results)
def pdCollect(self, tick): df = hqu.pdtick(tick) hqu.pdAddCols(df) # day0 hqday0 = df.iloc[df.shape[0] - 1] self.collect['day0'] = { 'date': hqday0.name.strftime(DateFormat), 'close': hqday0.Close, 'ccchg': hqday0.CCChg, 'vvchg': hqday0.VVChg, 'llchg': hqday0.LLChg, } # lldays dfLlDays = hqpdu.pdLlDays(df, daysAgo=self.collect['defaultLastnDays']) straightStart, straightEnd = hqpdu.pdStraightLlDays(dfLlDays) # straightDays = straightStart - straightEnd + 1 # print(df[(df.No >= straightStart) & (df.No <= straightEnd)]) self.collect['lldays'] = { 'straightStart': int(straightStart ), # convert from int64 to avoid json serialization error 'straightEnd': int(straightEnd), 'straightLoss': ((dfLlDays[dfLlDays.No == straightStart].PrvClose[0] - dfLlDays[dfLlDays.No == straightEnd].Close[0]) / dfLlDays[dfLlDays.No == straightStart].PrvClose[0]) }
def hq_scan(symbols, withinDays=3): results = [] for symbol in symbols: # df = pd.read_csv(HqCsvRepo.format(symbol), index_col=[0], parse_dates=True) df = hqu.pdtick(symbol) hqu.pdAddCols(df) # begin scan hqop.hq_llbcp(symbol, df, results) hqop.hq_hhbcn(symbol, df, results) return pd.DataFrame(data=np.array(results), columns=hqop.HqOpColumns)
def hq_LLChg(symbol): df = hqu.pdtick(symbol) hqu.pdAddCols(df) plt.figure(figsize=[13, 9]) # width and height in inches plt.suptitle('{} ({} days) - LLChg Distribution'.format( symbol, df.shape[0]), fontsize=18) plt.subplot(311) #plt.plot(range(df.shape[0]), df.LLChg, 'g', linewidth=1) #plt.hlines(0, 0, df.shape[0], colors='r') plt.plot(df.LLChg, color='g', linewidth=1) plt.plot(df.LLChg, 'go', markersize=3) plt.hlines(0, df.index[0], df.index[df.shape[0] - 1], colors='r') #markerData = df.LLChg[df.LLChg.isin([0])] # marker where slope = 0 markerData = df.LLChg[(df.LLChg < 0.01) & (df.LLChg >= 0)] # less than -1% plt.plot(markerData, 'ko', markersize=5, label=markerData.index) plt.legend(loc='upper left') plt.ylabel('(Low - PrvLow)/PrvClose', fontsize=12) plt.subplot(312) plt.plot(df.Low, color='g', label="Low") plt.plot(df.Low, 'go', markersize=3) plt.plot(df.Close, color='b', label="Close") plt.plot(df.Close, 'bo', markersize=3) plt.vlines(df.index, 1.7, df.Close, color="y", linestyle=(0, (1, 3))) #'dotted' plt.legend(loc="upper left") plt.subplot(313) plt.vlines(df.index, 1000, df.Volume) plt.ylabel('Volume', fontsize=12) plt.xlabel('Date', fontsize=14) plt.show()
# LL days in a row def pdStraightLlDays(llDays): llDays = pd.DataFrame(data=llDays) llDays['NextNo'] = llDays.No.shift(1) llDays['NoStep'] = llDays.NextNo - llDays.No # next day indicator if eq 1 llDays = llDays.reindex(index=llDays.index[::-1]) # reverse date order return llDays[llDays.NoStep != 1].No[0], llDays.No[ 0] # return straightStart, straightEnd if __name__ == "__main__": # ticks = hqu.hqticks('ticks.hq') for tick in ['BNGO', 'AVIR']: df = hqu.pdtick(tick) # df = hqu.pdtickDateAgo(tick, '2021-07-07') hqu.pdAddCols(df) # print(df.shape) # # test llbcp # llbcp = pdLlbcp(df, 50) # print(llbcp) # # test pdStraightLlDays # llDays = pdLlDays(df, daysAgo=10) # straightStart, straightEnd = pdStraightLlDays(llDays) # print(df[(df.No >= straightStart) & (df.No <= straightEnd)]) # print(tick, 'straight LL days:', straightLlDays) # print('percent diff:', 100 *