Esempio n. 1
0
    def _getDatas(self):
        combIndex = None
        for s in self.symbolList:
            self.symbolData[s] = web.get_data_yahoo(
                s,
                start=self.startDate.strftime("%Y%m%d"),
                end=self.endDate.strftime("%Y%m%d"),
                adjust_price=True).sort_index()
            del self.symbolData[s]['Adj_Ratio']
            self.symbolData[s].columns = [
                'open', 'high', 'low', 'close', 'volume'
            ]

            if combIndex is None:
                combIndex = self.symbolData[s].index
            else:
                combIndex = combIndex.union(self.symbolData[s].index)

            self.latestSymbolData[s] = []
            self.symbolData[s] = transfromDFtoDict(self.symbolData[s])

        self.dateIndex = combIndex
        self.start = 0
        for i, s in enumerate(self.symbolList):
            if s not in self.symbolData:
                del self.symbolList[i]
Esempio n. 2
0
    def _getDatas(self):
        self.logger.info("Start loading bars from Tushare source...")
        combIndex = None
        result = {}

        for s in self.symbolList:
            index = True if s.split('.')[1] == 'zicn' else False
            result[s] = getOneSymbolData((s, self.startDate, self.endDate,
                                          self._freq, self.priceAdj, index))
            self.logger.info(
                "Symbol {0:s} is ready for back testing.".format(s))

        for s in result:
            if not result[s].empty:
                self.symbolData[s] = result[s]
                if combIndex is None:
                    combIndex = self.symbolData[s].index
                else:
                    combIndex = combIndex.union(self.symbolData[s].index)

                self.symbolData[s] = transfromDFtoDict(self.symbolData[s])

        # transform
        self.dateIndex = combIndex
        self.start = 0
        for i, s in enumerate(self.symbolList):
            if s not in self.symbolData:
                del self.symbolList[i]

        self.logger.info("Bars loading finished!")
Esempio n. 3
0
    def _getDatas(self):

        self.logger.info("Start loading bars from DataYes source...")

        combIndex = None

        result = {}

        category = self.category(self.symbolList)

        if category['stocks']:
            for s in category['stocks']:
                result[s] = getOneSymbolData(
                    (self.mt, s, self.startDate, self.endDate))
                self.logger.info(
                    "Symbol {0:s} is ready for back testing.".format(s))

        if category['indexes']:
            for s in category['indexes']:
                result[s] = getOneSymbolIndexData(
                    (self.mt, s, self.startDate, self.endDate))
                self.logger.info(
                    "Symbol {0:s} is ready for back testing.".format(s))

        if category['futures']:
            for s in category['futures']:
                result[s] = getOneSymbolFutureData(
                    (self.mt, s, self.startDate, self.endDate))
                self.logger.info(
                    "Symbol {0:s} is ready for back testing.".format(s))

        if category['futures_con']:
            for s in category['futures_con']:
                result[s] = getOneSymbolFutureContinuesData(
                    (self.mt, s, self.startDate, self.endDate))
                self.logger.info(
                    "Symbol {0:s} is ready for back testing.".format(s))

        for s in result:
            if result[s] is not None and not result[s].empty:
                self.symbolData[s] = result[s]
                if combIndex is None:
                    combIndex = self.symbolData[s].index
                else:
                    combIndex = combIndex.union(self.symbolData[s].index)

                self.symbolData[s] = transfromDFtoDict(self.symbolData[s])

        # transform
        self.dateIndex = combIndex
        self.start = 0
        for i, s in enumerate(self.symbolList):
            if s not in self.symbolData:
                del self.symbolList[i]

        self.logger.info("Bars loading finished!")
Esempio n. 4
0
    def _getDatas(self):

        self.logger.info("Start loading bars from DataYes source...")

        combIndex = None

        result = {}

        category = self.category(self.symbolList)

        if category['stocks']:
            for s in category['stocks']:
                result[s] = getOneSymbolData((self.mt, s, self.startDate, self.endDate))
                self.logger.info("Symbol {0:s} is ready for back testing.".format(s))

        if category['indexes']:
            for s in category['indexes']:
                result[s] = getOneSymbolIndexData((self.mt, s, self.startDate, self.endDate))
                self.logger.info("Symbol {0:s} is ready for back testing.".format(s))

        if category['futures']:
            for s in category['futures']:
                result[s] = getOneSymbolFutureData((self.mt, s, self.startDate, self.endDate))
                self.logger.info("Symbol {0:s} is ready for back testing.".format(s))

        if category['futures_con']:
            for s in category['futures_con']:
                result[s] = getOneSymbolFutureContinuesData((self.mt, s, self.startDate, self.endDate))
                self.logger.info("Symbol {0:s} is ready for back testing.".format(s))

        for s in result:
            if not result[s].empty:
                self.symbolData[s] = result[s]
                if combIndex is None:
                    combIndex = self.symbolData[s].index
                else:
                    combIndex = combIndex.union(self.symbolData[s].index)

                self.symbolData[s] = transfromDFtoDict(self.symbolData[s])

        # transform
        self.dateIndex = combIndex
        self.start = 0
        for i, s in enumerate(self.symbolList):
            if s not in self.symbolData:
                del self.symbolList[i]

        self.logger.info("Bars loading finished!")
Esempio n. 5
0
    def _openConvertCSVFiles(self):
        combIndex = None
        for s in self.symbolList:
            filePath = os.path.join(self.csvDir, "{0:s}.csv".format(s))
            self.symbolData[s] = io.parsers.read_csv(filePath,
                                                     header=0,
                                                     index_col=0,
                                                     parse_dates=True)\
                .sort_index()

            if combIndex is None:
                combIndex = self.symbolData[s].index
            else:
                combIndex = combIndex.union(self.symbolData[s].index)

            self.symbolData[s] = transfromDFtoDict(self.symbolData[s])

        self.dateIndex = combIndex
        self.start = 0
Esempio n. 6
0
    def _openConvertCSVFiles(self):
        combIndex = None
        for s in self.symbolList:
            filePath = os.path.join(self.csvDir, "{0:s}.csv".format(s))
            self.symbolData[s] = io.parsers.read_csv(filePath,
                                                     header=0,
                                                     index_col=0,
                                                     parse_dates=True)\
                .sort_index()

            if combIndex is None:
                combIndex = self.symbolData[s].index
            else:
                combIndex = combIndex.union(self.symbolData[s].index)

            self.symbolData[s] = transfromDFtoDict(self.symbolData[s])

        self.dateIndex = combIndex
        self.start = 0
Esempio n. 7
0
    def _openConvertCSVFiles(self):
        combIndex = None
        for s in self.symbolList:
            filePath = os.path.join(self.csvDir, "{0:s}.csv".format(s))
            self.symbolData[s] = io.parsers.read_csv(filePath,
                                                     header=0,
                                                     index_col=0,
                                                     parse_dates=True,
                                                     usecols=['datetime', 'open', 'high', 'low', 'close', 'volume']).sort_index()

            if combIndex is None:
                combIndex = self.symbolData[s].index
            else:
                combIndex = combIndex.union(self.symbolData[s].index)

            self.latestSymbolData[s] = []
            self.symbolData[s] = transfromDFtoDict(self.symbolData[s])

        self.dateIndex = combIndex
        self.start = 0
Esempio n. 8
0
    def _openConvertCSVFiles(self):
        combIndex = None
        for s in self.symbolList:
            filePath = os.path.join(self.csvDir, "{0:s}.csv".format(s))
            self.symbolData[s] = io.parsers.read_csv(
                filePath,
                header=0,
                index_col=0,
                parse_dates=True,
                usecols=['datetime', 'open', 'high', 'low', 'close',
                         'volume']).sort_index()

            if combIndex is None:
                combIndex = self.symbolData[s].index
            else:
                combIndex = combIndex.union(self.symbolData[s].index)

            self.latestSymbolData[s] = []
            self.symbolData[s] = transfromDFtoDict(self.symbolData[s])

        self.dateIndex = combIndex
        self.start = 0
Esempio n. 9
0
    def _getDatas(self):
        combIndex = None
        for s in self.symbolList:
            self.symbolData[s] = web.get_data_yahoo(s,
                                                    start=self.startDate.strftime("%Y%m%d"),
                                                    end=self.endDate.strftime("%Y%m%d"),
                                                    adjust_price=True).sort_index()
            del self.symbolData[s]['Adj_Ratio']
            self.symbolData[s].columns = ['open', 'high', 'low', 'close', 'volume']

            if combIndex is None:
                combIndex = self.symbolData[s].index
            else:
                combIndex = combIndex.union(self.symbolData[s].index)

            self.latestSymbolData[s] = []
            self.symbolData[s] = transfromDFtoDict(self.symbolData[s])

        self.dateIndex = combIndex
        self.start = 0
        for i, s in enumerate(self.symbolList):
            if s not in self.symbolData:
                del self.symbolList[i]
Esempio n. 10
0
    def _getDatas(self):

        self.logger.info("Start loading bars from DataYes source...")

        combIndex = None

        def getOneSymbolData(params):
            mt = params[0]
            s = params[1]
            start = params[2]
            end = params[3]
            logger = params[4]
            result = params[5]
            data = mt.MktEqud(
                secID=s,
                beginDate=start,
                endDate=end,
                field=
                'tradeDate,openPrice,highestPrice,lowestPrice,turnoverVol,closePrice'
            )
            if data.empty:
                return
            data.index = pd.to_datetime(data['tradeDate'], format="%Y-%m-%d")
            data.sort_index(inplace=True)
            data.columns = [
                'tradeDate', 'open', 'high', 'low', 'volume', 'close'
            ]
            logger.info("Symbol {0:s} is ready for back testing.".format(s))
            result[s] = data

        def getOneSymbolIndeData(params):
            mt = params[0]
            s = params[1]
            start = params[2]
            end = params[3]
            logger = params[4]
            result = params[5]
            data = mt.MktIdxd(
                indexID=s,
                beginDate=start,
                endDate=end,
                field=
                'tradeDate,openIndex,highestIndex,lowestIndex,turnoverVol,closeIndex'
            )
            if data.empty:
                return
            data.index = pd.to_datetime(data['tradeDate'], format="%Y-%m-%d")
            data.sort_index(inplace=True)
            data.columns = [
                'tradeDate', 'open', 'high', 'low', 'volume', 'close'
            ]
            logger.info("Symbol {0:s} is ready for back testing.".format(s))
            result[s] = data

        def getOneSymbolFutureData(params):
            mt = params[0]
            s = params[1]
            start = params[2]
            end = params[3]
            logger = params[4]
            result = params[5]
            data = mt.MktFutd(
                ticker=s[:6],
                beginDate=start,
                endDate=end,
                field=
                'tradeDate,openPrice,highestPrice,lowestPrice,turnoverVol,closePrice'
            )
            if data.empty:
                return
            data.index = pd.to_datetime(data['tradeDate'], format="%Y-%m-%d")
            data.sort_index(inplace=True)
            data.columns = [
                'tradeDate', 'open', 'high', 'low', 'volume', 'close'
            ]
            logger.info("Symbol {0:s} is ready for back testing.".format(s))
            result[s] = data

        result = {}
        if self.category['stocks']:
            for s in self.category['stocks']:
                getOneSymbolData((self.mt, s, self.startDate, self.endDate,
                                  self.logger, result))

        if self.category['indexes']:
            for s in self.category['indexes']:
                getOneSymbolIndeData((self.mt, s, self.startDate, self.endDate,
                                      self.logger, result))

        if self.category['futures']:
            for s in self.category['futures']:
                getOneSymbolFutureData((self.mt, s, self.startDate,
                                        self.endDate, self.logger, result))

        for s in result:
            self.symbolData[s] = result[s]
            if combIndex is None:
                combIndex = self.symbolData[s].index
            else:
                combIndex = combIndex.union(self.symbolData[s].index)

            self.symbolData[s] = transfromDFtoDict(self.symbolData[s])

            # transform

        self.dateIndex = combIndex
        self.start = 0
        for i, s in enumerate(self.symbolList):
            if s not in self.symbolData:
                del self.symbolList[i]

        self.logger.info("Bars loading finished!")
Esempio n. 11
0
    def _getDatas(self):

        self.logger.info("Start loading bars from DataYes source...")

        combIndex = None

        def getOneSymbolData(params):
            mt = params[0]
            s = params[1]
            start = params[2]
            end = params[3]
            logger = params[4]
            result = params[5]
            data = mt.MktEqud(secID=s,
                              beginDate=start,
                              endDate=end,
                              field='tradeDate,openPrice,highestPrice,lowestPrice,turnoverVol,closePrice')
            if data.empty:
                return
            data.index = pd.to_datetime(data['tradeDate'], format="%Y-%m-%d")
            data.sort_index(inplace=True)
            data.columns = ['tradeDate', 'open', 'high', 'low', 'volume', 'close']
            logger.info("Symbol {0:s} is ready for back testing.".format(s))
            result[s] = data

        def getOneSymbolIndeData(params):
            mt = params[0]
            s = params[1]
            start = params[2]
            end = params[3]
            logger = params[4]
            result = params[5]
            data = mt.MktIdxd(indexID=s,
                              beginDate=start,
                              endDate=end,
                              field='tradeDate,openIndex,highestIndex,lowestIndex,turnoverVol,closeIndex')
            if data.empty:
                return
            data.index = pd.to_datetime(data['tradeDate'], format="%Y-%m-%d")
            data.sort_index(inplace=True)
            data.columns = ['tradeDate', 'open', 'high', 'low', 'volume', 'close']
            logger.info("Symbol {0:s} is ready for back testing.".format(s))
            result[s] = data

        def getOneSymbolFutureData(params):
            mt = params[0]
            s = params[1]
            start = params[2]
            end = params[3]
            logger = params[4]
            result = params[5]
            data = mt.MktFutd(ticker=s[:6],
                              beginDate=start,
                              endDate=end,
                              field='tradeDate,openPrice,highestPrice,lowestPrice,turnoverVol,closePrice')
            if data.empty:
                return
            data.index = pd.to_datetime(data['tradeDate'], format="%Y-%m-%d")
            data.sort_index(inplace=True)
            data.columns = ['tradeDate', 'open', 'high', 'low', 'volume', 'close']
            logger.info("Symbol {0:s} is ready for back testing.".format(s))
            result[s] = data

        result = {}
        if self.category['stocks']:
            for s in self.category['stocks']:
                getOneSymbolData((self.mt, s, self.startDate, self.endDate, self.logger, result))

        if self.category['indexes']:
            for s in self.category['indexes']:
                getOneSymbolIndeData((self.mt, s, self.startDate, self.endDate, self.logger, result))

        if self.category['futures']:
            for s in self.category['futures']:
                getOneSymbolFutureData((self.mt, s, self.startDate, self.endDate, self.logger, result))

        for s in result:
            self.symbolData[s] = result[s]
            if combIndex is None:
                combIndex = self.symbolData[s].index
            else:
                combIndex = combIndex.union(self.symbolData[s].index)

            self.symbolData[s] = transfromDFtoDict(self.symbolData[s])

            # transform

        self.dateIndex = combIndex
        self.start = 0
        for i, s in enumerate(self.symbolList):
            if s not in self.symbolData:
                del self.symbolList[i]

        self.logger.info("Bars loading finished!")