Entry 5146
przykladowy
Submitted by test
on July 18, 2010 at 10:37 a.m.
Language: S. Code size: 2.0 KB.
cr_ex = function(spk, last = 7, adn=1){ library(Hmisc) #EKSPORT FOR PNG FILES spk=deparse(substitute(spk)) #spk= "emk" #nam=spk #tyt=eval(as.character(deparse(quote(spk)))) initial.dir<-getwd() #save(cr,adnot, file = "E:/Stock_investing/R_test/qmodt.Rdata") path = "E:/Stock_investing/R_test/" setwd(path) #~ if(is.null(dev.list())==TRUE){win.graph(width = 12, height = 7, pointsize = 10)} #Eksport to PNG png(file=paste(spk,".png"), width=1024, height=700) cmd = paste("zip_for_charts.py ", spk, sep="") if(adn==0){cmd = paste(cmd, '0')} sys(cmd, text=NULL, output=TRUE) mytab = read.table( paste(path,"res.txt",sep=""), header=FALSE, sep="," , stringsAsFactors=FALSE, colClasses=c("character",c(rep("numeric",6))) ) # kolejnosc OHLC jest pomieszana tj. 0LHC ! test = xts(mytab[,c(2,4,3,5,6,7)], as.Date(as.character(mytab[,1]), format="%Y%m%d")) qmod = as.quantmod.OHLC(test, col.names = c( "Open", "High","Low", "Close", "Volume", "Adjusted")) sbs = sub("@", last, '@ months') qmod2 = last(qmod, sbs) #print(sbs) them = chartTheme("black", border='#999999', grid.col='#363636', major.tick='#9C9C9C', minor.tick='#CDC0B0', dn.border='#8B2323', up.up.col="#FFFFCC", #zmiana trendu, dn.up.border="#B5B5B5", dn.up.col="#DCDCDC", # close< open up.dn.col="#FFC1C1", dn.dn.col="#FF9999", dn.dn.border="#A52A2A" ) chartSeries(qmod2, name = spk, log.scale = TRUE, theme =them, multi.col = TRUE, TA=NULL ) addVo(); addSMA(30); zm = as.double(dailyReturn(last(qmod, '2 days'))[2]*100) zm_prc = sprintf("%.2f%%", zm) etyk = paste(zm_prc, spk) mtext(etyk, side=3, cex = 0.8 , col=ifelse(zm>= 0, "green","red"), adj = 0.03 , padj=0.5 , font = 2) #Comment when exporting to file #~ bringToTop(which = dev.cur(), stay = FALSE) if(adn==0){adnot()} #setwd(initial.dir) dev.off() }
This snippet took 0.01 seconds to highlight.
Back to the Entry List or Home.