r - 如何在 quantmod 中将指标显示为直方图?

标签 r xts quantmod

我有一个 xts 对象,其中包含以下值:开盘价、最高价、最低价、收盘价、成交量和事件。事件有正值和负值。

我的目标:我想将“Activity”显示为直方图,就像 MACD 一样,但我所能做的就是将其显示为 LINE 指标。

您对如何改进我的代码有什么想法吗? 谢谢大家。

我已经包含了我的代码和数据集:

#load data
dat1<-read.table("so1.txt",sep=",",header=F,stringsAsFactors=F)

#load libraries
library(quantmod)
library(xts)

#create an xts object
myxtsDaily<-xts(dat1[,2:7],order.by=as.POSIXct(dat1[,1]))
#name the columns of the xts object
colnames(myxtsDaily)<-c("Open","High","Low","Close","Volume","Activity")

#create function for "Activity" to be used for the indicator
Activity<-function(myxtsDaily){myxtsDaily[,"Activity"]*1}
addAct<-newTA(FUN=Activity,legend="Activity",histogram=TRUE)

#creat chart
myTheme <- chartTheme("white", up.col="green", dn.col="red")
chartSeries(myxtsDaily, TA="addVo();addAct()", theme=myTheme)

这是我得到的图表: enter image description here 和数据集:

"2014-04-14 23:59:59",1813,1828,1806.25,1825.25,1817375,-11424742.5
"2014-04-15 23:59:59",1825,1849.25,1809.25,1847,2633708,15250797.75
"2014-04-16 23:59:57",1846.75,1857,1840.75,1849.75,1617236,71489684.25
"2014-04-17 14:14:59",1850,1863.75,1847.25,1857.5,1212355,-64682131.75
"2014-04-20 23:59:31",1858,1862.75,1858,1860.5,20764,4622921.75
"2014-04-21 23:59:56",1860.5,1865.75,1856.5,1862.75,543742,-3327275.5
"2014-04-22 23:59:44",1863,1878.75,1861.5,1875.25,1105785,38897748.75
"2014-04-23 23:59:57",1875,1880.75,1867.5,1879,994766,-21499152
"2014-04-24 23:59:57",1879,1882.5,1863.75,1870.75,1568280,-48874765
"2014-04-25 14:14:59",1871,1873,1853,1860.25,1482993,-32882843.25
"2014-04-27 23:59:51",1861.75,1863,1858,1861.75,36382,197679.25
"2014-04-28 23:59:46",1861.75,1871.75,1844,1869,2063129,-15666877.5
"2014-04-29 23:59:59",1869.25,1875.25,1865.25,1868,1219307,-31611922.75
"2014-04-30 23:59:57",1868,1880.25,1866.5,1877.75,1462764,22162015.5
"2014-05-01 23:59:51",1877.75,1882.75,1871.5,1878.75,928576,26541281
"2014-05-02 14:14:59",1878.5,1886,1872,1872.5,1695321,-38554918.5
"2014-05-04 23:59:58",1875.5,1877.25,1871.25,1874.25,33459,2200935.75
"2014-05-05 23:59:56",1874,1880,1860.5,1879.75,1159609,11973977.75
"2014-05-06 23:59:59",1879.75,1881.5,1861,1861.75,1407020,-194154881.75
"2014-05-07 23:59:48",1862,1876,1854.5,1873.5,1988134,16046301.25
"2014-05-08 23:59:56",1873.5,1884.75,1865,1872,1743710,-24980947.25
"2014-05-09 14:14:59",1872.25,1875,1862.5,1874.75,1445125,17701156.75
"2014-05-11 23:59:58",1874,1878,1874,1876.25,35449,-2954357.5
"2014-05-12 23:59:47",1876.5,1895.5,1875.5,1895.25,1181998,62710371.75
"2014-05-13 23:59:57",1895.25,1898.5,1892,1896.25,1063091,24299903.75
"2014-05-14 23:59:58",1896,1896.25,1882.25,1886,1188544,-80103945.25
"2014-05-15 23:59:59",1886,1888.5,1859,1865.25,2246117,-169792103.25
"2014-05-16 14:14:58",1865.25,1875.75,1861.25,1875.25,1484140,19404118.75
"2014-05-18 23:59:53",1876.25,1877.5,1871.75,1872.25,32912,-7644115
"2014-05-19 23:59:56",1872,1883,1865.75,1880.5,1025339,15965039.25
"2014-05-20 23:59:59",1880.25,1884.5,1864.75,1869.5,1573780,-117398005.75
"2014-05-21 23:59:53",1869.5,1890.5,1867.5,1888.5,1350195,98358229.75
"2014-05-22 23:59:59",1888.25,1894,1882.75,1891.75,987303,39957384.75
"2014-05-23 14:15:00",1891.75,1899.25,1889.75,1896.5,731114,-17457302.75
"2014-05-25 23:59:42",1898,1899.75,1897,1899.5,16836,4300139.5
"2014-05-26 23:59:57",1899.25,1904.75,1898.75,1902.25,78857,9186097.5
"2014-05-27 23:59:48",1902.5,1912.25,1902.25,1910.75,856198,-15299409.25
"2014-05-28 23:59:59",1910.5,1914,1904.5,1910.75,1040436,-29433824
"2014-05-29 23:59:59",1911,1918,1907.25,1914.5,978236,11588088.75
"2014-05-30 14:14:59",1914.5,1922.25,1914.25,1919,1135223,-108553149.5
"2014-06-01 23:59:57",1921.25,1924.25,1920,1922.75,30480,13675297.5
"2014-06-02 23:59:47",1923,1924.25,1913.75,1920.5,1039326,-110158763.5
"2014-06-03 23:59:59",1920.25,1923.5,1916,1919.75,929758,-78812728.75
"2014-06-04 23:59:55",1920,1927,1916,1925,893019,-31281721.5
"2014-06-05 23:59:27",1925,1942,1921,1940.25,1677761,40396876.75
"2014-06-06 14:14:59",1940.25,1949.75,1938.25,1949.75,1144990,71590518.25
"2014-06-08 23:59:59",1949.25,1950,1947.5,1947.75,24824,-7635679.75
"2014-06-09 23:59:51",1947.5,1954.75,1945.75,1947,963095,-31933452.75
"2014-06-10 23:59:42",1947,1951.75,1943,1948.75,889710,68436261
"2014-06-11 23:59:59",1948.75,1949.25,1938.5,1944.75,1088859,-61271303
"2014-06-12 23:59:57",1944.5,1946.75,1920,1925.75,1265969,-110432688.5
"2014-06-13 14:14:59",1926,1929.75,1919,1927.5,951508,-31127760.5

最佳答案

我相信答案是:

addAct<-newTA(FUN=Activity,legend="Activity",type="h")

enter image description here

我是如何找到这个的:用 google 搜索:quantmod newTA barchart ... 以及这个:http://www.quantmod.com/examples/charting/ 被第二次打击。 (我忽略了第一个点击,b/c 这只是 addTA 的帮助页面,这就是我在系统上首先查看的地方。

关于r - 如何在 quantmod 中将指标显示为直方图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24250029/

相关文章:

r - 基于正则表达式的替换

r - 粘贴到一个新的字符串 var,但被 Lavaan 的新行折叠

r - 如何解决predict()中的错误: subscript out of bounds in R when doing binary classification?

r - 选择具有特定列匹配条件的行

r - 较长的物体长度不是较短的物体长度的倍数吗?

R:如何将 xts 对象转换为数值矩阵?

R - 绘制 xts 和 zoo 对象时如何更改日期格式?

r - quantmod: buildData(,na.rm=FALSE) 丢弃时间序列的头部

r - 试图创造一个滚动周期 cummax