<jupyter_start><jupyter_text>价格<jupyter_code>def rate_features(df):
    df.index = pd.to_datetime(df.index)
    df_tmp = df.copy()
    df_day_first = df_tmp.resample('D').last()
    
    O1 = df_day_first['price'][0]
    O2 = df_day_first['price'][1]
    O3 = df_day_first['price'][2]
    O4 = df_day_first['price'][3]
    O5 = df_day_first['price'][4]
    
    D1 = df_tmp[(df_tmp.index >= '2021-08-23')&(df_tmp.index < '2021-08-24')]
    D2 = df_tmp[(df_tmp.index >= '2021-08-24')&(df_tmp.index < '2021-08-25')]
    D3 = df_tmp[(df_tmp.index >= '2021-08-25')&(df_tmp.index < '2021-08-26')]
    D4 = df_tmp[(df_tmp.index >= '2021-08-26')&(df_tmp.index < '2021-08-27')]
    D5 = df_tmp[(df_tmp.index >= '2021-08-27')&(df_tmp.index < '2021-08-28')]
    
    D1['Ratio'] = (D1['price'])/O1
    D2['Ratio'] = (D2['price'])/O2
    D3['Ratio'] = (D3['price'])/O3
    D4['Ratio'] = (D4['price'])/O4
    D5['Ratio'] = (D5['price'])/O5
    
    #D1['Ratio'] = (D1['price']-O1)/O1
    #D2['Ratio'] = (D2['price']-O2)/O2
    #D3['Ratio'] = (D3['price']-O3)/O3
    #D4['Ratio'] = (D4['price']-O4)/O4
    #D5['Ratio'] = (D5['price']-O5)/O5
    
    df_out = pd.concat([D1,D2,D3,D4,D5])
    
    return df_out
def rate1_features(df):
    df.index = pd.to_datetime(df.index)
    df_tmp = df.copy()
    
    Op = df_tmp['price'][0]
    
    df_tmp['Ratio'] = df_tmp['price']/Op
    #df_tmp.drop(['AgoPrice'])
    
    #df_out = pd.concat([D1,D2,D3,D4,D5])
    
    return df_tmp
df_PingAn_rate = rate1_features(df_PingAn)
df_Wanke_rate = rate1_features(df_Wanke)
df_ZhongXing_rate = rate1_features(df_ZhongXing)
df_ChangCheng_rate = rate1_features(df_ChangCheng)
df_HuaQiao_rate = rate1_features(df_HuaQiao)
df_TCL_rate = rate1_features(df_TCL)
df_ZhongLian_rate = rate1_features(df_ZhongLian)
df_ShenWan_rate = rate1_features(df_ShenWan)
df_MeiDi_rate = rate1_features(df_MeiDi)
df_WeiChai_rate = rate1_features(df_WeiChai)
df_PingAn_rate = rate_features(df_PingAn)
df_Wanke_rate = rate_features(df_Wanke)
df_ZhongXing_rate = rate_features(df_ZhongXing)
df_ChangCheng_rate = rate_features(df_ChangCheng)
df_HuaQiao_rate = rate_features(df_HuaQiao)
df_TCL_rate = rate_features(df_TCL)
df_ZhongLian_rate = rate_features(df_ZhongLian)
df_ShenWan_rate = rate_features(df_ShenWan)
df_MeiDi_rate = rate_features(df_MeiDi)
df_WeiChai_rate = rate_features(df_WeiChai)
df_tmp = df_PingAn_rate[['Ratio']]
df_li = [df_Wanke_rate, df_ZhongXing_rate, df_ChangCheng_rate, df_HuaQiao_rate, df_TCL_rate,
        df_ZhongLian_rate, df_ShenWan_rate, df_MeiDi_rate, df_WeiChai_rate]
df_name = ['_万科A', '_中兴通讯', '_中国长城', '_华侨城A', '_TCL科技',
        '_中联重科', '_申万宏源', '_美的集团', '_潍柴动力']

for df, name in zip(df_li, df_name):
    df_tmp = df_tmp.join(df[['Ratio']], rsuffix=name)
df_tmp = df_tmp.rename(columns={'Ratio':'Ratio_平安银行'})
df_tmp = df_tmp.resample('30T').mean()
df_mianban = df_tmp.dropna()<jupyter_output><empty_output><jupyter_text>开始绘图<jupyter_code>df_mianban
#df_mianban.plot(y='price', figsize=(20,8),fontsize = 12)

y_label = ['Ratio_平安银行','Ratio_万科A', 'Ratio_中兴通讯', 'Ratio_中国长城', 'Ratio_华侨城A', 'Ratio_TCL科技',
        'Ratio_中联重科', 'Ratio_申万宏源', 'Ratio_美的集团', 'Ratio_潍柴动力']

df_mianban.reset_index(inplace=True)

ax1 = df_mianban.plot(y=y_label, figsize=(20,10),fontsize = 16)

ax1.set_title('10支股票价格截面数据',fontsize = 24)
ax1.set_ylabel('净值',fontsize=20)
ax1.legend(fontsize=13)

plt.savefig('10支股票价格增长情况.jpg')
plt.show()<jupyter_output><empty_output><jupyter_text>成交量<jupyter_code>def volume_features(df):
    df.index = pd.to_datetime(df.index)
    df_tmp = df.copy()
    
    df_tmp = df_tmp[(df_tmp.index >= '2021-08-23')&(df_tmp.index < '2021-08-24')]
    df_tmp['log_volume'] = np.log(df_tmp['volume'])
    
    return df_tmp
df_PingAn_volume = volume_features(df_PingAn)
df_Wanke_volume = volume_features(df_Wanke)
df_ZhongXing_volume = volume_features(df_ZhongXing)
df_ChangCheng_volume = volume_features(df_ChangCheng)
df_HuaQiao_volume = volume_features(df_HuaQiao)
df_TCL_volume = volume_features(df_TCL)
df_ZhongLian_volume = volume_features(df_ZhongLian)
df_ShenWan_volume = volume_features(df_ShenWan)
df_MeiDi_volume = volume_features(df_MeiDi)
df_WeiChai_volume = volume_features(df_WeiChai)
df_tmp = df_PingAn_volume[['log_volume']]
df_li = [df_Wanke_volume, df_ZhongXing_volume, df_ChangCheng_volume, df_HuaQiao_volume, df_TCL_volume,
        df_ZhongLian_volume, df_ShenWan_volume, df_MeiDi_volume, df_WeiChai_volume]
df_name = ['_万科A', '_中兴通讯', '_中国长城', '_华侨城A', '_TCL科技',
        '_中联重科', '_申万宏源', '_美的集团', '_潍柴动力']

for df, name in zip(df_li, df_name):
    df_tmp = df_tmp.join(df[['log_volume']], rsuffix=name)
    
df_tmp = df_tmp.rename(columns={'log_volume':'log_volume_平安银行'})
#df_tmp = df_tmp.resample('D').mean()
df_mianban = df_tmp.dropna()
df_mianban
y_label = ['log_volume_TCL科技','log_volume_平安银行','log_volume_潍柴动力','log_volume_中联重科',
            'log_volume_中国长城','log_volume_申万宏源', 'log_volume_万科A',
           'log_volume_中兴通讯', 'log_volume_美的集团', 'log_volume_华侨城A' ]

#df_mianban.reset_index(inplace=True)
ax2 = df_mianban.plot(y=y_label, figsize=(18,8),fontsize = 16, rot=0)

ax2.set_title('10支股票成交量截面数据',fontsize = 24)
ax2.set_ylabel('LN成交量',fontsize=20)
ax2.legend(fontsize=13)

plt.savefig('10支股票成交量对比.jpg')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16309094361116386, 'fraction_numerical': 0.04082020125308525, 'mean_word_length': 5.949868073878628, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '486302', 'license': 'Apache-2.0', 'n_tokens_mistral': 2621, 'n_tokens_neox': 2638, 'n_words': 268, 'path': 'DL/plot.ipynb', 'repo_name': 'YuLing91/Cryptocurrency-trading-systems-based-on-recurrent-reinforcement-learning', 'size': '5267'}