def macd(coin_name, amount): model = SeqRegressor(coin=coin_name.lower(), model=MODEL) model.to(DEVICE) dataloaderX = cryptoData(coin_name.lower(), DEVICE=DEVICE) DAYS = len(dataloaderX) model.eval(dataloaderX[33][0].unsqueeze(1)) macd_line = [] signal_line = [] x = [] start_amount = amount no_of_coins = 0 print("\n", coin_name.upper(), ":") for i, (x_input, target) in enumerate( dataloaderX ): # TODO: Discuss standard time slot across all algorithms if i < 34: # let dataloader catchup with macd range continue if i == DAYS: break predictedPrice = model(x_input.unsqueeze(1)) * dataloaderX.pmax predictedPrice = predictedPrice.squeeze() (macd, macd_9, ema_12, ema_26, price) = dataloaderX.getMacDData(i) ema_12 = ema_12 + (predictedPrice - ema_12) * dataloaderX.multiplier_12 ema_26 = ema_26 + (predictedPrice - ema_26) * dataloaderX.multiplier_26 macd = ema_12 - ema_26 macd_9 = macd_9 + (macd - macd_9) * dataloaderX.multiplier_9 x.append(i) macd_line.append(macd) signal_line.append(macd_9) # If MACD crosses over Signal Line then bullish market if macd - macd_9 > 0 and no_of_coins == 0: no_of_coins = amount / price amount = 0 # If MACD crosses below Signal Line then bearish market if macd - macd_9 <= 0 and no_of_coins != 0: amount = no_of_coins * price no_of_coins = 0 if amount == 0: amount = no_of_coins * price print("\nStart: ", start_amount, " End: ", amount) macd_line = np.asarray(macd_line) signal_line = np.asarray(signal_line) x = np.asarray(x)
def boll_band(coin, amount): model = SeqRegressor(coin=coin, model=MODEL) model.to(DEVICE) print("\n", coin.upper(), ":") dataloader = cryptoData(coin, DEVICE=DEVICE) model.eval(dataloader[28][0].unsqueeze(1)) start = amount cash = amount no_of_coins = 0 mean = [] ub = [] lb = [] x = [] for i, (x_input, target) in enumerate( dataloader ): # TODO: Discuss standard time slot across all algorithms # Wait for the Moving Average if (i < 34): continue (sma_20, sma_30, sma_5, ubb, lbb, price) = dataloader.getBollBandData(i) trend = sma_5 - sma_30 x.append(i) ub.append(ubb) lb.append(lbb) mean.append(sma_20) predictedPrice = model(x_input.unsqueeze(1)) * dataloader.pmax predictedPrice = predictedPrice.squeeze() if trend > 0: # If Upward Trend and price touches Upper Bollinger Band then Buy if predictedPrice - ubb >= 0 and no_of_coins == 0: # print("Buy\n") no_of_coins = cash / price cash = 0 else: # If Downward Trend and price touches Lower Bollinger Band then Sell if predictedPrice - lbb <= 0 and no_of_coins != 0: # print("Sell\n") cash = no_of_coins * price no_of_coins = 0 if no_of_coins != 0: cash = no_of_coins * price no_of_coins = 0 print("\nStart: ", start, " End: ", cash)
def awesomeLSTM(coin_name, amount): model = SeqRegressor(coin=coin_name.lower(),model= MODEL) model.to(DEVICE) dataloaderX = cryptoData(coin_name.lower(),DEVICE=DEVICE) DAYS = len(dataloaderX) model.eval(dataloaderX[33][0].unsqueeze(1)) sma5_line = [] sma34_line = [] ao_line = [] start_amount = amount no_of_coins = 0 print("\n",coin_name.upper(),":") for i,(x_input,target) in enumerate(dataloaderX): # TODO: Discuss standard time slot across all algorithms if i < 34: # let dataloader catchup with macd range continue if i == DAYS: break predictedPrice = model(x_input.unsqueeze(1)) * dataloaderX.pmax sma_5,sma_34,AO,price,(new_sma5_lower,new_sma34_lower) = dataloaderX.getAOData(i) sma5_line.append(sma_5) sma34_line.append(sma_34) ao_line.append(AO) predicted_sma5 = (new_sma5_lower + predictedPrice)/2 predicted_sma34 = (new_sma34_lower + predictedPrice)/2 # Averaging out AO and predicted AO AO = (predicted_sma5 -predicted_sma34 + AO)/2 if AO > 0 and no_of_coins == 0: no_of_coins = amount/price amount = 0 if AO <= 0 and no_of_coins != 0: amount = no_of_coins*price no_of_coins = 0 if amount == 0: amount = no_of_coins*price print("\nStart: ",start_amount," End: ",amount) sma5_line = np.asarray(sma5_line) sma34_line = np.asarray(sma34_line) ao_line = np.asarray(ao_line)
COIN = "eth" MODEL = "unorm" STOCHASTIC = True if __name__ == "__main__": model = SeqRegressor(stochastic=STOCHASTIC, model=MODEL, coin=COIN) if MODE == "train": test = False else: test = True dataloader = cryptoData(currency=COIN, test=test, DEVICE=DEVICE, model=MODEL) model.to(DEVICE) breaker = len(dataloader) for j in range(100): model.eval(dataloader[0][0].unsqueeze(1)) t, h = [], [] z = 0 m = 0 r = 0 for i, (x, target) in enumerate(dataloader): if i == breaker: break x.unsqueeze_(1)
def main(COIN1, COIN2): model_coin1 = MLPRegressor(coin=COIN1, model=MODEL) model_coin1.to(DEVICE) model_coin2 = MLPRegressor(coin=COIN2, model=MODEL) model_coin2.to(DEVICE) dataloader_coin1 = cryptoData(COIN1, DEVICE=DEVICE, model=MODEL) DAYS_coin1 = len(dataloader_coin1) dataloader_coin2 = cryptoData(COIN2, DEVICE=DEVICE, model=MODEL) DAYS_coin2 = len(dataloader_coin2) model_coin1.eval(dataloader_coin1[0][0]) model_coin2.eval(dataloader_coin2[0][0]) residualModel = Residual(dataloader_coin1, dataloader_coin2) coin1_amt = 0 coin2_amt = 0 cash = 0 startDay = 34 trendThreshold = 1 shorts = longs = holds = 0 time = 0 for i in range(startDay, min(DAYS_coin1, DAYS_coin2)): time += 1 x_coin1, target_coin1 = dataloader_coin1[i] x_coin2, target_coin2 = dataloader_coin2[i] price_coin1 = dataloader_coin1.getDataFrame(i, 1) price_coin2 = dataloader_coin2.getDataFrame(i, 1) if i == startDay: coin1_amt = 5000 / price_coin1 coin2_amt = 5000 / price_coin2 out_coin1 = model_coin1(x_coin1) out_coin2 = model_coin2(x_coin2) zScore, risk = residualModel.zScore(i, out_coin1, out_coin2) trend_coin1 = getGeneralTrends(dataloader_coin1, i) trend_coin2 = getGeneralTrends(dataloader_coin2, i) if not risk: if zScore > 1: shorts += 1 if trend_coin2 > trendThreshold: temp = coin1_amt * price_coin1 coin1_amt = 0 coin2_amt += (temp / price_coin2) # print("\t",i,"Transaction: short at ",price_coin1.item(),price_coin2.item()) elif zScore < -1: longs += 1 if trend_coin1 > trendThreshold: temp = coin2_amt * price_coin2 coin2_amt = 0 coin1_amt += (temp / price_coin1) # print("\t",i,"Transaction: long at ",price_coin1.item(),price_coin2.item()) else: holds += 1 out_coin1 = out_coin1.item() * dataloader_coin1.pmax.item() out_coin2 = out_coin2.item() * dataloader_coin2.pmax.item() print(COIN1, COIN2, "\n\t", (coin1_amt * price_coin1) + (coin2_amt * price_coin2) + cash) print(time, '\n')
def macd(coin_name, amount): model = MLPRegressor(coin=coin_name.lower(), model=MODEL) model.to(DEVICE) dataloaderX = cryptoData(coin_name.lower(), DEVICE=DEVICE) DAYS = len(dataloaderX) model.eval(dataloaderX[33][0]) sma5_line = [] sma34_line = [] ao_line = [] start_amount = amount no_of_coins = 0 print("\n", coin_name.upper(), ":") buyAndHold = 10000 first = False time = 0 for i, (x_input, target) in enumerate( dataloaderX ): # TODO: Discuss standard time slot across all algorithms if i < 34: # let dataloader catchup with macd range continue if i == DAYS: break if not first: first = True buyAndHold = buyAndHold / target predictedPrice = model(x_input) * dataloaderX.pmax sma_5, sma_34, AO, price, (new_sma5_lower, new_sma34_lower) = dataloaderX.getAOData(i) sma5_line.append(sma_5) sma34_line.append(sma_34) ao_line.append(AO) predicted_sma5 = (new_sma5_lower + predictedPrice) / 2 predicted_sma34 = (new_sma34_lower + predictedPrice) / 2 # Averaging out AO and predicted AO AO = (predicted_sma5 - predicted_sma34 + AO) / 2 if AO > 0 and no_of_coins == 0: no_of_coins = amount / price amount = 0 if AO <= 0 and no_of_coins != 0: amount = no_of_coins * price no_of_coins = 0 # print(predicted_sma5.item()) time += 1 if amount == 0: amount = no_of_coins * price print("\nStart: ", start_amount, " End: ", amount) print(buyAndHold * target, time) sma5_line = np.asarray(sma5_line) sma34_line = np.asarray(sma34_line) ao_line = np.asarray(ao_line)