Showing posts with label How to use Vector autoregressive models (VAR) in the stock market. Show all posts
Showing posts with label How to use Vector autoregressive models (VAR) in the stock market. Show all posts

## How to use Vector autoregressive models (VAR) in the stock market.

We get data MSFT from '2004-01-02', to='2019-07-30'
Draw chartSeries(ClCl(MSFT))

> MSFT.M <- to.monthly(MSFT.ret)\$MSFT.ret.Close
ret <- dailyReturn(Cl(MSFT), type='log')
par(mfrow=c(2,2))
> acf(ret, main="Return ACF");
> pacf(ret, main="Return PACF");
> acf(ret^2, main="Squared return ACF");
> pacf(ret^2, main="Squared return PACF")
> par(mfrow=c(1,1))
> m=mean(ret);s=sd(ret);
> par(mfrow=c(1,2))
hist(ret, nclass=40, freq=FALSE, main='Return histogram');curve(dnorm(x,
+      mean=m,sd=s), from = -0.3, to = 0.2, add=TRUE, col="red")
> plot(density(ret), main='Return empirical distribution');curve(dnorm(x,
+     mean=m,sd=s), from = -0.3, to = 0.2, add=TRUE, col="red")

> par(mfrow=c(1,1))
plot(density(ret), main='Return EDF - upper tail', xlim = c(0.1, 0.2),
+      ylim=c(0,2));
> curve(dnorm(x, mean=m,sd=s), from = -0.3, to = 0.2, add=TRUE, col="red")
> plot(density(ret), xlim=c(-5*s,5*s),log='y', main='Density on log-scale')

### Black-Scholes formula-R

Black-Scholes formula-R > BlackScholes <- function(TypeFlag = c("c", "p"), S, X, Time, r, b, sigma) { TypeFla...