Bitcoin price smoothing 2018-02-26T17:32:28+00:00

Time series smoothing of Bitcoin prices for time period 11-01-2013 and 31-12-2013.

The goal was to smooth the line based on data and on first and averaged observation. Alpha shows the amount of weight we leave to the observation before our actual one.

### Code:

gibanje <- bitcoin[,2]
gibanje <- ts(gibanje)
ts.plot(gibanje,col = "blue",lwd = 1.5, main = "Bitstamp",xlab = "Cas",ylab = "\$")
points(gibanje,pch=20)

#a
G <- function(vrsta, k){
vektor <- rep(NA, length(vrsta))
vektor[1:k] <- vrsta[1:k]

for (i in k:length(vrsta)){
vektor[i] <- sum(vrsta[(i-k+1):i]) * (1/k)
}
return(vektor)
}
#b
red7 <- G(gibanje, 7)

n <- length(red7)
konec <- red7[n]

zglajena <-append(red7[1:n], konec)
zglajena <- ts(zglajena)

ts.plot(gibanje, red7, col = c("blue", "red"),lwd = c(1.5, 1.8),main = "Bitstamp (k = 7)",
xlab = "Cas", ylab = "\$")
points(gibanje,pch=20)

legend("topleft",c("unsmoothed", "smoothed"),col = c("blue", "red"),lwd = 1.5, bty = "n")

#d
krivulja <- ts(red7)
ngibanje <- length(gibanje)
napaka <- sum((gibanje[8:ngibanje]-red7[8:n])^2)/(ngibanje-7)

EG <- function(vrsta, alpha){
vektor <- rep(NA, length(vrsta))
vektor[1] <- vrsta[1]
for (i in 2:length(vrsta)){
vektor[i] <- alpha*vrsta[i] + (1 - alpha)*vektor[i-1]
}
return(vektor)
}

eksponentna <- EG(gibanje, 0.4)

n <- length(eksponentna)