Showing posts with label How to generate the two time series. Show all posts
Showing posts with label How to generate the two time series. Show all posts

## Generate the two time series length 999

Fixed random seeds
set.seed(20140625)
Define length of simulation
> N <- 999
Simulate normal random walk
> x <- cumsum(rnorm(N))
Set an initial parameter
> gamma <- 0.7
Get cointegrating series
> y <- gamma * x + rnorm(N)
plot the two series
> plot(x, type='l')
> lines(y,col="green")
summary(ur.df(x,type="none"))

###############################################

#### # Augmented Dickey-Fuller Test Unit Root Test #

###############################################

Test regression none

Call:
lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)

Residuals:
Min      1Q  Median      3Q     Max
-2.9293 -0.6857 -0.0430  0.6568  3.0650

Coefficients:
Estimate Std. Error t value
z.lag.1    -0.002151   0.002995  -0.718
z.diff.lag  0.015978   0.031770   0.503
Pr(>|t|)
z.lag.1       0.473
z.diff.lag    0.615

Residual standard error: 0.9896 on 995 degrees of freedom
Multiple R-squared:  0.0007246, Adjusted R-squared:  -0.001284
F-statistic: 0.3608 on 2 and 995 DF,  p-value: 0.6972

Value of test-statistic is: -0.7182

Critical values for test statistics:
1pct  5pct 10pct
tau1 -2.58 -1.95 -1.62

### summary(ur.df(y,type="none"))

###############################################
# Augmented Dickey-Fuller Test Unit Root Test #
###############################################

Test regression none

Call:
lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)

Residuals:
Min      1Q  Median      3Q     Max
-4.9951 -1.0130  0.0000  0.9533  4.2422

Coefficients:
Estimate Std. Error t value
z.lag.1    -0.010684   0.006218  -1.718
z.diff.lag -0.391398   0.029214 -13.398
Pr(>|t|)
z.lag.1      0.0861 .
z.diff.lag   <2e-16 ***
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’
0.1 ‘ ’ 1

Residual standard error: 1.448 on 995 degrees of freedom
Multiple R-squared:  0.1606, Adjusted R-squared:  0.1589
F-statistic: 95.18 on 2 and 995 DF,  p-value: < 2.2e-16

Value of test-statistic is: -1.7182

Critical values for test statistics:
1pct  5pct 10pct
tau1 -2.58 -1.95 -1.62
The test statistics is larger than the critical value at the significance level.so
we can't reject the null hypothesis.

#### Now take a linear combination of two series

> z = y - gamma*x
> plot(z,type='l')

### Black-Scholes formula-R

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