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)
Beispiel #2
0
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)
Beispiel #3
0
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)
import torch
from torch import nn
from torch.optim import Adam
from torch.nn.init import xavier_normal as xavier
import matplotlib.pyplot as plt

from data.unorm_loader import cryptoData
from models.model import SeqRegressor

DEVICE = torch.device("cpu")
MODE = "train"

if __name__ == "__main__":

    model = SeqRegressor()

    optimizer = Adam(model.parameters(), lr=0.00001, weight_decay=0.000001)
    lossfn = nn.MSELoss(reduction='mean')

    if MODE == "train":
        test = False
    else:
        test = True

    dataloader = cryptoData("btc", test=test, DEVICE=DEVICE, window=7)
    model.to(DEVICE)
    breaker = len(dataloader)

    for j in range(700):
        tots = 0
from torch.optim import Adam
from torch.nn.init import xavier_normal as xavier
import matplotlib.pyplot as plt

from data.loader import cryptoData
from models.model import SeqRegressor

DEVICE = torch.device("cpu")
MODE = "test"
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):