简体   繁体   English

xts对象上的循环中的quantmod中的chart_Series

[英]chart_Series in quantmod in a loop on an xts object

I am trying to create multiple charts and insert a vertical line using quantmod's chart_Series in a loop. 我正在尝试创建多个图表,并在循环中使用Quantmod的chart_Series插入一条垂直线。 When I run the code, it does not produce a chart or an error message. 当我运行代码时,它不会产生图表或错误消息。 I'm not sure what I'm doing wrong. 我不确定自己在做什么错。 Below is the code I am using and sample data. 以下是我正在使用的代码和示例数据。 Any assistance would be appreciated. 任何援助将不胜感激。 Thank you. 谢谢。

library(quantmod)
xt <- xts(rep(FALSE, nrow(B825)), index(B825))
Buy.Date <- c('2017-08-25')
xt[Buy.Date,] <- TRUE

for(i in 1: ncol(B825)) {
  chart_Series(B825[,i])
  add_TA(xt, on =-1, col = "white", border = "white")
}

             STNG  ASC
2017-05-18 4.0188 7.70
2017-05-19 4.1185 7.70
2017-05-22 4.1484 7.80
2017-05-23 4.1883 7.70
2017-05-24 3.9989 7.50
2017-05-25 3.9590 7.45
2017-05-26 3.7795 7.45
2017-05-30 3.6997 7.35
2017-05-31 3.7097 7.20
2017-06-01 3.7695 7.20
2017-06-02 3.6299 7.20
2017-06-05 3.6000 7.20
2017-06-06 3.6000 7.25
2017-06-07 3.5900 7.15
2017-06-08 3.6698 7.55
2017-06-09 3.8094 7.70
2017-06-12 3.7894 7.85
2017-06-13 3.8493 7.95
2017-06-14 3.7894 7.75
2017-06-15 3.6399 7.60
2017-06-16 3.7595 7.85
2017-06-19 3.7496 7.90
2017-06-20 3.6000 7.85
2017-06-21 3.6099 7.65
2017-06-22 3.7595 7.85
2017-06-23 3.9889 8.15
2017-06-26 4.0088 8.40
2017-06-27 4.0587 8.50
2017-06-28 4.0487 8.35
2017-06-29 4.0786 8.20
2017-06-30 3.9590 8.15
2017-07-03 4.0388 8.45
2017-07-05 3.9490 8.10
2017-07-06 3.7595 7.85
2017-07-07 3.7695 7.85
2017-07-10 3.7695 7.65
2017-07-11 3.7894 7.85
2017-07-12 3.7496 7.95
2017-07-13 3.7994 8.00
2017-07-14 3.8892 8.00
2017-07-17 3.8493 8.00
2017-07-18 3.7296 7.85
2017-07-19 3.7296 8.00
2017-07-20 3.7496 7.90
2017-07-21 3.7196 7.80
2017-07-24 3.6797 7.85
2017-07-25 3.6698 7.95
2017-07-26 3.6897 7.95
2017-07-27 3.7496 7.95
2017-07-28 3.7097 7.95
2017-07-31 3.6997 7.95
2017-08-01 3.6598 7.95
2017-08-02 3.6199 7.95
2017-08-03 3.5501 7.85
2017-08-04 3.5302 7.70
2017-08-07 3.5401 7.55
2017-08-08 3.5202 7.40
2017-08-09 3.5401 7.25
2017-08-10 3.4105 7.20
2017-08-11 3.3507 7.25
2017-08-14 3.4005 7.45
2017-08-15 3.3806 7.30
2017-08-16 3.2111 7.45
2017-08-17 3.3806 7.20
2017-08-18 3.5002 7.30
2017-08-21 3.3606 7.20
2017-08-22 3.4005 7.30
2017-08-23 3.4404 7.35
2017-08-24 3.6997 7.65
2017-08-25 3.9689 7.95
2017-08-28 3.8991 8.05
2017-08-29 3.9789 8.05
2017-08-30 3.9889 8.00
2017-08-31 4.0587 8.10
2017-09-01 4.0088 8.10
2017-09-05 3.7097 7.75
2017-09-06 3.5002 7.65
2017-09-07 3.5202 7.70
2017-09-08 3.5202 7.55
2017-09-11 3.4404 7.55
2017-09-12 3.4404 7.45
2017-09-13 3.4005 7.40
2017-09-14 3.5701 7.35
2017-09-15 3.4903 7.35
2017-09-18 3.3806 7.55
2017-09-19 3.4604 7.95
2017-09-20 3.5701 8.00
2017-09-21 3.4304 7.70
2017-09-22 3.5900 8.00
2017-09-25 3.5300 8.05
2017-09-26 3.4100 8.00
2017-09-27 3.5300 8.20
2017-09-28 3.4900 8.20
2017-09-29 3.4300 8.25
2017-10-02 3.5900 8.50
2017-10-03 3.5800 8.85
2017-10-04 3.6200 8.75
2017-10-05 3.7000 8.95
2017-10-06 3.6400 8.90
2017-10-09 3.5400 8.80

UPDATE 更新

str(B825)

An ‘xts’ object on 2017-05-19/2017-10-10 containing:
  Data: num [1:100, 1:2] 4.12 4.15 4.19 4 3.96 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:2] "STNG" "ASC"
  Indexed by objects of class: [Date] TZ: UTC
  xts Attributes:  
 NULL
for(i in 1: ncol(B825)) {
  windows()
  print(chart_Series(B825[,i], name=names(B825)[i]))
  print(add_TA(xt, on =-1, col = "red", border = "white"))
}

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM