本文在股市可视化中可视化相关矩阵 :最小生成树
在本文示例中,我将使用日数据和1分钟数据来可视化股票数据 。
我发现以下概念定义非常有用:
#*****************************************************************
# 加载历史数据
#*****************************************************************
getSymbols(tickers, src = 'yahoo', from = '1970-01-01', env = data, auto.assign =
for(i in ls(data)) data[[i]] = adjustOHLC(data[[i]
# 删除历史数据很少的样本
remove.min.history(data)
# 显示已删除的
print(setdiff(tickers,names(data$prices)))
#*****************************************************************
# 可视化关联矩阵
#*****************************************************************
prices = data$prices
ret = diff(log(prices))
ret = last(ret, 252)
plt(ret, 0.5)
接下来,让我们获取1分钟的收盘价数据,并基于最近5天可视化相关性:
#*****************************************************************
# 加载历史数据
#*****************************************************************
if(!file.exists(filename)) {
data1[[ticker]] = getSymbol.intraday.google(ticker,
#*****************************************************************
# 可视化关联矩阵
#*****************************************************************
print(join(c(
,format(range(index(ret)), '%d-%b-%Y %H-%M')), ' '))
plot.cor(ret, 0.5)
辅助函数:
#*****************************************************************
#函数创建相关矩阵
#*****************************************************************
clncor = function(ret, threshold = 0.5) {
cor(coredata(ret), use='complete.obs',method='pearson')
cor_mat[ abs(cor_mat) < threshold] = 0
#*****************************************************************
# 绘制最小生成树
#*****************************************************************
plco = function(ho = 0.5) {
cor_mat = clean.cor(ret, threshold
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有