Пример #1
0
 def prep(*ini_list) :
     ini_list = filter(lambda x : "benchmark" in x , ini_list)
     print (ini_list)
     for path, section, key, stock_list in INI_READ.read(*ini_list) :
         if section == 'Index' : pass
         else : continue
         yield key, stock_list
Пример #2
0
 def prep(*ini_list):
     for path, section, key, value in INI.read(*ini_list):
         if 'Industry' not in section: continue
         if 'Gas' not in key: continue
         if 'Util' not in key: continue
         break
     return value[:2]
Пример #3
0
 def read(cls, *path_of_interest):
     ini_list = cls.config_list
     if len(path_of_interest) > 0:
         ini_list = filter(lambda x: x in path_of_interest, ini_list)
         ini_list = list(ini_list)
     logging.info("loading results {}".format(ini_list))
     for path, section, key, value in INI_READ.read(*ini_list):
         logging.debug((path, section, key, value))
         yield path, section, key, value
Пример #4
0
 def config(cls):
     ini_list = cls.instance().input_file
     logging.info('Reading input file {}'.format(ini_list))
     ret = {}
     for path, section, key, value_list in INI_READ.read(*[ini_list]):
         if section not in ret:
             ret[section] = {}
         ret[section][key] = value_list
     return ret
Пример #5
0
def enrich_background(sector_file, background, entity='stock'):
    logging.info('reading file {}'.format(sector_file))
    ret = {}
    for path, section, key, ticker_list in INI_READ.read(*[sector_file]):
        for ticker in ticker_list:
            name = background.get(ticker, {})
            name = name.get('Security Name', '')
            ret[ticker] = {'SECTOR': key, 'NAME': name, 'ENTITY': entity}
    return ret
    def merge(cls):
        ret = DICT_HELPER.init()
        logging.info('loading config files {}'.format(VARIABLES().draft))
        for path, section, key, stock in INI_READ.read(*[VARIABLES().draft]):
            ret.append(key, *stock)
        for omit in VARIABLES().omit_list:
            ret.data.pop(omit, None)

        stock_list = ret.values()
        return ret.data, stock_list
Пример #7
0
 def readPortfolio(cls) :
     portfolio = VARIABLES().input_file
     logging.info('reading file {}'.format(portfolio))
     ret = {}
     for path, section, key, weight in INI_READ.read(*[portfolio]) :
         if section.startswith('dep_') :
            continue
         if section not in ret :
            ret[section] = {}
         ret[section][key] = float(weight[0])
     return ret
Пример #8
0
 def background(cls,background_files) :
     logging.info('reading file {}'.format(background_files))
     ret = {}
     for path, key, stock, value in INI_READ.read(*background_files) :
         if "File Creation Time" in stock :
            continue
         if stock not in ret :
            ret[stock] = {}
         value = ', '.join(value)
         ret[stock][key] = value
     return ret
Пример #9
0
 def read(cls):
     logging.info('reading file {}'.format(cls.config_file))
     ret = {}
     for path, section, stock_sector, stock_list in INI_READ.read(
             *[cls.config_file]):
         if section not in ret:
             ret[section] = {}
         ret[section][stock_sector] = stock_list
     target = 'MERGED'
     ret = ret.get(target, ret)
     stock_list = cls.flatten(ret.values())
     return ret, stock_list
Пример #10
0
def init(*ini_list):
    performers = {}
    stability = {}
    for file_name, name, key, value in READ.read(*ini_list):
        config = None
        if name == "Stability":
            config = stability
        if name == "Performance":
            config = performers
        config[key] = value
    ret = performers.get('Q1234', [])
    return ret
Пример #11
0
 def read(cls) :
     benchmark = VARIABLES().benchmark
     logging.info('reading file {}'.format(benchmark))
     ret = {}
     for path, section, key, stock_list in INI_READ.read(*benchmark) :
         #if section not in ['MOTLEYFOOL', 'Index'] : continue
         if section not in ['PERSONAL', 'Index'] : continue
         if section == 'MOTLEYFOOL' :
            if 'NASDAQ' not in key : continue
            if 'FUND' not in key : continue
         if section == 'Index' :
            if '500' not in key : continue
         ret[key] = stock_list
     logging.debug(ret)
     return ret
Пример #12
0
    def background(cls):
        load_file = cls.instance().background
        if not (cls._background_cache is None):
            logging.info('reading cache {}'.format(load_file))
            return cls._background_cache
        logging.info('reading file {}'.format(load_file))
        ret = {}
        for path, key, stock, value in INI_READ.read(*load_file):
            if "File Creation Time" in stock:
                continue
            if stock not in ret:
                ret[stock] = {}
            if key in cls._floats_in_summary:
                value = float(value[0])
            else:
                value = ', '.join(value)
            ret[stock][key] = value

        load_file = cls.instance().sector
        logging.info('reading file {}'.format(load_file))
        for path, section, key, ticker_list in INI_READ.read(*load_file):
            entity = 'stock'
            if 'fund' in path:
                key = '{} ({})'.format(section, key)
                entity = 'fund'
            for ticker in ticker_list:
                if ticker not in ret:
                    ret[ticker] = {}
                ret[ticker]['SECTOR'] = key
                ret[ticker]['ENTITY'] = entity

        ret = pd.DataFrame(ret).T
        ret['SECTOR'] = ret['SECTOR'].fillna("Unknown")
        ret['NAME'] = ret['NAME'].fillna("Unavailable")
        ret.fillna(0.0, inplace=True)
        return ret
Пример #13
0
 def _readSector(cls) :
     load_file = VARIABLES().category
     if not (cls._cache is None) :
        logging.debug('reading cache {}'.format(load_file))
        return cls._cache
     logging.info('reading file {}'.format(load_file))
     ret = {}
     for path, section, key, ticker_list in INI_READ.read(*load_file) :
         if 'fund' in path :
            key = '{} ({})'.format(section,key)
         for ticker in ticker_list :
             if ticker not in ret : 
                ret[ticker] = {}
             ret[ticker]['Sector'] = key
     cls._cache = ret
     return ret
Пример #14
0
 def read(cls) :
     load_file = cls.category
     if not (cls._cache is None) :
        return cls._cache
     logging.info('reading file {}'.format(load_file))
     ret = {}
     for path, section, key, ticker_list in INI_READ.read(*load_file) :
         entity = 'Stock'
         if 'fund' in path :
            key = '{} ({})'.format(section,key)
            entity = 'Fund'
         for ticker in ticker_list :
             if ticker not in ret :
                ret[ticker] = {}
             ret[ticker]['SECTOR'] = key
             ret[ticker]['ENTITY'] = entity
     ret = pd.DataFrame(ret).T
     logging.info(ret)
     cls._cache = ret
     return ret
Пример #15
0
 def read(cls) :
     load_file = cls.background
     if not (cls._background_cache is None) :
        logging.info('reading cache {}'.format(load_file))
        return cls._background_cache
     logging.info('reading file {}'.format(load_file))
     ret = {}
     for path, key, stock, value in INI_READ.read(*load_file) :
         if "File Creation Time" in stock :
             continue
         if stock not in ret :
            ret[stock] = {}
         if key in cls._floats_in_summary :
            if '=' in value[0] :
               value = [0]
            value = float(value[0])
         else :
            value = ', '.join(value)
         ret[stock][key] = value
     ret = pd.DataFrame(ret).T
     cls._background_cache = ret
     return ret
Пример #16
0
 def test_03_read(self) :
     target = 'test_ini_input_file'
     ini_list = globals().get(target,[])
     count = 12
     for a,b,c,d in READ.read(*ini_list) :
         if b.startswith('dep_') :
             continue
         if c.startswith('sharpe') :
             continue
         if c.startswith('risk') :
             continue
         if c.startswith('return') :
             continue
         logging.debug((a,b,c,d))
         self.assertIsInstance(a,str)
         self.assertIsInstance(b,str)
         self.assertIsInstance(c,str)
         if 'dictionary' in c :
            self.assertIsInstance(d,dict)
         else :
            self.assertIsInstance(d,list)
         count -= 1
         if count == 0 : break
Пример #17
0
def _get_config(config):
    logging.info("loading results {}".format(config))
    for path, section, key, stock_list in INI_READ.read(*config):
        yield path, section, key, stock_list
Пример #18
0
 def dep_config():
     ini_list = EXTRACT.instance().config_list
     logging.info("loading results {}".format(ini_list))
     for path, section, key, stock_list in INI_READ.read(*ini_list):
         yield path, section, key, stock_list