Qstkutil.DataAccess

From Quantwiki
Jump to: navigation, search

What Directory does DataAccess read from

We use default data in the class to maintain consistency in the class and to make sure everyone gets the same values and answers. As market adjusted data changes everyday.

There should be a directory named Yahoo in your s_datapath at the end of the code attached below.

1. If environment variable named QSDATA and QSSCRATCH are defined, then these will be used as the data and temp directory respectively.

2. If the variables are not defined but s_datapath and s_scratchpath are passed in the initialization of the DataAccess class, then these paths are used to access the data directory. Please note that the paths declared here are absolute paths from the root.

3. If none of the two are followed then it'll use the default data that comes with the installation.

    def __init__(self, sourcein=DataSource.YAHOO, s_datapath=None,
                 s_scratchpath=None, cachestalltime=12):
        '''
        @param sourcestr: Specifies the source of the data. Initializes paths based on source.
        @note: No data is actually read in the constructor. Only paths for the source are initialized
        @param: Scratch defaults to a directory in /tmp/QSScratch
        '''
        try:
            self.rootdir = os.environ['QSDATA']
            try:
                self.scratchdir = os.environ['QSSCRATCH']
            except:
                self.scratchdir = os.path.join(tempfile.gettempdir(), 'QSScratch')
        except:
            if s_datapath != None:
                self.rootdir = s_datapath
                if s_scratchpath != None:
                    self.scratchdir = s_scratchpath
                else:
                    self.scratchdir = os.path.join(tempfile.gettempdir(), 'QSScratch')
            else:
                self.rootdir = os.path.join(os.path.dirname(__file__), '..', 'QSData')
                self.scratchdir = os.path.join(tempfile.gettempdir(), 'QSScratch')

        print "Scratch Directory: ", self.scratchdir
        print "Data Directory: ", self.rootdir
Personal tools