Mathematics, Science, statistics, economics, finance, econometrics, Business Mathematics, statistical analysis, R language, Computer Science, Stock Analysis, APPLE Stock Analysis, Amazon stock Analysis, GARCH model, Arch model,q-q plot,ols, regression, Time Series, t-test, cofactor, variance, standard deviation,Matlab,Nifty 50 Analysis,BMW stock analysis,

Email Subscribers

Enter your email address:

Delivered by FeedBurner

Wednesday, 30 October 2019

Linear filtering to a univariate 'timeSeries'

Applies linear filtering to a univariate 'timeSeries'

timeSeries

> x <- MSFT[1:12, ]
> x
GMT
              Open    High     Low   Close   Volume
2000-09-27 63.4375 63.5625 59.8125 60.6250 53077800
2000-09-28 60.8125 61.8750 60.6250 61.3125 26180200
2000-09-29 61.0000 61.3125 58.6250 60.3125 37026800
2000-10-02 60.5000 60.8125 58.2500 59.1250 29281200
2000-10-03 59.5625 59.8125 56.5000 56.5625 42687000
2000-10-04 56.3750 56.5625 54.5000 55.4375 68226700
2000-10-05 55.5000 57.2500 55.2500 55.3750 40549700
2000-10-06 55.8125 56.7500 54.7500 55.5625 30897000
2000-10-09 55.6250 55.7500 53.0000 54.1875 29161800
2000-10-10 53.9375 55.5625 53.8125 54.5625 31033100
2000-10-11 54.0000 56.9375 54.0000 55.7500 50602900
2000-10-12 56.3125 56.8750 53.8125 54.3750 45109800
> X <- cbind(x[, "Open"], returns(x[, "Open"]))
> colnames(X) <- c("Open", "Return")
> x
GMT
              Open    High     Low   Close   Volume
2000-09-27 63.4375 63.5625 59.8125 60.6250 53077800
2000-09-28 60.8125 61.8750 60.6250 61.3125 26180200
2000-09-29 61.0000 61.3125 58.6250 60.3125 37026800
2000-10-02 60.5000 60.8125 58.2500 59.1250 29281200
2000-10-03 59.5625 59.8125 56.5000 56.5625 42687000
2000-10-04 56.3750 56.5625 54.5000 55.4375 68226700
2000-10-05 55.5000 57.2500 55.2500 55.3750 40549700
2000-10-06 55.8125 56.7500 54.7500 55.5625 30897000
2000-10-09 55.6250 55.7500 53.0000 54.1875 29161800
2000-10-10 53.9375 55.5625 53.8125 54.5625 31033100
2000-10-11 54.0000 56.9375 54.0000 55.7500 50602900
2000-10-12 56.3125 56.8750 53.8125 54.3750 45109800
> Y <- rbind(x[1:3, "Open"], x[10:12, "Open"])
> Y
GMT
           Open_Open
2000-09-27   63.4375
2000-09-28   60.8125
2000-09-29   61.0000
2000-10-10   53.9375
2000-10-11   54.0000
2000-10-12   56.3125
> range <- High - Low
Error: object 'High' not found
> X = MSFT[, 1:4]
> X = 100 * returns(X)
> cov(X[, "Open"], X[, "Close"])
        Close
Open 5.370449
> cov(X)
           Open     High       Low     Close
Open  12.024989 7.717341  9.072359  5.370449
High   7.717341 8.566159  8.007279  7.931451
Low    9.072359 8.007279 10.543072  8.505720
Close  5.370449 7.931451  8.505720 11.676740
> x = MSFT[1:20, "Open"]
> lag(x, k = -1:1)
GMT
           Open[-1] Open[0] Open[1]
2000-09-27  60.8125 63.4375      NA
2000-09-28  61.0000 60.8125 63.4375
2000-09-29  60.5000 61.0000 60.8125
2000-10-02  59.5625 60.5000 61.0000
2000-10-03  56.3750 59.5625 60.5000
2000-10-04  55.5000 56.3750 59.5625
2000-10-05  55.8125 55.5000 56.3750
2000-10-06  55.6250 55.8125 55.5000
2000-10-09  53.9375 55.6250 55.8125
2000-10-10  54.0000 53.9375 55.6250
2000-10-11  56.3125 54.0000 53.9375
2000-10-12  53.8750 56.3125 54.0000
2000-10-13  53.5000 53.8750 56.3125
2000-10-16  51.8750 53.5000 53.8750
2000-10-17  49.6250 51.8750 53.5000
2000-10-18  58.4375 49.6250 51.8750
2000-10-19  61.3125 58.4375 49.6250
2000-10-20  64.6250 61.3125 58.4375
2000-10-23  62.6250 64.6250 61.3125
2000-10-24       NA 62.6250 64.6250
> data <- matrix(rnorm(100), ncol = 2)
> s <- timeSeries(data, units=c("A", "B"))
> head(s)

               A           B
[1,]  1.34501889 -0.01515725
[2,] -0.83806595 -0.50574314
[3,]  0.11467005 -0.83601647
[4,] -1.92993351  0.73093456
[5,]  0.88410486 -0.36609669
[6,]  0.09300388 -0.04980351
> f <- filter(s, rep(1, 3))
> head(f)

              A          B
[1,]         NA         NA
[2,]  0.6216230 -1.3569169
[3,] -2.6533294 -0.6108251
[4,] -0.9311586 -0.4711786
[5,] -0.9528248  0.3150344
[6,]  1.4894797 -0.9541888
> plot(cbind(s[, 1], f[, 1]), plot.type="s")

No comments:

Post a Comment

Greeks in the option market

How to calculate greeks in the option market  plotbullcall(s= 100, x1 = 95, x2 = 105, t = (45/365), r = 0.02,sigma = 0.20, sigma2 = 0...