Exemplo n.º 1
0
def fetch_data(currenceyAr, exchange, directory, period):
    dataObj = GetData(exchange, directory)
    EWCEWAIGE = pd.read_csv('EWCEWAIGE.csv').set_index('date')
    currenceyPairs = []
    currenceyTsLengths = []
    for currencey in currenceyAr:
        if currencey == 'ewc' or currencey == 'ewa' or currencey == 'ige':
            currenceyPairs.append(EWCEWAIGE[currencey].values)
            currenceyTsLengths.append(len(EWCEWAIGE[currencey].values))
        else:
            ts = dataObj.fetch(currencey)
            ts = dataObj.periodFormatter(currencey, period)
            ts.index = pd.to_datetime(ts.index).dropna()
            currenceyTsLengths.append(len(ts.Close.values))
            currenceyPairs.append(ts.Close.values)
    maxLen = 20000
    for count, curr in enumerate(currenceyPairs):
        if min(currenceyTsLengths) < 10000:
            currenceyPairs[count] = curr[-min(currenceyTsLengths):]
        else:
            currenceyPairs[count] = curr[-maxLen:]
    A = []
    for curr in currenceyPairs:
        A.append(curr)
    A = np.transpose(np.array(A))

    return A
Exemplo n.º 2
0
    def __init__(self, exchange, currencey, period, directory, livePreScreen=False):
        self.exchange=exchange
        self.currencey = currencey
        self.period = period
        self.directory = directory
        
        dataObj = GetData(self.exchange, self.directory)
        self.ts = dataObj.fetch(self.currencey)
        self.ts = dataObj.periodFormatter(self.currencey, period)
        self.ts.index = pd.to_datetime(self.ts.index).dropna()
        
        dataObj = GetData(self.exchange, self.directory)
        self.tsA = dataObj.fetch('XMR/USDT')
        self.tsA = dataObj.periodFormatter('XMR/USDT', period)
        self.tsA.index = pd.to_datetime(self.tsA.index).dropna()
        self.tsB = dataObj.fetch('ETH/USDT')
        self.tsB = dataObj.periodFormatter('ETH/USDT', period)
        self.tsB.index = pd.to_datetime(self.tsB.index).dropna()

        self.USDCAD = pd.read_csv('CADUSD.csv').astype(float).dropna()
        self.EWCEWAIGE = pd.read_csv('EWCEWAIGE.csv').set_index('date')
Exemplo n.º 3
0
def main():
    data = GetData('poloniex', newdata=True)
    tickers = [
        'LTC/USDT'
    ]  #,'BTC/USDT']                           #tickers = data.tickers()
    ##    tickers = ['OMG/BTC']#,'ETH/BTC','XMR/BTC','ZEC/BTC','BTC/USDT']
    periods = ['5m', '15m', '30m', '1h']  #periods = ['5m','15m','30m','1h']
    maximum_parameters = []
    proportion_test = 0.1
    graph_results = True
    data.fetch('BTC/USDT')  # use if list length error'ETH/USDT','XRP/USDT',
    type_coin = 'USDT'
    for tick in tickers:
        if tick[-len(type_coin):] == type_coin:
            data.fetch(tick)
            temp_results = []
            for numsimul in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
                for period in periods:
                    '''formats the bitcoin and current coin data to the right period'''
                    tick_data = data.periodFormatter(tick, period)
                    startDate = tick_data.index[0]
                    btc_data = data.periodFormatter('BTC/USDT', period,
                                                    startDate)
                    '''formats the raw data to the proportion of data chosen'''
                    startDate = tick_data.index[int(
                        (1 - proportion_test) * len(tick_data))]
                    endDate = tick_data.index[-1]
                    btc_prices = btc_data.loc[startDate:endDate]['Close']
                    tick_prices = tick_data.loc[startDate:endDate]['Close']

                    if len(tick_prices) != len(btc_prices):
                        tick_prices.drop(tick_prices.index[0], inplace=True)

                    if len(tick_prices) == len(
                            btc_prices) or tick[-len(type_coin):] == type_coin:

                        strategy = Strategy(len(tick_prices), numsimul)

                        for count, price in enumerate(tick_prices.values):
                            if type_coin == 'BTC':
                                strategy.tick(price, btc_prices.values[count])
                            elif type_coin == 'USDT':
                                strategy.tick(price)
                            strategy.macd(26, 12, 9, count, len(tick_prices))
                        temp_results.append([
                            tick, period, strategy.profit, strategy.balance,
                            tick_prices, strategy.numtrades,
                            min(strategy.balanceList), strategy
                        ])

                    else:
                        print('length error')
                        break

            optimumParam = None
            for result in temp_results:
                if optimumParam == None:
                    optimumParam = result
                    optimum = result
                elif result[3] > optimumParam[3]:
                    optimumParam = result
                else:
                    pass

            print(optimumParam[0], optimumParam[1],
                  '\nProfit on one coin per trade:', optimumParam[2],
                  '\nBalance on', optimumParam[-1].USDpertrade,
                  'USD per trade:', optimumParam[3],
                  '\nNumber of simeltaneuos trades:',
                  optimumParam[-1].numSimul, '\nNumber of trades:',
                  optimumParam[-1].numtrades)
            maximum_parameters.append(optimumParam)
    for param in maximum_parameters:
        plot = Graphics(param[4],
                        bal=param[-1].balanceList,
                        buylist=param[-1].buylist,
                        selllist=param[-1].selllist,
                        MACD=param[-1].MACD,
                        signal=param[-1].signal,
                        EMAfast=param[-1].EMAfast,
                        EMAslow=param[-1].EMAslow)
        plot.MACD_plot(26)
Exemplo n.º 4
0
def main():
    data = GetData('poloniex', newdata=False)
    tickers = ['OMG/BTC']  #tickers = data.tickers()
    periods = ['30m']  #periods = ['5m','15m','30m','1h']
    maximum_parameters = []
    proportion_test = 0.1
    graph_results = True
    #data.fetch('BTC/USDT') # use if list length error

    for tick in tickers:
        if tick[-3:] == 'BTC':
            data.fetch(tick)
            temp_results = []

            for period in periods:
                '''formats the bitcoin and current coin data to the right period'''
                tick_data = data.periodFormatter(tick, period)
                startDate = tick_data.index[0]
                btc_data = data.periodFormatter('BTC/USDT', period, startDate)
                prices = [close for close in tick_data['Close']]
                '''formats the raw data to the proportion of data chosen'''
                startDate = tick_data.index[int(
                    (1 - proportion_test) * len(prices))]
                endDate = tick_data.index[-1]
                btc_prices = btc_data.loc[startDate:endDate]['Close']
                tick_prices = tick_data.loc[startDate:endDate]['Close']

                for MAlong in [10, 15, 30]:
                    for x in [2, 3, 4]:
                        MAshort = int(MAlong / x)
                        if len(tick_prices) == len(btc_prices):

                            strategy = Strategy(len(tick_prices))

                            for count, price in enumerate(tick_prices.values):
                                strategy.tick(price, btc_prices.values[count])
                                strategy.movingaverage(MAlong, MAshort, count)

                            profit, balance = strategy.returnParam()
                            temp_results.append([
                                tick, period, tick_prices, strategy, profit,
                                balance, MAlong, MAshort
                            ])
                        else:
                            print('length error')
                            break

            optimumParam = None
            for result in temp_results:
                if optimumParam == None:
                    optimumParam = result
                    optimum = result
                elif result[5] > optimumParam[5]:
                    optimumParam = result
                else:
                    pass

            print(optimumParam[0], optimumParam[1], optimumParam[4],
                  optimumParam[5], optimumParam[6], optimumParam[7])
            maximum_parameters.append(optimumParam)

        for param in maximum_parameters:
            plot = Graphics(param[2], param[3].MAlong, param[3].MAshort,
                            param[3].buylist, param[3].selllist,
                            param[3].balanceList)
            plot.MA_plot()