yt3 = MoveAverage(y,3)#计算3个月 s30 = np.sqrt(((y0[3:]-yt3[3:])**2).mean())#计算与真实数据误差 s3 = np.sqrt(((y[3:]-yt3[3:])**2).mean())#计算与预测所用样本的误差 yt5 = MoveAverage(y,5)#计算5个月 s5 = np.sqrt(((y[5:]-yt3[5:])**2).mean())#计算误差 ...
通过pandas的rolling()方法可以实现数据移动,ewa()实现加权移动,mean()实现平均。step平均的间隔。 # 对数据进行移动平均来平滑数据 def move_average(data,step): series=pd.Series(data) rol_mean=series.rolling(window=step).mean() # 移动平均 rol_weight_mean=pd.DataFrame.ewm(series,span=step).mean()...
df['ATR'] = df['TR'].rolling(window=22).mean()# 计算吊灯退出(长仓和短仓)df['Chandelier_Exit_Long'] = df['high'].rolling(window=22).max() - df['ATR'] *3df['Chandelier_Exit_Short'] = df['low'].rolling(window=22).min() + df['ATR'] *3returndf[['Chandelier_Exit_Long',...
defnp_move_avg(a,n,mode="same"):return(np.convolve(a,np.ones((n,))/n,mode=mode))modes=['full','same','valid']forminmodes:plt.plot(np_move_avg(np.ones((200,)),50,mode=m));plt.axis([-10,251,-.1,1.1]);plt.legend(modes,loc='lower center');plt.show() 5.参考...
1、自动化office,包括对excel、word、ppt、email、pdf等常用办公场景的操作,python都有对应的工具库,...
# 移动平均图 defdraw_trend(timeSeries,size):f=plt.figure(facecolor='white')# 对size个数据进行移动平均 rol_mean=timeSeries.rolling(window=size).mean()# 对size个数据进行加权移动平均 rol_weighted_mean=pd.ewma(timeSeries,span=size)timeSeries.plot(color='blue',label='Original')rolmean.plot(col...
[quintile] = filtered_df_shifted #For Equal-Weight, simply take the average return across stocks within each quintile dataframe portfolio_returns[quintile] = quintile_dfs[quintile].mean(axis=1).dropna() # Plot the cumulative return (1+portfolio_returns).cumprod().hvplot(title = 'Portfolios - ...
>>>importshutil>>>shutil.copyfile('data.db','archive.db')>>>shutil.move('/build/executables','installdir') 文件通配符 glob 模块提供了一个函数用于从目录通配符搜索中生成文件列表: 实例 >>>importglob >>>glob.glob('*.py') ['primes.py','random.py','quote.py'] ...
布尔值和布尔代数的表示完全一致,一个布尔值只有True、False两种值,要么是True,要么是False,在Python中,可以直接用True、False表示布尔值(请注意大小写),也可以通过布尔运算计算出来。 布尔值可以用and、or和not运算。 and运算是与运算,只有所有都为 True,and运算结果才是 True。
pre = np.mean(pre,axis=0)*365 pre = np.array(pre) pre[pre<0]=np.nan lon,lat = np.meshgrid(lon, lat) #绘制二维网格 """设置绘图区域, 投影""" fig, ax1 = plt.subplots(figsize=(12,6), subplot_kw={'projection':ccrs.PlateCarree()}) ...