import pandas as pd import numpy as np import matplotlib.pyplot as plt…
Jump to turn (6)
- 1import pandas as pd import numpy as np import matplotlib.pyplot as plt 假设成交量数据存储
- 2如果我想用呢?
- 3raise TypeError("Unknown artist property: %s" % prop) TypeError: Unknown artist
- 4AttributeError: 'AxesStack' object has no attribute 'clear'
- 5import pandas as pd import numpy as np import matplotlib.pyplot as plt 假设成交量数据存储
- 6报错 File "D:\Anaconda3\lib\site-packages\matplotlib\figure.py", line 2745, in clf
- User
import pandas as pd import numpy as np import matplotlib.pyplot as plt
假设成交量数据存储在名为df的DataFrame中,包含日期和成交量两列
df=pd.read_excel('C:/Users/陈赞/Desktop/K线导出_000906_日线数据.xls').iloc[3800:,]
为了方便计算,先将日期列设置为索引
df.set_index('Date', inplace=True)
计算每日成交量的均值,作为基准值
base_volume = df['vol'].mean()
计算每日成交量相对基准值的比例,得到情绪指数
emotion_index = df['vol'] / base_volume
进行指数加权移动平均处理,得到平滑的情绪指数
ema = emotion_index.ewm(span=20).mean()
计算情绪指数的移动平均和标准差
window_size = 20 ema = np.convolve(emotion_index, np.ones(window_size)/window_size, mode='valid') std = np.std(emotion_index)
计算上下轨道
upper_bound = ema + 2std lower_bound = ema - 2std plt.fill_between(range(window_size-1, len(emotion_index)), upper_bound, lower_bound, alpha=0.2, label='Upper/Lower Bound')
绘制情绪指数和上下轨道
plt.plot(emotion_index, label='emotion index',use_index=False) plt.plot(ema, label=f'{window_size}-day EMA',use_index=False)
plt.legend() plt.show()代码报错'Line2D' object has no property 'use_index'
- Assistant