Copyright 2011 - 2019 Jon Danielsson. This code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The GNU General Public License is available at: https://www.gnu.org/licenses/.

Last updated August 2019

```
price = read.csv('index.csv')
y=diff(log(price$Index)) # calculate returns
plot(y) # plot returns
```

Last updated June 2018

```
using CSV;
price = CSV.read("index.csv", nullable = false);
y = diff(log.(price[:,1]));
using Plots;
plot(y)
```

Last updated August 2019

```
library(moments)
library(tseries)
mean(y)
sd(y)
min(y)
max(y)
skewness(y)
kurtosis(y)
acf(y,1)
acf(y^2,1)
jarque.bera.test(y)
Box.test(y, lag = 20, type = c("Ljung-Box"))
Box.test(y^2, lag = 20, type = c("Ljung-Box"))
```

Last updated June 2018

```
using StatsBase;
println(std(y))
println(minimum(y))
println(maximum(y))
println(skewness(y))
println(kurtosis(y))
println(autocor(y, 1:20))
println(autocor(y.^2, 1:20))
using HypothesisTests;
println(JarqueBeraTest(y))
println(LjungBoxTest(y,20))
println(LjungBoxTest(y.^2, 20))
```

Last updated August 2019

```
library(MASS)
library(stats)
par(mfrow=c(1,2), pty="s")
q = acf(y,20)
q1 = acf(y^2,20)
```

Last updated June 2018

```
using Plots;
q1 = autocor(y, 1:20)
q2 = autocor(y.^2, 1:20)
plot(bar(q1), bar(q2))
```

Last updated June 2018

```
library(car)
par(mfrow=c(1,2), pty="s")
qqPlot(y)
qqPlot(y,distribution="t",df=5)
```

Last updated June 2018

```
using Plots, StatPlots, Distributions;
plot(qqplot(Normal,float(y),qqline=:quantile), qqplot(TDist(5),float(y),qqline=:quantile))
```

Last updated June 2018

```
p = read.csv('stocks.csv')
y=apply(log(p),2,diff)
print(cor(y)) # correlation matrix
```

Last updated June 2018

```
using CSV;
price = CSV.read("stocks.csv",nullable=false)
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
```