def test_data(): n = 100 t = np.arange(n) # [0 .. n-1] # triangle # x = np.concatenate((np.arange(0,n/2,1), np.arange(n/2,0,-1))) # step x = ti.step(t - n/2) * 10 # ramp # x = ramp(t - n/2) # normalized random # x = np.cumsum(np.random.randn(n)) # x = np.sin(8 * np.pi/n * t) + (.1 * t) # x = 20 * np.sin(2 * 2*np.pi/n * t) # Add noise: x = x + 1.2 * np.random.randn(len(x)) assert len(ti.sma(x, 10)) == len(x) assert len(ti.ema(x, 10)) == len(x) assert len(ti.linear_fit(x, 10)) == len(x) assert len(ti.iir_lowpass(x, 2, 10)) == len(x) assert len(ti.moving_min(x, 10)) == len(x) assert len(ti.moving_max(x, 10)) == len(x) assert len(ti.aema(x, 10)) == len(x) assert len(ti.rate_of_change(x, 20)) == len(x) assert len(ti.acceleration(x, 20)) == len(x)
def make_current_data(binance, symbol, day_start, day_end): df = pd.DataFrame(columns=[ "Time", "Close", "High", "Low", "Volume", "QuoteVolume", "TakerVolume", "TakerQuoteVolume", "TradeCount", "WMA7", "EMA25", "MA99", "BOLL_UP", "BOLL_DOWN", "SAR", "MACD", "MACD_SIGNAL", "RSI12" ]) #df = pd.DataFrame(columns=["Time","Open","Close","High","Low","Volume","QuoteVolume","TakerVolume","TakerQuoteVolume","TradeCount","MA7","MA25","MA99","EMA7","EMA25","EMA99","WMA7","WMA25","WMA99","BOLL_UP","BOLL_DOWN","VWAP","TEMA","SAR","MACD","MACD_SIGNAL","RSI6","RSI12","RSI24","K","D","J","OBV","WR","DI+","DI-","ADX","MTM","EMV"]) df.loc[:, "Time"] = pd.to_datetime(df["Time"]) df = df.set_index("Time") #to match the minimum size pad_multiplier = 300 // const.TIME_LENGTH if day_start == 0 and day_end == 0: klines = binance.get_klines(symbol, const.TIME_LENGTH * pad_multiplier) df = df.append(klines) else: for i in range(day_start, day_end, -1): klines = binance.get_historical_klines( symbol, str(i + 1) + " days ago UTC", str(i) + " days ago UTC") df = df.append(klines) try: df = df.astype("float64") #mpf.plot(df, type="candle") #df.loc[:, "MA7"] = technical_indicators.ma(df,7) #df.loc[:, "MA25"] = technical_indicators.ma(df,25) df.loc[:, "MA99"] = technical_indicators.ma(df, 99) #df.loc[:, "EMA7"] = technical_indicators.ema(df,7) df.loc[:, "EMA25"] = technical_indicators.ema(df, 25) #df.loc[:, "EMA99"] = technical_indicators.ema(df,99) df.loc[:, "WMA7"] = technical_indicators.wma(df, 7) #df.loc[:, "WMA25"] = technical_indicators.wma(df,25) #df.loc[:, "WMA99"] = technical_indicators.wma(df,99) df.loc[:, "BOLL_UP"], df.loc[:, "BOLL_DOWN"] = technical_indicators.boll( df, 21) #df.loc[:, "VWAP"] = technical_indicators.vwap(df,14) #df.loc[:, "TEMA"] = technical_indicators.tema(df,9) df.loc[:, "SAR"] = technical_indicators.sar(df) df.loc[:, "MACD"], df.loc[:, "MACD_SIGNAL"] = technical_indicators.macd(df) #df.loc[:, "RSI6"] = technical_indicators.rsi(df,6) df.loc[:, "RSI12"] = technical_indicators.rsi(df, 12) #df.loc[:, "RSI24"] = technical_indicators.rsi(df,24) #df.loc[:, "K"],df.loc[:, "D"],df.loc[:, "J"] = technical_indicators.kdj(df) #df.loc[:, "OBV"] = technical_indicators.obv(df) #df.loc[:, "WR"] = technical_indicators.wr(df,14) #df.loc[:, "DI+"],df.loc[:, "DI-"],df.loc[:, "ADX"] = technical_indicators.dmi(df) #df.loc[:, "MTM"] = technical_indicators.mtm(df) #df.loc[:, "EMV"] = technical_indicators.emv(df) #df.loc[:, "PL"] = technical_indicators.pl(df,12) #df = df.append(klines) except Exception as e: print('Exception : {}'.format(e)) df = None return df
def _main(): print("test_indicator = {}".format(ti.test_indicator('XBB.TO'))) t = np.arange(-5, 5, 1) s = ti.step(t) r = ti.ramp(t) plt.plot(t, s, marker='x', linestyle='None', label='step') plt.plot(t, r, marker='o', markerfacecolor='None', linestyle='None', label='ramp') plt.legend() plt.show() t = np.linspace(0, 4 * np.pi, 50) s = np.sin(t) c = np.cos(t) o = ti.cross_over(s, c) u = ti.cross_under(s, c) fig = plt.figure() ax = fig.add_subplot(211) ax.plot(t, s, marker='.', label='sin') ax.plot(t, c, marker='x', label='cos') ax.legend() ax2 = fig.add_subplot(212) ax2.plot(t, o, marker='^', markerfacecolor='None', linestyle='None', label='cross over') ax2.plot(t, u, marker='v', markerfacecolor='None', linestyle='None', label='cross under') ax2.legend() plt.show() n = 100 t = np.arange(n) # [0 .. n-1] # triangle # x = np.concatenate((np.arange(0,n/2,1), np.arange(n/2,0,-1))) # step x = ti.step(t - n / 2) * 10 # ramp #x = ramp(t - n/2) # normalized random # x = np.cumsum(np.random.randn(n)) # x = np.sin(8 * np.pi/n * t) + (.1 * t) # x = 20 * np.sin(2 * 2*np.pi/n * t) # Add noise: x = x + 1.2 * np.random.randn(len(x)) fig = plt.figure() ax = fig.add_subplot(211) ax.plot(t, x, 'o', label='raw') ax.plot(t, ti.sma(x, 10), label='sma') ax.plot(t, ti.ema(x, 10), label='ema') ax.plot(t, ti.linear_fit(x, 10), label='linear_fit') ax.plot(t, ti.iir_lowpass(x, 1, 10), label='iir_lowpass') ax.plot(t, ti.moving_min(x, 10), label='moving_min') ax.plot(t, ti.moving_max(x, 10), label='moving_max') ax.plot(t, ti.aema(x, 10), label='aema') ax.grid(True) ax.legend() ax2 = fig.add_subplot(212) ax2.plot(t, ti.rate_of_change(x, 20), 'x', label='rate_of_change') ax2.plot(t, ti.acceleration(x, 20), 'o--', label='acceleration') ax2.grid(True) ax2.legend() plt.show()
def make_current_data(binance, symbol, day_start, day_end): sub_pair_symbols = const.PAIR_SYMBOLS.copy() sub_pair_symbols.remove(symbol) df = pd.DataFrame(columns=[ "Time", "Close", "High", "Low", "Volume", "QuoteVolume", "TakerVolume", "TakerQuoteVolume", "TradeCount", "WMA7", "EMA25", "MA99", "BOLL_UP", "BOLL_DOWN", "SAR", "MACD", "MACD_SIGNAL", "RSI12" ]) #df = pd.DataFrame(columns=["Time","Open","Close","High","Low","Volume","QuoteVolume","TakerVolume","TakerQuoteVolume","TradeCount","MA7","MA25","MA99","EMA7","EMA25","EMA99","WMA7","WMA25","WMA99","BOLL_UP","BOLL_DOWN","VWAP","TEMA","SAR","MACD","MACD_SIGNAL","RSI6","RSI12","RSI24","K","D","J","OBV","WR","DI+","DI-","ADX","MTM","EMV"]) df.loc[:, "Time"] = pd.to_datetime(df["Time"]) df = df.set_index("Time") sub_pair_dict = {} for i in sub_pair_symbols: sub_pair_dict[i] = pd.DataFrame(columns=[ "Close", "High", "Low", "Volume", "QuoteVolume", "TakerVolume", "TakerQuoteVolume", "TradeCount" ]) #to match the minimum size pad_multiplier = 128 // const.TIME_LENGTH if day_start == 0 and day_end == 0: klines = binance.get_klines(symbol, const.TIME_LENGTH * pad_multiplier) df = df.append(klines) for i in sub_pair_symbols: sub_klines = binance.get_klines(i, const.TIME_LENGTH * pad_multiplier) sub_pair_dict[i] = sub_pair_dict[i].append(sub_klines) else: for i in range(day_start, day_end, -64): klines = binance.get_historical_klines( symbol, str(i + 64) + " days ago UTC", str(i) + " days ago UTC") df = df.append(klines) for j in sub_pair_symbols: sub_klines = binance.get_historical_klines( j, str(i + 64) + " days ago UTC", str(i) + " days ago UTC") sub_pair_dict[j] = sub_pair_dict[j].append(sub_klines) df = df.astype("float64") #mpf.plot(df, type="candle") #df.loc[:, "MA7"] = technical_indicators.ma(df,7) #df.loc[:, "MA25"] = technical_indicators.ma(df,25) df.loc[:, "MA99"] = technical_indicators.ma(df, 99) #df.loc[:, "EMA7"] = technical_indicators.ema(df,7) df.loc[:, "EMA25"] = technical_indicators.ema(df, 25) #df.loc[:, "EMA99"] = technical_indicators.ema(df,99) df.loc[:, "WMA7"] = technical_indicators.wma(df, 7) #df.loc[:, "WMA25"] = technical_indicators.wma(df,25) #df.loc[:, "WMA99"] = technical_indicators.wma(df,99) df.loc[:, "BOLL_UP"], df.loc[:, "BOLL_DOWN"] = technical_indicators.boll(df, 21) #df.loc[:, "VWAP"] = technical_indicators.vwap(df,14) #df.loc[:, "TEMA"] = technical_indicators.tema(df,9) df.loc[:, "SAR"] = technical_indicators.sar(df) df.loc[:, "MACD"], df.loc[:, "MACD_SIGNAL"] = technical_indicators.macd(df) #df.loc[:, "RSI6"] = technical_indicators.rsi(df,6) df.loc[:, "RSI12"] = technical_indicators.rsi(df, 12) #df.loc[:, "RSI24"] = technical_indicators.rsi(df,24) #df.loc[:, "K"],df.loc[:, "D"],df.loc[:, "J"] = technical_indicators.kdj(df) #df.loc[:, "OBV"] = technical_indicators.obv(df) #df.loc[:, "WR"] = technical_indicators.wr(df,14) #df.loc[:, "DI+"],df.loc[:, "DI-"],df.loc[:, "ADX"] = technical_indicators.dmi(df) #df.loc[:, "MTM"] = technical_indicators.mtm(df) #df.loc[:, "EMV"] = technical_indicators.emv(df) #df.loc[:, "PL"] = technical_indicators.pl(df,12) #df = df.append(klines) for i in sub_pair_symbols: df.insert(len(df.columns), i, sub_pair_dict[i]["Close"]) df = df.fillna(0.1) df = df.astype("float64") return df