y = read.csv("TPE.csv")
x = y$Close
x = ts(rev(x))
plot(x, main="TPE:TAIEX prices")

logx = log(x)
plot(logx, main="Log TAIEX prices")

trend= time(logx)
fit = lm(logx ~ trend)
plot(logx, main="Log TAIEX with time trend" )
abline(fit, col=2)

# plot the residual
z = ts(resid(fit))
plot(z, type="o", ylab="Residuals",
main="Log SPX with time trend, residuals")

acf(z)

# log returns
r = diff(logx)
plot(r, ylab="Log return", main="Log SPX returns")

acf(r)

mu = mean(r)
z = r - mu
plot(z, main="Random walk with drift, residuals")

acf(z)
