使用 pandas 和 matplotlib 画收盘价折线图和移动均线
所属分类 quant
浏览量 463
import pandas as pd
import matplotlib.pyplot as plt
# 读取沪深300行情数据
data = pd.read_csv('/path/data/hs300.csv')
# close_price = data.loc[:, 'close']
# 取收盘价
close_price = data['close']
# 5日 和 10日 移动均线
ma_5 = close_price.rolling(window=5).mean()
ma_10 = close_price.rolling(window=10).mean()
plt.plot(close_price)
plt.plot(ma_5, label='MA5')
plt.plot(ma_10, label='MA10')
plt.legend()
plt.show()
date,open,high,low,close,volume,amount
20230711,3853.80,3870.65,3844.52,3869.49,8651.07,1775.86
20230712,3864.60,3874.04,3838.56,3843.44,11152.20,2140.47
20230713,3855.66,3901.10,3855.66,3898.42,12030.02,2352.79
20230714,3904.60,3908.49,3893.79,3899.10,12236.48,2202.30
20230717,3881.62,3881.62,3852.26,3867.17,9834.01,1746.24
20230718,3871.04,3871.04,3844.51,3854.94,9143.86,1671.04
20230719,3848.48,3860.01,3830.41,3850.87,7958.57,1513.11
20230720,3857.77,3875.62,3818.71,3823.69,9204.21,1743.21
20230721,3816.98,3849.51,3808.80,3821.91,7950.76,1571.44
20230724,3803.35,3828.79,3798.80,3805.22,7548.35,1514.48
20230725,3866.64,3915.81,3866.64,3915.12,16306.63,2998.54
20230726,3908.17,3912.98,3893.40,3907.01,10788.17,1929.13
20230727,3914.23,3935.36,3894.69,3902.35,11066.71,1968.45
20230728,3889.79,4000.92,3886.55,3992.74,17973.55,3100.92
20230731,4018.89,4064.36,4002.08,4014.63,19960.68,3665.44
20230801,4009.18,4031.70,3983.03,3998.00,14228.69,2556.21
20230802,3985.70,4008.33,3958.51,3969.90,12585.57,2048.76
20230803,3962.13,4005.00,3962.13,4004.98,12900.66,2248.10
20230804,4033.72,4058.24,4011.62,4020.58,17826.72,3165.30
20230807,4002.97,4002.97,3977.02,3990.15,12131.07,2270.91
20230808,3980.04,4002.29,3963.46,3979.73,10987.17,2026.11
20230809,3967.36,3982.11,3961.84,3967.57,9464.03,1743.94
20230810,3962.86,3976.46,3945.39,3975.72,9717.68,1756.47
上一篇
下一篇
指数分类 行业 主题 风格 策略指数
《打开量化投资的黑箱(原书第2版)》序和前言笔记
多因子量化选股模型
《亚当理论》摘录
技术分析常用指标
anaconda 使用