<jupyter_start><jupyter_text>combine-------------<jupyter_code>from pandas import ExcelWriter
writer = ExcelWriter('d:/多因子500+300合并.xlsx')

df1 = pd.read_csv('d:/hs300.csv', index_col=0)
df2 = pd.read_csv('d:/zz500.csv', index_col=0)
weights_secnario = {
    '3-1': (3., 1.),
    '2-1': (2., 1.),
    '1-1': (1., 1.),
}
for key, weights in weights_secnario.items():
    weight300, weight500 = weights
    ret_series = (weight300* df1['ret_after_tc'] + weight500 * df2['ret_after_tc']) /  (weight300 + weight500)

    sharp_calc = MovingSharp(49)
    drawdown_calc = MovingMaxDrawdown(49)
    max_drawdown_calc = MovingMaxDrawdown(len(ret_df))

    res_df = pd.DataFrame(columns=['daily_return', 'cum_ret', 'sharp', 'drawdown', 'max_drawn'])

    total_returns = 0.

    for i, ret in enumerate(ret_series):
        date = ret_series.index[i]
        sharp_calc.push({'ret': ret, 'riskFree': 0.})
        drawdown_calc.push({'ret': ret})
        max_drawdown_calc.push({'ret': ret})
        total_returns += ret
        res_df.loc[date, 'daily_return'] = ret
        res_df.loc[date, 'cum_ret'] = total_returns
        res_df.loc[date, 'drawdown'] = drawdown_calc.result()[0]
        res_df.loc[date, 'max_drawn'] = max_drawdown_calc.result()[0]

        if i < 10:
            res_df.loc[date, 'sharp'] = 0.
        else:
            res_df.loc[date, 'sharp'] = sharp_calc.result() * np.sqrt(49)
            
        res_df.to_excel(writer, key)
writer.save()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1712558764271323, 'fraction_numerical': 0.0409670920080591, 'mean_word_length': 3.1736694677871147, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '491731', 'license': 'MIT', 'n_tokens_mistral': 612, 'n_tokens_neox': 554, 'n_words': 94, 'path': 'notebooks/candidate_prod_model_20171204.ipynb', 'repo_name': 'lion-sing/alpha-mind', 'size': '1489'}