Exemplo n.º 1
0
    stock_names, etf_names = process_names(nasdaq)
    names = {}
    names.update(etf_names)
    names.update(stock_names)
    ticker_list = sorted(names.keys())
    background = TRANSFORM.summary(data_store, stock_list)
    background['NAME'] = names
    LOAD.background(**background)


if __name__ == '__main__':
    import sys
    import logging
    from libCommon import ENVIRONMENT

    env = ENVIRONMENT()
    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)
    #logging.basicConfig(stream=sys.stdout, format=log_msg, level=logging.INFO)

    ini_list = env.list_filenames('local/*.ini')
    #file_list = env.list_filenames('local/historical_prices/*pkl')
    #output_file_by_type = '../local/stock_by_type.ini'
    background_file = '../local/stock_background.ini'

    local_dir = '{}/local'.format(env.pwd_parent)
    data_store = '../local/historical_prices'
Exemplo n.º 2
0
    plt.legend(**kwargs)
    plt.savefig(path)
    plt.clf()
    plt.cla()
    plt.close()


if __name__ == '__main__':

    import sys
    import logging
    from libCommon import ENVIRONMENT
    from libFinance import STOCK_TIMESERIES, HELPER as FINANCE
    from libSharpe import HELPER as MONTECARLO

    env = ENVIRONMENT()

    log_msg = '%(module)s.%(funcName)s(%(lineno)s) %(levelname)s - %(message)s'
    logging.basicConfig(stream=sys.stdout, format=log_msg, level=logging.DEBUG)

    file_list = env.list_filenames('local/historical_prices/*pkl')
    ini_list = env.list_filenames('local/*.ini')

    portfolio_ini = filter(lambda ini: "portfolio" in ini, ini_list)
    portfolio_ini = filter(lambda ini: "sharpe" in ini, ini_list)
    logging.debug(portfolio_ini)

    def prep(tickers):
        reader = STOCK_TIMESERIES.init()
        values = map(lambda ticker: reader.extract_from_yahoo(ticker), tickers)
        values = map(lambda data: pd.DataFrame(data)['Adj Close'], values)
Exemplo n.º 3
0
    meta = ['returns', 'risk', 'sharpe']
    stock_list = filter(lambda x: x not in meta, stock_list)
    max_sharp, min_dev = PORTFOLIO.find(data_list,
                                        stocks=stock_list,
                                        portfolios=25000,
                                        period=FINANCE.YEAR)
    logging.debug((max_sharpe, min_dev))
    yield max_sharpe, min_dev


if __name__ == '__main__':

    import logging
    from libCommon import ENVIRONMENT

    env = ENVIRONMENT()
    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_list = env.list_filenames('local/method01_step02*.ini')
    file_list = env.list_filenames('local/historical_prices/*pkl')
    save_file = "{}/local/method01_step03_sharpe_portfolios.ini".format(
        env.pwd_parent)

    ini = main(file_list, ini_list)

    config = INI.init()
Exemplo n.º 4
0
def embedImage(canvas):
    f = open(path_to_file, 'rb')
    story.append(Image(f))


def main(save_file):
    c = canvas.Canvas(save_file)
    c.drawString(100, 750, "Welcome to Reportlab!")
    fonts(c)
    #horizontalscale(c)
    c.save()


if __name__ == '__main__':
    import os, sys
    import logging
    from libCommon import ENVIRONMENT

    env = ENVIRONMENT()
    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)
    logging.basicConfig(stream=sys.stdout, format=log_msg, level=logging.INFO)

    local_dir = '{pwd_parent}/local'.format(**vars(env))
    test_dir = 'testResults'
    save_file = '{}/hello.pdf'.format(test_dir)
    env.mkdir(test_dir)
    main(save_file)
Exemplo n.º 5
0
        tbl = StockTemplate.addTable(captions, images, weights, returns)
        logging.debug(tbl)
        ret.append(tbl)
        ret.append(PageBreak())

    logging.debug(ret)
    doc.multiBuild(ret)


if __name__ == '__main__':

    import logging
    import sys
    from libCommon import ENVIRONMENT

    env = ENVIRONMENT()
    log_filename = '{pwd_parent}/log/{name}.log'.format(**vars(env))
    log_msg = '%(module)s.%(funcName)s(%(lineno)s) %(levelname)s - %(message)s'
    #logging.basicConfig(stream=sys.stdout, format=log_msg, level=logging.INFO)
    logging.basicConfig(filename=log_filename,
                        filemode='w',
                        format=log_msg,
                        level=logging.DEBUG)

    ini_list = env.list_filenames('local/*.ini')

    input_file = env.list_filenames('local/report_generator.ini')
    output_file = "{pwd_parent}/local/image.pdf".format(**vars(env))

    main()
Exemplo n.º 6
0
    ]
    ts = [
        ('TOPPADDING', (0, 0), (-1, -1), 0),
        ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ('VALIGN', (0, 0), (-1, -1), 'TOP'),
    ]
    ts = TableStyle(ts)


if __name__ == "__main__":

    import sys
    import logging
    from libCommon import ENVIRONMENT

    env = ENVIRONMENT()
    pdf_landscape = '{pwd_parent}/local/example_landscape.pdf'.format(
        **vars(env))
    pdf_portrait = '{pwd_parent}/local/example_portrait.pdf'.format(
        **vars(env))

    log_msg = '%(module)s.%(funcName)s(%(lineno)s) %(levelname)s - %(message)s'
    logging.basicConfig(stream=sys.stdout, format=log_msg, level=logging.DEBUG)

    story = []
    toc = StockTemplate.initToc()
    story.append(toc)
    story.append(PageBreak())
    story.append(Paragraph('First heading', StockTemplate.h1))
    story.append(Paragraph('Text in first heading', PS('body')))
    story.append(Paragraph('First sub heading', StockTemplate.h2))
Exemplo n.º 7
0
        name_list.append(returns_list[i])
        image_list.append(image_div_list[i])
        image_list.append(image_return_list[i])
        tbl = addTable(name_list, image_list)
        ret.append(tbl)
        name_list = []
        image_list = []
    doc.build(ret)


if __name__ == '__main__':
    import os, sys
    import logging
    from libCommon import ENVIRONMENT

    env = ENVIRONMENT()
    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)
    logging.basicConfig(stream=sys.stdout, format=log_msg, level=logging.INFO)

    local_dir = '{pwd_parent}/local'.format(**vars(env))
    target = 'local/*.ini'
    ini_list = env.list_filenames(target)
    target = 'local/images/*.png'
    file_list = env.list_filenames(target)
    file_name = map(lambda x: os.path.basename(x), file_list)
    file_list = dict(zip(file_name, file_list))
    test_dir = 'testResults'
    save_file = '{}/image.pdf'.format(test_dir)
    env.mkdir(test_dir)
Exemplo n.º 8
0
    STEP_04.returns(target_01, **stocks)
    save("{}/step_04_{}.png".format(local_dir, target_01))
    STEP_01.volume(target_02, **stocks)
    save("{}/step_01_{}.png".format(local_dir, target_02))
    STEP_02.volume(target_02, **stocks)
    save("{}/step_02_{}.png".format(local_dir, target_02))
    STEP_03.volume(target_02, **stocks)
    save("{}/step_03_{}.png".format(local_dir, target_02))
    STEP_04.volume(target_02, **stocks)
    save("{}/step_04_{}.png".format(local_dir, target_02))


if __name__ == '__main__':
    import os, sys
    import logging
    from libCommon import ENVIRONMENT

    env = ENVIRONMENT()
    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)
    logging.basicConfig(stream=sys.stdout, format=log_msg, level=logging.INFO)

    ini_list = env.list_filenames('local/*.ini')
    file_list = env.list_filenames('local/historical_prices/*pkl')

    local_dir = '{pwd_parent}/local'.format(**vars(env))
    test_dir = 'testResults'
    env.mkdir(test_dir)
    main(test_dir)
Exemplo n.º 9
0
    yield "combined_sharpe", max_sharp
    yield "combined_risk", min_dev
    return
@exit_on_exception
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'))

if __name__ == '__main__' :
   import sys
   import logging
   from libCommon import ENVIRONMENT

   env = ENVIRONMENT()
   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)
   logging.basicConfig(stream=sys.stdout, format=log_msg, level=logging.INFO)

   portfolio_list = env.list_filenames('local/portfolio*.ini')
   ini_list = env.list_filenames('local/*.ini')
   file_list = env.list_filenames('local/historical_prices/*pkl')
   input_file = env.list_filenames('local/method02*.ini')
   output_file = "{}/local/method02_step06.ini".format(env.pwd_parent)
   sector_list = ['Basic Materials','Communication Services','Consumer Cyclical','Consumer Defensive','Energy','Financial Services','Healthcare','Industrials','Real Estate','Technology','Utilities']

   main(input_file, file_list,ini_list,output_file)
Exemplo n.º 10
0
        section['description2'] = returns['description_summary'][i]
        section['description3'] = returns['description_details'][i]
        section['name'] = portfolio_name_list[i]
        key = "portfolio_{}".format(i)
        portfolio[key] = section

    LOAD.config(summary, portfolio)


if __name__ == '__main__':

    import sys
    import logging
    from libCommon import ENVIRONMENT

    env = ENVIRONMENT()

    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)
    #logging.basicConfig(stream=sys.stdout, format=log_msg, level=logging.INFO)

    ini_list = env.list_filenames('local/*.ini')
    category = filter(
        lambda x: 'stock_by_sector.ini' in x or 'fund_by_type.ini' in x,
        ini_list)
    background = filter(lambda x: 'background.ini' in x, ini_list)
    benchmark = filter(lambda x: 'benchmark' in x, ini_list)
Exemplo n.º 11
0
def main():
    env = ENVIRONMENT()
    logging.info(env)
    file_list = env.list_filenames(extension='local/*.ini')
    logging.info(file_list)