R/bahibo_plot.R

Defines functions bahibo.plot

Documented in bahibo.plot

bahibo.plot <- function(coin="Bitcoin",currency="EUR",quote="Open",log=FALSE){
  if(currency!="EUR" & currency != "USD"){
      stop("currency no found")
  }
  if(currency!="EUR" & currency != "USD") stop("currency no found")
  name<-bahibo.coins()
  if(coin%in%name==F & coin %in% paste(tolower(substr(name, 1, 1)), substr(name, 2, nchar(name)), sep="") ==F) stop("Coin not found - use bahibo.coins() to see all available coins")

  if (!require("zoo")) install.packages("zoo")
  library(zoo)
  coin_hist<-bahibo.hist(coin=coin,currency = currency,quote = quote)
 # coin_hist<-zoo(coin_hist,as.Date(rownames(coin_hist)))

  coin_hist<-log(coin_hist)
  r<-diff(coin_hist)
  n<-length(r)
  par(mfrow=c(2,1))
  if(log==F){
    coin_hist<-exp(coin_hist)
    r<-exp(r)-1
  }
  d<-mean(r)
  plot.zoo(coin_hist,main = paste(coin, ifelse(log==T, "log",""), "Chart and returns",quote),ylab = ifelse(log==T, "log Price","Price"),col = "blue",las=1,bty="n",xlab="Jahre")

  plot.zoo(r,ylab = "returns",col = "blue",las=1,bty="n",xlab="Jahre",
           main=paste("Returns"))
  abline(h=0,col="gray")
  par(mfrow=c(1,1))
  coin<-cbind(coin_hist[2:(n+1)],r)
  colnames(coin)<-c(quote,"returns")
  return(coin)

}
StephanBahibo/Bahibo documentation built on Feb. 13, 2022, 9:13 a.m.