price = read.csv('index.csv')
y=diff(log(price$Index)) # calculate returns
plot(y) # plot returns
using CSV, DataFrames;
price = CSV.read("index.csv",DataFrame)
y = diff(log.(price[:,1]))
using Plots;
plot(y, title = "S&P500 returns", legend = false)
library(moments)
library(tseries)
mean(y)
sd(y)
min(y)
max(y)
skewness(y)
kurtosis(y)
jarque.bera.test(y)
using Statistics, StatsBase;
println("Standard deviation: ", std(y), "\n")
println("Minimum value: ", minimum(y), "\n")
println("Maximum value: ", maximum(y), "\n")
println("Skewness: ", skewness(y), "\n")
println("Kurtosis: ", kurtosis(y), "\n")
println("Autocorrelation of returns:", "\n", autocor(y, 1:20), "\n")
println("Autocorrelation of returns squared:", "\n", autocor(y.^2, 1:20), "\n")
using HypothesisTests;
println(JarqueBeraTest(y))
println(LjungBoxTest(y,20))
println(LjungBoxTest(y.^2, 20))
library(MASS)
library(stats)
par(mfrow=c(1,2), pty="s")
q = acf(y,20)
q1 = acf(y^2,20)
Box.test(y, lag = 20, type = c("Ljung-Box"))
Box.test(y^2, lag = 20, type = c("Ljung-Box"))
q1 = autocor(y, 1:20)
q2 = autocor(y.^2, 1:20)
plot(bar(q1, title = "ACF of returns"),
bar(q2, title = "ACF of returns squared"), legend = false)
library(car)
par(mfrow=c(1,2), pty="s")
qqPlot(y)
qqPlot(y,distribution="t",df=5)
using StatsPlots, Distributions;
plot(qqplot(Normal,float(y),qqline=:quantile, title = "QQPlot vs Normal"),
qqplot(TDist(5),float(y),qqline=:quantile, title = "QQPlot vs Student-t(5)"),
qqplot(TDist(4),float(y),qqline=:quantile, title = "QQPlot vs Student-t(4)"),
qqplot(TDist(3),float(y),qqline=:quantile, title = "QQPlot vs Student-t(3)"))
p = read.csv('stocks.csv')
y=apply(log(p),2,diff)
print(cor(y)) # correlation matrix
price = CSV.read("stocks.csv", DataFrame)
y1 = diff(log.(price[:,1]))
y2 = diff(log.(price[:,2]))
y3 = diff(log.(price[:,3]))
y = hcat(y1,y2,y3)
println(cor(y)) # correlation matrix