Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (29 sloc) 7.25 KB
library("TTR")
#data(ttrc)
#ohlc <- ttrc[,c("Open", "High", "Low", "Close")]
#Open = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 4)
#High = c(2, 3, 4, 2, 3, 4, 2, 3, 4, 5)
#Low = c(1, 2, 3, 2, 3, 4, 5, 2, 1, 4)
#Close = c(3, 2, 1, 3, 4, 2, 1, 4, 2, 3)
#ohlc <- data.frame(Open, High, Low, Close)
Open = c(115100,126640,123500,131470,126720,125670,124000,125330,122750,124100,124130,125920,123000,119320,116550,104220,106770,107730,109000,108010,109230,112490,110020,116000,114370,115160,115600,115900,115100,114000,112500,114400,114800,112300,110750,104450,109000,108340,108860,110240,111830,113000,111990,114500,114100,117500,117540,115000,115000,112000,110500,111730,113500,112200,112270,107470,107580,105540,108280,104760,105100,105900,104500,105000,108250,107200,105510,107800,105870,103760,104720,103060,103940,106100,107500,109350,109960,111990,112300,112120,112360,113500,116500,116790,114000,116030,112160,110500,113210,114280,110750,114970,110770,111500,108730,111260,112500,108960,114620,113880,110310,108650,108410,107150,105810,103310,105030,105700,108050,111500,113450,111460,112700,113950,113870,115000,115820,116000,115900,114800,117880,117410,118230,118900,119250,117610,116840,116300,117550,114100,113430,114940,116940,116660,117050,116520,116940,115650,115630,114940,115510,115410,114800,115600,115510,115570,115120,116160,118560,118400,118600,119900,117310,119020,118760,117120,116950,115750,117570,117740,118350,117820,118500,119450,119760,121820,120330,121300,120320,121590,121950,121680,121890,123350,123290,121560,120360,120170,120940,120000,119660,121210,120230,119400,119300,117880,117200,120350,120320,121590,120720,120690,123030,124360,122430,123050,123700,122160,122550,123510,123490,126400,125650,125580,127460,128070,128710,130910,131270,131020,131180,132660,133170,136090,134480,135810,135430,136200,136150,135230,137550,136690,137120,138430,137210)
High = c(116000,127010,123500,131470,126720,126400,124250,125330,122750,124150,124130,125920,123000,119320,116550,104220,107000,110650,109000,108010,109500,112490,110020,116000,115280,115160,115600,115900,115100,114000,112500,114800,114850,112300,110750,113940,109200,110620,110200,110240,112530,113000,111990,115290,116500,117500,117540,115000,115130,112000,110500,111730,113500,112200,113330,107470,107580,106930,108580,105790,105100,105900,106000,105000,108250,107200,111960,107800,105870,103760,106100,103630,103940,106100,107500,110160,109960,112000,112300,112120,112360,113500,116500,116790,114000,116030,112160,110500,113500,114280,110750,114970,110770,111500,108730,111260,112500,108960,114870,113880,110310,108650,108570,107150,105810,103310,105150,105700,108100,111720,113450,112540,112700,113990,113870,115000,115820,116410,115900,114800,118000,118740,118500,118900,119250,117610,116840,117280,117550,114100,113430,115940,117370,116940,117940,116520,116940,115650,115940,115800,115510,115800,114890,116060,115790,115900,116000,118670,118900,118990,120560,120200,119130,119580,118950,117500,118280,117790,118000,119000,118350,118500,119300,120580,121790,122000,121830,121700,121520,122600,122390,122210,123500,124110,123690,121560,120550,121200,121300,120800,121000,121440,120720,120000,119410,118500,120500,121000,121990,121590,121580,123150,124760,124520,124070,123770,124050,122920,124130,124070,127300,127260,126640,128060,128670,130070,131630,131490,132690,132330,133110,133850,136650,136370,136350,136560,136390,137080,136780,138360,137910,137730,138580,138850,138310)
Low = c(115100,126430,123500,131470,126720,125150,124000,125230,122750,124000,124130,125920,123000,119320,108110,104220,106600,107730,109000,106670,109200,112490,110020,116000,114370,115160,115600,114570,114990,114000,112500,114400,114800,112300,110330,104000,108620,107600,108580,110240,111530,113000,111180,114500,114100,117500,117540,115000,110300,112000,110500,111730,113500,112200,110430,107470,106000,105540,108280,104640,105100,105000,104500,105000,106050,107200,105510,107500,105870,103550,104720,103060,103450,106100,107500,108200,109650,111990,110470,112120,112100,113500,115900,114690,114000,114520,112160,110500,113210,114280,110750,114970,110770,111500,108730,111260,112500,106160,113440,112850,108690,108070,107920,106980,105810,103310,105030,105700,108050,111500,111390,111460,112700,113950,113870,115000,115820,115350,115900,114800,117880,117410,117570,118750,117810,117610,116200,116300,117000,113100,113430,114940,115940,116660,116940,115940,115810,115650,115450,114940,115510,115080,114250,115200,114770,115400,115120,116160,118200,117900,118600,117000,116770,118450,117000,116690,115550,115750,117000,117620,117270,117630,118440,119390,119570,120400,119850,120000,120060,121550,121150,121670,121720,122800,121470,120200,119690,119950,120050,119430,119660,118750,119380,118950,117150,117000,117110,119620,120080,120420,120330,120630,122640,121980,121880,122960,121590,121390,122540,122070,122450,125180,125200,125370,127330,127870,128450,129910,130970,130530,127100,132610,132710,133800,134350,134460,134470,135270,135160,134600,136370,136130,137120,137210,136600)
Close = c(116000,127010,123500,131470,126720,125150,124250,125330,122750,124000,124130,125920,123000,119320,108110,104220,106600,110590,109000,106670,109500,112490,110020,116000,115280,115160,115600,114570,114990,114000,112500,114800,114850,112300,110330,104000,108620,108350,110200,110240,112530,113000,111180,115030,116500,117500,117540,115000,115130,112000,110500,111730,113500,112200,110430,107470,106000,106930,108580,105790,105100,105000,106000,105000,106480,107200,107900,107500,105870,103550,106100,103630,103450,106100,107500,109460,109650,112000,110470,112120,112100,113500,116000,114690,114000,114650,112160,110500,113500,114280,110750,114970,110770,111500,108730,111260,112500,106160,113440,113500,108690,108070,108100,107140,105810,103310,105070,105700,108100,111720,111390,112540,112700,113990,113870,115000,115820,115900,115900,114800,118000,118010,117570,118750,118970,117610,116200,117280,117000,113370,113430,115700,115940,116940,117130,115940,115810,115650,115940,115690,115510,115120,114730,116060,115790,115590,116000,118170,118270,118990,119830,117270,119130,119300,117060,116810,115960,117790,117400,118520,117990,118460,119300,119500,121650,120400,120600,120270,121250,121980,121690,121870,123340,123320,121720,120200,120150,121030,120350,119630,121000,120240,119720,119740,117680,117700,120500,120520,121640,120770,121120,123100,124690,122500,122990,123650,123540,122600,123600,123880,126740,125720,125630,127540,128200,128650,130800,131430,131030,131300,132780,132960,136030,134450,135690,135370,136070,136130,135280,137710,136610,137170,138470,137260,138220)
ohlc <- data.frame(Open, High, Low, Close)
vClose <- volatility(ohlc, calc = "close")
vGK <- volatility(ohlc, calc = "garman")
vP <- volatility(ohlc, calc = "parkinson")
vRS <- volatility(ohlc, calc = "rogers")
vYZ <- volatility(ohlc, calc = "yang.zhang")
vYZ2 <- volatility(ohlc, calc = "yang.zhang", n = 30)
#plot(xrange, yrange, type = "n", xlab = "Strike", ylab = "Volatility")
#par(mfrow=c(2,1))
plot(vClose, type = "lines", xlab = "Day", ylab = "Volatility")
#points(vGK, type = "lines", col = "yellow")
#points(vP, type = "lines", col = "blue")
#points(vRS, type = "lines", col = "orange")
points(vYZ, type = "lines", col = "red")
#points(vYZ2, type = "lines", col = "green")
#plot(Open, type = "lines")
#bbands <- BBands(ttrc[,c("High","Low","Close")])
You can’t perform that action at this time.