def FormatDataTwapPortfolio(self, portfolio_obj, portfolio_data_list):
        common_functions_obj = CCommonFunctions()
        portfolio_obj.m_strScripName = portfolio_data_list[0]['ScripName']
        temp_date = portfolio_data_list[0]['DateTime'].date()
        temp_date = str(temp_date.day) + '-' + str(temp_date.month) + '-' + str(temp_date.year)
        print "temp date :" + str(temp_date)
        for portfolio_data in portfolio_data_list:
            portfolio_obj.m_nCountOfRows += 1
            portfolio_obj.m_DatetimeList.append(portfolio_data['DateTime'])
            portfolio_obj.m_strOrderIDList.append(portfolio_data['OrderID'])
            portfolio_obj.m_strStatusList.append(portfolio_data['Status'])
            portfolio_obj.m_nOrderQtyList.append(portfolio_data['OrderQty'])
            portfolio_obj.m_fOrderPriceList.append(portfolio_data['OrderPrice'])
            portfolio_obj.m_strSideList.append(portfolio_data['Side'])
            portfolio_obj.m_nFilledSizeList.append(portfolio_data['FilledSize'])
            portfolio_obj.m_fAvgPriceList.append(portfolio_data['AvgPrice'])
            portfolio_obj.m_fPriceList.append(portfolio_data['Price'])
            portfolio_obj.m_nSizeList.append(portfolio_data['Size'])
            
            if portfolio_data['Status'].upper() == 'COMPLETE':
                portfolio_obj.m_OrderCompleteDatetimeList.append(portfolio_data['DateTime'])
                portfolio_obj.m_fOrderCompleteAvgPriceList.append(portfolio_data['AvgPrice'])
            
            if not (portfolio_data['Price'].upper() == 'NULL' or portfolio_data['Price'].upper() == 'NONE'):
                portfolio_obj.m_OrderExecutionDatetimeList.append(portfolio_data['DateTime'])
                portfolio_obj.m_fOrderExecutionFillPriceList.append(portfolio_data['Price'])
        
        portfolio_obj.m_strTimeWindowList     = common_functions_obj.GetDateTimeList(temp_date, common_functions_obj.GetWindowList(self.m_nWindowSize)[0])
        portfolio_obj.m_strTimeWindowPlotList = common_functions_obj.GetDateTimeList(temp_date, common_functions_obj.GetWindowList(self.m_nWindowSize)[1])
        print "displaying portfolio timw window list"
        for iter in range(0, len(portfolio_obj.m_strTimeWindowList)):
            print str(portfolio_obj.m_strTimeWindowList[iter])  +"\t" + str(portfolio_obj.m_strTimeWindowPlotList[iter])
        print "end of display"

        return True
예제 #2
0
    def GetStrategyList(self, strategy_log_obj, portfolio_twap_obj):
        index_strategy = 0
        index_portfolio = 0
        common_functions_obj = CCommonFunctions()

        while index_strategy < strategy_log_obj.m_nCountOfRows and index_portfolio < len(
                portfolio_twap_obj.m_fOrderExecutionFillPriceList):
            if common_functions_obj.CompareTime(
                    strategy_log_obj.m_DatetimeList[index_strategy],
                    portfolio_twap_obj.m_DatetimeList[index_portfolio]) == -1:
                index_strategy += 1

            elif common_functions_obj.CompareTime(
                    strategy_log_obj.m_DatetimeList[index_strategy],
                    portfolio_twap_obj.m_DatetimeList[index_portfolio]
            ) == 0 or common_functions_obj.CompareTime(
                    strategy_log_obj.m_DatetimeList[index_strategy],
                    portfolio_twap_obj.m_DatetimeList[index_portfolio]) == 1:
                strategy_log_obj.m_strStrategyExecutionList.append(
                    strategy_log_obj.m_strStrategyList[index_strategy - 1])
                index_portfolio += 1

        # print "displaying Strategy execution list"
        # for iter in range(0, len(strategy_log_obj.m_strStrategyExecutionList)):
        #     print str(strategy_log_obj.m_strStrategyExecutionList[iter])
        return True
예제 #3
0
    def GetVwapWindow(self, data_object, list_index, time_window_index):
        common_functions_obj = CCommonFunctions()
        temp_vol = 0
        temp_vwap = 0

        while common_functions_obj.CompareTime(
                data_object.m_DatetimeList[list_index],
                data_object.m_strTimeWindowList[time_window_index]) == -1:
            if not data_object.m_nSizeList[list_index] == "NULL":
                temp_vol = temp_vol + float(
                    data_object.m_nSizeList[list_index])
                temp_vwap = temp_vwap + float(
                    data_object.m_nSizeList[list_index]) * float(
                        data_object.m_fPriceList[list_index])

            list_index += 1

            if list_index >= len(data_object.m_nSizeList):
                break

        if not temp_vol == 0:
            temp_vwap = temp_vwap / temp_vol
            data_object.m_fVwapWindowList.append(temp_vwap)

        return list_index
예제 #4
0
    def GetDataMarket(self, market_obj, path, date, scrip, windowInterval):
        common_functions_obj = CCommonFunctions()
        filename = path + '/' + common_functions_obj.FormatDate(
            date) + '/' + scrip.replace(
                ':', '') + '_' + common_functions_obj.FormatDate(
                    date) + '_trades.csv'
        with open(filename, 'rb') as marketTrade_file_obj:
            marketTrade_file_contents = csv.reader(marketTrade_file_obj)
            market_obj.m_strScripName = scrip

            for row in marketTrade_file_contents:
                if row[0].strip() == scrip:
                    market_obj.m_nCountOfRows += 1
                    market_obj.m_DatetimeList.append(
                        common_functions_obj.GetDateTime(
                            row[2].strip(), row[3].strip()))
                    market_obj.m_fPriceList.append(float(row[4].strip()))
                    market_obj.m_nSizeList.append(int(row[5].strip()))
            market_obj.m_strTimeWindowList = common_functions_obj.GetDateTimeList(
                date,
                common_functions_obj.GetWindowList(windowInterval)[0])
            market_obj.m_strTimeWindowPlotList = common_functions_obj.GetDateTimeList(
                date,
                common_functions_obj.GetWindowList(windowInterval)[1])
            CCommonFunctions.total_daily_market_volume = sum(
                market_obj.m_nSizeList)
        return True
 def FormatDataPredicted(self, predicted_obj, predicted_data_list): 
     common_functions_obj = CCommonFunctions()
     temp_date = predicted_data_list[0]['DateTime'].date()
     temp_date = str(temp_date.day) + '-' + str(temp_date.month) + '-' + str(temp_date.year)
     
     for predicted_data in predicted_data_list:
         predicted_obj.m_nCountOfRows += 1
         predicted_obj.m_DatetimeList.append(predicted_data['DateTime'])
         predicted_obj.m_nSizeList.append(predicted_data['Size'])
     predicted_obj.m_strTimeWindowList     = common_functions_obj.GetDateTimeList(temp_date, common_functions_obj.GetWindowList(self.m_nWindowSize)[0])
     predicted_obj.m_strTimeWindowPlotList = common_functions_obj.GetDateTimeList(temp_date, common_functions_obj.GetWindowList(self.m_nWindowSize)[1])
     return True
 def FormatDataFuture(self, future_obj, future_data_list):
     common_functions_obj = CCommonFunctions()
     temp_date = future_data_list[0]['DateTime'].date()
     temp_date = str(temp_date.day) + '-' + str(temp_date.month) + '-' + str(temp_date.year)
     future_obj.m_strScripName = future_data_list[0]['ScripName']
     
     for future_data in future_data_list:
         future_obj.m_nCountOfRows += 1
         future_obj.m_DatetimeList.append(future_data['DateTime'])
         future_obj.m_fPriceList.append(future_data['Price'])
     future_obj.m_strTimeWindowList     = common_functions_obj.GetDateTimeList(temp_date, common_functions_obj.GetWindowList(self.m_nWindowSize)[0])
     future_obj.m_strTimeWindowPlotList = common_functions_obj.GetDateTimeList(temp_date, common_functions_obj.GetWindowList(self.m_nWindowSize)[1])
     return True
 def FormatDataMarket(self, market_obj, market_data_list):
     common_functions_obj = CCommonFunctions()
     market_obj.m_strScripName = market_data_list[0]['ScripName']
     temp_date = market_data_list[0]['DateTime'].date()
     temp_date = str(temp_date.day) + '-' + str(temp_date.month) + '-' + str(temp_date.year)
     for market_data in market_data_list:
         market_obj.m_nCountOfRows += 1
         market_obj.m_DatetimeList.append(market_data['DateTime'])
         market_obj.m_fPriceList.append(market_data['Price'])
         market_obj.m_nSizeList.append(market_data['Size'])
     market_obj.m_strTimeWindowList     = common_functions_obj.GetDateTimeList(temp_date, common_functions_obj.GetWindowList(self.m_nWindowSize)[0])
     market_obj.m_strTimeWindowPlotList = common_functions_obj.GetDateTimeList(temp_date, common_functions_obj.GetWindowList(self.m_nWindowSize)[1])
     CCommonFunctions.total_daily_market_volume = sum(market_obj.m_nSizeList)
     return True
예제 #8
0
    def GetVolWindow(self, data_object, list_index, time_window_index):
        common_functions_obj = CCommonFunctions()
        temp_vol = 0

        while common_functions_obj.CompareTime(
                data_object.m_DatetimeList[list_index],
                data_object.m_strTimeWindowList[time_window_index]) == -1:
            if not data_object.m_nSizeList[list_index] == "NULL":
                temp_vol = temp_vol + float(
                    data_object.m_nSizeList[list_index])

            list_index += 1

            if list_index >= len(data_object.m_nSizeList):
                break

        data_object.m_nVolumeWindowList.append(temp_vol)

        return list_index
예제 #9
0
    def GetDataStrategyLogs(self, strategy_log_obj, path, date, filename):
        common_functions_obj = CCommonFunctions()
        filename = path + '/' + common_functions_obj.FormatDate(
            date) + '/' + filename
        strategy_logs_file_obj = open(filename)
        strategy_logs_file_contents = strategy_logs_file_obj.read().split('\n')

        utils_ntwap_obj = CUtilsNtwap()
        for row in strategy_logs_file_contents:
            row = utils_ntwap_obj.FormatRow(row)

            if len(row) > 0 and not utils_ntwap_obj.GetPrice(row) == 'nan':
                temp_timestamp = utils_ntwap_obj.GetTimeStamp(row)
                temp_price = utils_ntwap_obj.GetPrice(row)
                temp_strategy = utils_ntwap_obj.GetStrategy(row)
                strategy_log_obj.m_nCountOfRows += 1
                strategy_log_obj.m_DatetimeList.append(
                    common_functions_obj.GetDateTimeStrategyLog(
                        date, temp_timestamp))
                strategy_log_obj.m_fPriceList.append(float(temp_price))
                strategy_log_obj.m_strStrategyList.append(temp_strategy)
        return True
예제 #10
0
    def GetStrategyList(self, strategy_log_obj, portfolio_twap_obj):
        index_strategy = 0
        index_portfolio = 0
        common_functions_obj = CCommonFunctions()

        while index_strategy < strategy_log_obj.m_nCountOfRows and index_portfolio < len(
                portfolio_twap_obj.m_fOrderExecutionFillPriceList):
            if common_functions_obj.CompareTime(
                    strategy_log_obj.m_DatetimeList[index_strategy],
                    portfolio_twap_obj.m_DatetimeList[index_portfolio]) == -1:
                index_strategy += 1

            elif common_functions_obj.CompareTime(
                    strategy_log_obj.m_DatetimeList[index_strategy],
                    portfolio_twap_obj.m_DatetimeList[index_portfolio]
            ) == 0 or common_functions_obj.CompareTime(
                    strategy_log_obj.m_DatetimeList[index_strategy],
                    portfolio_twap_obj.m_DatetimeList[index_portfolio]) == 1:
                strategy_log_obj.m_strStrategyExecutionList.append(
                    strategy_log_obj.m_strStrategyList[index_strategy - 1])
                index_portfolio += 1
        return True
예제 #11
0
 def GetDataCash(self, cash_obj, path, date, scrip, windowInterval):
     common_functions_obj = CCommonFunctions()
     filename = path + '/' + common_functions_obj.FormatDate(
         date) + '/' + scrip + '_' + common_functions_obj.FormatDate(
             date) + '_trades.csv'
     with open(filename, 'rb') as cash_file_obj:
         cash_file_contents = csv.reader(cash_file_obj)
         cash_obj.m_strScripName = scrip
         for row in cash_file_contents:
             if row[0].strip() == scrip:
                 cash_obj.m_nCountOfRows += 1
                 cash_obj.m_DatetimeList.append(
                     common_functions_obj.GetDateTime(
                         row[2].strip(), row[3].strip()))
                 cash_obj.m_fPriceList.append(float(row[4].strip()))
         cash_obj.m_strTimeWindowList = common_functions_obj.GetDateTimeList(
             date,
             common_functions_obj.GetWindowList(windowInterval)[0])
         cash_obj.m_strTimeWindowPlotList = common_functions_obj.GetDateTimeList(
             date,
             common_functions_obj.GetWindowList(windowInterval)[1])
     return True
예제 #12
0
    def GetDataPredicted(self, predicted_obj, path, date, scrip,
                         windowInterval):
        common_functions_obj = CCommonFunctions()
        filename = path + '/' + common_functions_obj.FormatDate(
            date) + '/' + scrip.replace(':', '') + '.csv'
        with open(filename, 'rb') as predicted_file_obj:
            predicted_file_contents = csv.reader(predicted_file_obj)
            predicted_obj.m_strScripName = scrip

            for row in predicted_file_contents:
                predicted_obj.m_nCountOfRows += 1
                predicted_obj.m_DatetimeList.append(
                    common_functions_obj.GetDateTime(
                        date, common_functions_obj.FormatTime(row[0].strip())))
                predicted_obj.m_nSizeList.append(float(row[1].strip()))
            predicted_obj.m_strTimeWindowList = common_functions_obj.GetDateTimeList(
                date,
                common_functions_obj.GetWindowList(windowInterval)[0])
            predicted_obj.m_strTimeWindowPlotList = common_functions_obj.GetDateTimeList(
                date,
                common_functions_obj.GetWindowList(windowInterval)[1])
        return True
예제 #13
0
    def GetDataTwapPortfolio(self, portfolio_twap_obj, path, input_date,
                             filename, scrip, windowInterval):
        common_functions_obj = CCommonFunctions()
        filename = path + '/' + common_functions_obj.FormatDate(
            input_date) + '/' + filename
        with open(filename, 'rb') as portfolio_file_obj:
            portfolio_file_contents = csv.reader(portfolio_file_obj)
            portfolio_twap_obj.m_strScripName = scrip

            for row in portfolio_file_contents:
                if row[1].strip() == scrip:
                    temp_datetime = row[0].strip().split(' ')
                    date = temp_datetime[0]
                    time = temp_datetime[1]
                    portfolio_twap_obj.m_nCountOfRows += 1
                    portfolio_twap_obj.m_DatetimeList.append(
                        common_functions_obj.GetDateTimePortfolio(date, time))
                    portfolio_twap_obj.m_strOrderIDList.append(row[2].strip())
                    portfolio_twap_obj.m_strStatusList.append(row[3].strip())
                    portfolio_twap_obj.m_nOrderQtyList.append(
                        int(row[4].strip()))
                    portfolio_twap_obj.m_fOrderPriceList.append(
                        float(row[5].strip()))
                    portfolio_twap_obj.m_strSideList.append(row[6].strip())
                    portfolio_twap_obj.m_nFilledSizeList.append(row[7].strip())
                    portfolio_twap_obj.m_fAvgPriceList.append(row[8].strip())
                    portfolio_twap_obj.m_fPriceList.append(row[9].strip())
                    portfolio_twap_obj.m_nSizeList.append(row[10].strip())
                    portfolio_twap_obj.m_FillDateTimeList.append(
                        common_functions_obj.GetDateTimePortfolio(date, time))

                    if row[3].strip().upper() == 'COMPLETE':
                        portfolio_twap_obj.m_OrderCompleteDatetimeList.append(
                            common_functions_obj.GetDateTimePortfolio(
                                date, time))
                        portfolio_twap_obj.m_fOrderCompleteAvgPriceList.append(
                            row[8].strip())

                    if not row[9].strip().upper() == 'NONE':
                        portfolio_twap_obj.m_OrderExecutionDatetimeList.append(
                            common_functions_obj.GetDateTimePortfolio(
                                date, time))
                        portfolio_twap_obj.m_fOrderExecutionFillPriceList.append(
                            row[9].strip())

            portfolio_twap_obj.m_strTimeWindowList = common_functions_obj.GetDateTimeList(
                input_date,
                common_functions_obj.GetWindowList(windowInterval)[0])
            portfolio_twap_obj.m_strTimeWindowPlotList = common_functions_obj.GetDateTimeList(
                input_date,
                common_functions_obj.GetWindowList(windowInterval)[1])
        return True