Пример #1
0
 def config(cls, save_file, **config) :
     logging.info("results saved to {}".format(save_file))
     ret = INI.init()
     for key in sorted(config) :
         value = config.get(key,{})
         INI.write_section(ret,key,**value)
     ret.write(open(save_file, 'w'))
Пример #2
0
def main(save_file) : 
    ret = INI.init()
    for key, value in action() :
        logging.debug(value)
        INI.write_section(ret,key,**value)
    ret.write(open(save_file, 'w'))
    logging.info("results saved to {}".format(save_file))
Пример #3
0
def main(file_list, ini_list, save_file):
    logging.info("loading results {}".format(ini_list))
    ret = INI.init()
    for key, value in action(file_list, ini_list):
        logging.debug(value)
        INI.write_section(ret, key, **value)
    ret.write(open(save_file, 'w'))
    logging.info("results saved to {}".format(save_file))
Пример #4
0
 def background(cls, **config):
     save_file = EXTRACT.instance().background_file
     ret = INI.init()
     for key in sorted(config):
         value = config.get(key, [])
         INI.write_section(ret, key, **value)
     ret.write(open(save_file, 'w'))
     logging.info("results saved to {}".format(save_file))
Пример #5
0
 def config(cls, data):
     save_file = EXTRACT.singleton().output_file
     ret = INI.init()
     for key in sorted(data):
         logging.info(key)
         value = data[key]
         INI.write_section(ret, key, **value)
     ret.write(open(save_file, 'w'))
     logging.info('writing to file {}'.format(save_file))
Пример #6
0
 def portfolio(cls, save_file, **portfolio) :
     logging.info("saving results to file {}".format(save_file))
     ret = INI.init()
     name_list = sorted(portfolio.keys())
     value_list = map(lambda key : portfolio[key], name_list)
     for i, name in enumerate(name_list) :
         if not isinstance(value_list,list) :
            value_list = list(value_list)
         INI.write_section(ret,name,**value_list[i])
     ret.write(open(save_file, 'w'))
     logging.info("results saved to file {}".format(save_file))
Пример #7
0
 def config(cls, summary, portfolio):
     save_file = EXTRACT.instance().output_file
     ret = INI.init()
     INI.write_section(ret, "summary", **summary)
     for key in portfolio.keys():
         values = portfolio[key]
         if not isinstance(values, dict):
             values = values.to_dict()
         INI.write_section(ret, key, **values)
     ret.write(open(save_file, 'w'))
     logging.info('saving file {}'.format(save_file))
Пример #8
0
def main(local_dir) :
    for name, section_list in action() :
        output_file = "{}/portfolio_{}.ini".format(local_dir, name)
        output_file = output_file.replace(" ", "_")
        ret = INI.init()
        name_list = sorted(section_list.keys())
        value_list = map(lambda key : section_list[key], name_list)
        for i, name in enumerate(name_list) :
            if not isinstance(value_list,list) :
               value_list = list(value_list)
            INI.write_section(ret,name,**value_list[i])
        logging.info("saving results to file {}".format(output_file))
        ret.write(open(output_file, 'w'))
 def draft(cls,data) :
     save_file = EXTRACT.instance().draft
     logging.info('Loading results : {}'.format(save_file))
     config = INI.init()
     for i, SECTION in enumerate(sorted(data)) :
         target = 'alias'
         if SECTION == target :
             alias = data.get(SECTION)
             continue
         logging.info((i,SECTION))
         value = data.get(SECTION)
         INI.write_section(config, SECTION, **value)
     for name in sorted(alias) :
         INI.write_section(config,name,**alias[name])
     config.write(open(save_file, 'w'))
def main():

    env = globals().get('env', None)
    nasdaq = '{}/local/{}'.format(env.pwd_parent, NASDAQ.path)
    finder = NASDAQ.init(filename=nasdaq)

    stock_list = map(lambda stock: PROFILE.get(stock), finder())
    ini, empty_list = find(stock_list)
    stock_ini = '{pwd_parent}/local/yahoo_background.ini'.format(**vars(env))
    config = INI.init()
    temp = ini['Background']
    for key in sorted(temp.keys()):
        INI.write_section(config, key, **temp[key])
    config.write(open(stock_ini, 'w'))

    stock_ini = '{pwd_parent}/local/yahoo_background_sector.ini'.format(
        **vars(env))
    config = INI.init()
    temp = ini['SectorGroupBy']
    for key in sorted(temp.keys()):
        INI.write_section(config, key, **temp[key])
    config.write(open(stock_ini, 'w'))

    # At one time, industries contained different sectors, this is no longer the case

    stock_ini = '{pwd_parent}/local/yahoo_background_industry.ini'.format(
        **vars(env))
    config = INI.init()
    temp = ini['IndustryGroupBy']
    for key in sorted(temp.keys()):
        INI.write_section(config, key, **temp[key])
    config.write(open(stock_ini, 'w'))
    return empty_list
Пример #11
0
    ret = pd.DataFrame(ret).T
    # screen potential under valued
    ret = ret[ret['returns'] < 0.15]
    if len(ret) == 0: return [], None

    _len = len(ret)
    size = int(_len * .1)
    # filter riskier
    ret = ret.sort_values(['risk']).head(_len - size)
    return list(ret.T.columns), ret


if __name__ == '__main__':

    from glob import glob
    import os, sys

    pwd = os.getcwd()
    pwd = pwd.replace('bin', 'local')
    ini_list = glob('{}/*.ini'.format(pwd))
    file_list = glob('{}/historical_prices/*pkl'.format(pwd))

    Sector_Top, Industry_Top, Fund_Top = main(file_list, ini_list)

    config = INI.init()
    INI.write_section(config, 'Sector', **Sector_Top)
    INI.write_section(config, 'Industry', **Industry_Top)
    INI.write_section(config, 'Fund', **Fund_Top)
    stock_ini = "{}/yahoo_sharpe_undervalued.ini".format(pwd)
    config.write(open(stock_ini, 'w'))
Пример #12
0
    label, data = STOCK_TIMESERIES.load(control)
    print label
    quarter = Partition.by_quarter(data)
    return label, data, quarter, file_list


if __name__ == '__main__':

    import os, sys
    from glob import glob
    from libCommon import INI

    pwd = os.getcwd()
    file_list = glob('{}/historical_prices/*pkl'.format(pwd))
    control_label, control, control_by_quarter, file_list = prep(*file_list)
    ini_stable, ini_performance = main(control_by_quarter, *file_list)

    pwd = pw.replace('bin', 'local')
    config_file = '{}/nasdaq_quarterly.ini'.format(pwd)
    config = INI.init()
    INI.write_section(config, 'Stability', **ini_stable)
    INI.write_section(config, 'Performance', **ini_performance)
    config.write(open(config_file, 'w'))
    '''
   for q in sorted(control_by_quarter.keys()) :
       data = control_by_quarter[q]['Volume']
       print control_label, q, 'Volume mean', round(data.mean(),2), 'Volume std', round(data.std(),2)
       data = control_by_quarter[q]['Adj Close']
       print control_label, q, 'Adj Close mean', round(data.mean(),2), 'Adj Close std', round(data.std(),2)
   '''
Пример #13
0
def main(input_file, file_list, ini_list,output_file) : 
    ret = INI.init()
    for name, section_list in action(input_file, file_list, ini_list) :
        INI.write_section(ret,name,**section_list)
    ret.write(open(output_file, 'w'))
def main(save_file):
    stock, etf, alias = NASDAQ.init().stock_list()

    background = STOCKMONITOR.init()
    logging.info(background)
    stockmonitor = background()
    temp = reduce(lambda a, b: a + b, stockmonitor.values())
    stock = set(stock) - set(temp)
    stock_list = sorted(list(stock))

    FinanceModel = scrape_financemodelling(stock_list)
    temp = reduce(lambda a, b: a + b, FinanceModel.values())
    stock = set(stock) - set(temp)
    stock_list = sorted(list(stock))

    yahoo = scrape_yahoo(stock_list)
    temp = reduce(lambda a, b: a + b, yahoo.values())
    stock = set(stock) - set(temp)
    stock_list = sorted(list(stock))
    '''
    Try a set of alternative names
    '''
    _retry, stock_list = handle_alias(*stock_list, **alias)
    retry = map(lambda x: alias[x].values(), _retry)
    retry = reduce(lambda a, b: a + b, retry)

    FinanceModel2 = scrape_financemodelling(retry)
    temp_fm = reduce(lambda a, b: a + b, FinanceModel2.values())
    retry = set(retry) - set(temp_fm)
    retry = sorted(list(retry))

    yahoo2 = scrape_yahoo(retry)
    temp_y = reduce(lambda a, b: a + b, yahoo2.values())
    retry = set(retry) - set(temp_y)
    retry = sorted(list(retry))

    logging.info(retry)
    logging.info(temp_fm)
    logging.info(temp_y)
    logging.info(_retry)

    config = INI.init()
    INI.write_section(config, "STOCKMONITOR", **stockmonitor)
    INI.write_section(config, "FINANCEMODEL", **FinanceModel)
    INI.write_section(config, "YAHOO", **yahoo)
    INI.write_section(config, "FINANCEMODEL2", **FinanceModel2)
    INI.write_section(config, "YAHOO2", **yahoo2)
    INI.write_section(config, "NASDAQTRADER", **{
        'unkown': stock_list,
        'alias': retry
    })
    for name in sorted(alias):
        INI.write_section(config, name, **alias[name])
    config.write(open(save_file, 'w'))
   from glob import glob
   import os,sys
   from libCommon import TIMER

   pwd = os.getcwd()

   dir = pwd.replace('bin','log')
   name = sys.argv[0].split('.')[0]
   log_filename = '{}/{}.log'.format(dir,name)
   log_msg = '%(module)s.%(funcName)s(%(lineno)s) %(levelname)s - %(message)s'
   logging.basicConfig(filename=log_filename, filemode='w', format=log_msg, level=logging.DEBUG)

   local = pwd.replace('bin','local')
   ini_list = glob('{}/*.ini'.format(local))
   file_list = glob('{}/historical_prices/*pkl'.format(local))

   elapsed = TIMER.init()
   logging.info("Started {}".format(name))
   ini = main(file_list,ini_list)
   logging.info("Finished {} Elapsed time {} ".format(name,elapsed()))

   config = INI.init()
   for key in ini.keys() :
       values = ini[key]
       if not isinstance(values,dict) :
          values = values.to_dict()
       INI.write_section(config,key,**values)
   stock_ini = "{}/sharpe_diversified_portfolios.ini".format(local)
   config.write(open(stock_ini, 'w'))
    log_filename = '{pwd_parent}/log/{name}.log'.format(**vars(env))
    log_msg = '%(module)s.%(funcName)s(%(lineno)s) %(levelname)s - %(message)s'
    logging.basicConfig(filename=log_filename,
                        filemode='w',
                        format=log_msg,
                        level=logging.INFO)

    ini, empty_list = main()

    print empty_list

    stock_ini = '{}/local/prototype_background.ini'.format(env.pwd_parent)
    config = INI.init()
    temp = ini['Background']
    for key in sorted(temp.keys()):
        INI.write_section(config, key, **temp[key])
    config.write(open(stock_ini, 'w'))

    stock_ini = '{}/local/prototype_background_sector.ini'.format(
        env.pwd_parent)
    config = INI.init()
    temp = ini['SectorGroupBy']
    for key in sorted(temp.keys()):
        INI.write_section(config, key, **temp[key])
    config.write(open(stock_ini, 'w'))

    # At one time, industries contained different sectors, this is no longer the case

    stock_ini = '{}/local/nasdaq_background_industry.ini'.format(
        env.pwd_parent)
    config = INI.init()
 def final(cls,data) :
     save_file = EXTRACT.instance().final
     logging.info('Loading results : {}'.format(save_file))
     config = INI.init()
     INI.write_section(config,"MERGED",**data)
     config.write(open(save_file, 'w'))