def construct_ibo_portfolio_4date(**kwargs):
    # date_to

    ibo_output = ibo.generate_ibo_sheet_4date(**kwargs)
    sheet_4date = ibo_output['sheet_4date']
    cov_output = ibo_output['cov_output']
    cov_data_integrity = cov_output['cov_data_integrity']

    if cov_data_integrity < 80:
        return {'success': False}

    cov_matrix = cov_output['cov_matrix']
    sheet_4date['qty'] = sheet_4date['ticker_head'].apply(lambda x: round(1000/m.sqrt(cov_matrix[x][x])))
    sheet_4date['pnl_scaled'] = sheet_4date['pnl']*sheet_4date['qty']

    return {'success': True, 'sheet_4date': sheet_4date}
def generate_ibo_formatted_output(**kwargs):

    if 'report_date' in kwargs.keys():
        report_date = kwargs['report_date']
    else:
        report_date = exp.doubledate_shift_bus_days()

    output_dir = ts.create_strategy_output_dir(strategy_class='ibo', report_date=report_date)

    out_dictionary = ibo.generate_ibo_sheet_4date(date_to=report_date)
    cov_matrix = out_dictionary['cov_output']['cov_matrix']

    cov_matrix.reset_index(drop=False,inplace=True)

    writer = pd.ExcelWriter(output_dir + '/' + 'cov_matrix.xlsx', engine='xlsxwriter')
    cov_matrix.to_excel(writer, sheet_name='cov_matrix')
    writer.save()

    cov_data_integrity = round(out_dictionary['cov_output']['cov_data_integrity'], 2)

    with open(output_dir + '/' + 'covDataIntegrity.txt','w') as text_file:
        text_file.write(str(cov_data_integrity))
Esempio n. 3
0
def generate_ibo_formatted_output(**kwargs):

    if 'report_date' in kwargs.keys():
        report_date = kwargs['report_date']
    else:
        report_date = exp.doubledate_shift_bus_days()

    output_dir = ts.create_strategy_output_dir(strategy_class='ibo',
                                               report_date=report_date)

    out_dictionary = ibo.generate_ibo_sheet_4date(date_to=report_date)
    cov_matrix = out_dictionary['cov_output']['cov_matrix']

    cov_matrix.reset_index(drop=False, inplace=True)

    writer = pd.ExcelWriter(output_dir + '/' + 'cov_matrix.xlsx',
                            engine='xlsxwriter')
    cov_matrix.to_excel(writer, sheet_name='cov_matrix')
    writer.save()

    cov_data_integrity = round(
        out_dictionary['cov_output']['cov_data_integrity'], 2)

    with open(output_dir + '/' + 'covDataIntegrity.txt', 'w') as text_file:
        text_file.write(str(cov_data_integrity))

    sheet_4date = out_dictionary['sheet_4date']

    writer = pd.ExcelWriter(output_dir + '/summary.xlsx', engine='xlsxwriter')

    sheet_4date.to_excel(writer, sheet_name='all')

    worksheet_all = writer.sheets['all']
    worksheet_all.freeze_panes(1, 0)
    worksheet_all.autofilter(0, 0, len(sheet_4date.index),
                             len(sheet_4date.columns))