コード例 #1
0
ファイル: main.py プロジェクト: lotus321/Project-Portfolio
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
コード例 #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')
コード例 #3
0
    def data():
        #read in config info from json file
        data_config = json.load(open('input_config.json', 'r'))

        previous_data_name = data_config["data_and_directories"][
            "previous_data_name"]
        main_src_directory = data_config["data_and_directories"][
            "main_src_directory"]
        data_directory = data_config["data_and_directories"][
            "main_data_directory"]

        period = data_config["data_information"]["period"]
        assetType = data_config["data_information"]["asset_type"]
        pip = data_config["data_information"]["pip"]

        #we want to make it s.t. if the 'newdata' param is False, then there must be an accompanying file directory
        if data_config["data_and_directories"][
                "newData"] == False and previous_data_name == False:
            print(
                '\nyou need to input a directory for the chosen file dummboy')
            sys.exit(2)

        #creating a very specific directory
        temp_dir = ''
        for currency in data_config["data_information"]["currencies"].split(
                ','):
            temp_dir = temp_dir + '_' + tickDir(currency)

        #get data for all specified tickers. NOTE as is, this will only create a df as long as the shortest time series
        if data_config["data_and_directories"]["newData"] == False:
            full_df = dePickler(data_directory + previous_data_name)
            temp_dir = 'period_' + str(period) + '_pulledAt_' + str(
                time.time())[:10] + '_' + temp_dir + '_' + str(
                    full_df.index.values[-1]).replace('.', '').replace(
                        ':', '').replace(':', '') + '_to_' + str(
                            full_df.index.values[0]).replace('.', '').replace(
                                ':', '').replace(':', '') + '.pickle'

        else:
            dataObj = GetData(
                exchange=data_config["data_information"]["exchange"],
                directory=data_directory,
                period=data_config["data_information"]["period"],
                asset_type=data_config["data_information"]["asset_type"],
                newdata=data_config["data_and_directories"]["newData"])
            full_df = None

            #for each currency, fetch the time series and create a full dataframe
            for currency in data_config["data_information"][
                    "currencies"].split(','):
                data = dataObj.fetch(currency)

                #make the df include seperate names for open high low and close
                for label in ['Close', 'Open', 'High', 'Low', 'Volume']:
                    if full_df is None:
                        full_df = pd.DataFrame(data[label])
                        full_df.columns = [currency + '_' + label]
                    else:
                        full_df[currency + '_' + label] = data[label]

            temp_dir = 'period_' + str(period) + '_pulledAt_' + str(
                time.time())[:10] + '_' + temp_dir + '_' + str(
                    full_df.index.values[-1]).replace('.', '').replace(
                        ':', '').replace(':', '') + '_to_' + str(
                            full_df.index.values[0]).replace('.', '').replace(
                                ':', '').replace(':', '') + '.pickle'

        #create features for all of the data and save
        print('Creating Features')
        mlObj = MLstrategy(data=full_df,
                           currencies=data_config["data_information"]
                           ["currencies"].split(','),
                           model_directory=main_src_directory + 'models/',
                           pip=pip)

        #if we're not collecting new data, then no need to create new data. Otherwise, create new features
        if data_config["data_and_directories"]["newData"] == False:
            df = full_df
        else:
            df = mlObj.preprocessIndicators(
                forecastLen=data_config["data_information"]["forecastLen"])
            pickler(data_directory + 'INDICATORS_ADDED_' + temp_dir, df)

        print(full_df)
        return full_df
コード例 #4
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)
コード例 #5
0
ファイル: main.py プロジェクト: lotus321/Project-Portfolio
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()