我有一个包含以下值的xts对象:Open,High,Low,CLose,Volume和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)
这是我得到的图表: 和数据集:
"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
答案 0 :(得分:2)
我相信答案是:
addAct<-newTA(FUN=Activity,legend="Activity",type="h")
我是如何找到的:使用Google搜索:quantmod newTA barchart
...并且:http://www.quantmod.com/examples/charting/
第二次被击中。 (我忽略了第一次点击b / c它只是addTA的帮助页面,这是我在我的系统上首先看到的地方。