首页  

pandas 股票指数技术分析     所属分类 quant 浏览量 400
import pandas as pd
hs300file = "/data/hs300.txt"
hs300df = pd.read_csv(hs300file)

# 唐奇通道
hs300df["up"] = hs300df["high"].rolling(window=20).max()
hs300df["down"] = hs300df["low"].rolling(window=20).min()
hs300df["mid"] = (hs300df["up"] + hs300df["down"]) / 2
hs300df[["up","down","close"]].plot()


# 布林通道
hs300df["bollstd"] = hs300df["close"].rolling(window=20).std()
hs300df["bollmid"] = hs300df["close"].rolling(window=20).mean()
hs300df["bollhigh"] = hs300df["bollmid"] + 2*hs300df["bollstd"]
hs300df["bolllow"] = hs300df["bollmid"] - 2*hs300df["bollstd"]
hs300df[["bollhigh","bolllow","close"]].plot()



hs300df["close"].describe()

hs300df["ma250"] = hs300df["close"].rolling(window=250).mean()

hs300df["median250"] = hs300df["close"].rolling(window=250).median()


# 每日收益率
hs300df["returns"] = hs300df["close"].pct_change()

# 波动率
hs300df["volatility"] = hs300df["returns"].rolling(window=250).std() * np.sqrt(250)
# 每日收益 直方图
hs300df["returns"].hist(bins=50)
# 累计收益
hs300df["returns_cum"] = (1+hs300df["returns"]).cumprod()

hs300df[["ma250","close"]].plot()

上一篇     下一篇
常见交易类型

唐奇安通道指标

pandas 计算 布林通道 和 唐奇通道

pandas dataframe 计算收益率

java量化交易技术资料

开源授权协议