Пример #1
0
    def get_symbols_in_sublist(self, subdir):
        '''
        @summary: Returns all the symbols belonging to that subdir of the data store.
        @param subdir: Specifies which subdir you want.
        @return: A list of symbols belonging to that subdir
        '''

        pathtolook = self.rootdir + self.midPath + subdir
        stocksAtThisPath = cached_listdir(pathtolook)

        #Next, throw away everything that is not a .pkl And these are our stocks!
        try:
            stocksAtThisPath = [
                x for x in stocksAtThisPath
                if (str(x).find(str(self.fileExtensionToRemove)) > -1)
            ]
            #Now, we remove the .pkl to get the name of the stock
            stocksAtThisPath = [
                (x.partition(str(self.fileExtensionToRemove))[0])
                for x in stocksAtThisPath
            ]
        except:
            print("error: no path to " + subdir)
            stocksAtThisPath = list()

        return stocksAtThisPath
Пример #2
0
    def getPathOfFile(self, symbol_name, bDelisted=False):
        '''
        @summary: Since a given pkl file can exist in any of the folders- we need to look for it in each one until we find it. Thats what this function does.
        @return: Complete path to the pkl file including the file name and extension
        '''

        if not bDelisted:
            for path1 in self.folderList:
                if (os.path.exists(str(path1) + str(symbol_name + ".pkl"))):
                    # Yay! We found it!
                    return (str(str(path1) + str(symbol_name) + ".pkl"))
                    #if ends
                elif (os.path.exists(str(path1) + str(symbol_name + ".csv"))):
                    # Yay! We found it!
                    return (str(str(path1) + str(symbol_name) + ".csv"))
                #for ends

        else:
            ''' Special case for delisted securities '''
            lsPaths = []
            for sPath in self.folderList:
                if re.search('Delisted Securities', sPath) == None:
                    continue

                for sFile in cached_listdir(sPath):
                    if not re.match('%s-\d*.pkl' % symbol_name, sFile) == None:
                        lsPaths.append(sPath + sFile)

            lsPaths.sort()
            return lsPaths

        print("Did not find path to " + str(symbol_name) +
              ". Looks like this file is missing")
Пример #3
0
    def get_all_symbols(self):
        '''
        @summary: Returns a list of all the symbols located at any of the paths for this source. @see: {__init__}
        @attention: This will discard all files that are not of type pkl. ie. Only the files with an extension pkl will be reported.
        '''

        listOfStocks = list()
        #Path does not exist

        if (len(self.folderList) == 0):
            raise ValueError("DataAccess source not set")

        for path in self.folderList:
            stocksAtThisPath = list()
            #print str(path)
            stocksAtThisPath = cached_listdir(str(path))
            #Next, throw away everything that is not a .pkl And these are our stocks!
            stocksAtThisPath = [
                x for x in stocksAtThisPath
                if (str(x).find(str(self.fileExtensionToRemove)) > -1)
            ]
            #Now, we remove the .pkl to get the name of the stock
            stocksAtThisPath = [
                (x.partition(str(self.fileExtensionToRemove))[0])
                for x in stocksAtThisPath
            ]

            listOfStocks.extend(stocksAtThisPath)
            #for stock in stocksAtThisPath:
            #listOfStocks.append(stock)
        return listOfStocks
def getStocks(listOfPaths):

    listOfStocks = list()
    #Path does not exist
    print("Reading in all stock names...")
    fileExtensionToRemove = ".h5"

    for path in listOfPaths:
        stocksAtThisPath = list()

        stocksAtThisPath = cached_listdir(str(path))
        #Next, throw away everything that is not a .h5 And these are our stocks!
        stocksAtThisPath = [
            x for x in stocksAtThisPath
            if (str(x).find(str(fileExtensionToRemove)) > -1)
        ]
        #Now, we remove the .h5 to get the name of the stock
        stocksAtThisPath = [(x.partition(str(fileExtensionToRemove))[0])
                            for x in stocksAtThisPath]

        for stock in stocksAtThisPath:
            listOfStocks.append(stock)
        return listOfStocks