-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass5_1.R
More file actions
34 lines (24 loc) · 802 Bytes
/
Copy pathclass5_1.R
File metadata and controls
34 lines (24 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# importing the lib
library(sspir)
# creating a seed
set.seed(1)
# creating a synthetic serie
Plummet.dat <- 20 + 2*rnorm(20) + c(rep(0,10), rep(-10,10))
n <- length(Plummet.dat)
Plummet.mat <- matrix(Plummet.dat, nrow = n, ncol = 1)
# plotting the synthetic serie
plot(m1$y, ylab = "Closing price", main = "Simulated")
# training a kalman filter
m1 <- SS(y = Plummet.mat,
Fmat = function(tt,x,phi) return( matrix(1) ),
Gmat = function(tt,x,phi) return( matrix(1) ),
Wmat = function(tt,x,phi) return( matrix(0.1)),
Vmat = function(tt,x,phi) return( matrix(2) ),
m0 = matrix(25), C0 = matrix(10))
# forecasting
m1.f <- kfilter(m1)
# smoother
m1.s <- smoother(m1.f)
# plotting the predictions
lines(m1.f$m, lty = 2)
lines(m1.s$m, lty = 3)