# Cut-and-Paste Code Below into Window Above and Run
#
#
# WL20 Model
#
# Measurement Matrix
# N OIL QA GWP P.Wheat. P.Oil. TEMP CO2
#[1,] 0.28446 0.2711 0.28207 0.28244 0.2363 0.24296 0.2514 0.28373
#[2,] -0.01609 0.2410 0.09854 -0.14132 0.4114 0.06595 -0.2352 -0.09833
#[3,] -0.11117 -0.2412 -0.08826 0.02134 0.4611 0.71182 0.1901 -0.02010
# Carbon TotalFootprint Earths WorldGlobal LivingPlanet URBAN
#[1,] 0.28329 0.2752 0.2788 0.28190 -0.1839 0.28401
#[2,] 0.09253 0.1817 0.1484 -0.09257 0.7705 -0.08681
#[3,] -0.09554 -0.2926 -0.2312 -0.09432 -0.0576 -0.07068
#
# Fraction of Variance
# [1] 0.8741 0.9414 0.9725 0.9865 0.9949 0.9980 0.9987 0.9993 0.9998 0.9999
#[11] 1.0000 1.0000 1.0000 1.0000
#
merge.forecast <- function (fx,n=1) {
# Merges a forecast with the outputdata
x <- splice(fx$pred,fx$forecast[[n]])
colnames(x) <- seriesNames(fx$data$output)
return(x)
}
#
AIC <- function(model) {informationTestsCalculations(model)[3]}
require(dse)
require(matlab)
#
f <- matrix( c( 1.01169571, -0.02519461, -0.09358484, 0.210941578,
-0.01360718, 0.9633012,9 -0.05250691, -0.003862528,
0.02303607, -0.03631204, 0.93554760, 0.018115378,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To Stabilize
# Uncomment next line
# f[1,1] <- 0.959503994
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
US_E20 <- SS(F=f,H=h,K=k,z0=c( 0.210941578, -0.003862528, 0.018115378 , 1.0000000000),
output.names=c("W1","W2","W3"))
stability(m0 <- SS(F=f[1:3,1:3,drop=FALSE],Q=eye(3),R=eye(3),H=eye(3)))
W20.data <- simulate(W20,sampleT=50,start=1950)
#W20.data <- simulate(W20,sampleT=100,noise=matrix(0,50,3),start=1950
W20.f <- forecast(m <- l(W20,W20.data),horizon=150)
W20.fx <- merge.forecast(W20.f)
#
# USL20 Model W Input
#
# Measurement Matrix
# L.US.E. L.US.U. GDP.US. GDP.C. GDP.I. GDP.X. GDP.G. P.US.TBILL.
#[1,] 0.19546 0.1383 0.19785 0.19720 0.19613 -0.14024 0.19755 0.004288
#[2,] 0.06686 0.2001 -0.04622 -0.05545 -0.03549 0.07506 -0.03769 0.405829
#[3,] -0.03120 0.2391 0.02841 0.03142 -0.02725 0.22293 0.05408 0.076302
# P.CPAPER. P.FED.FUNDS. P.CPI. P.GDP. P.SP500. V.NYSE. P.S.P.DPR.
#[1,] -0.015537 0.01268 0.197726 0.19669 0.18676 0.1665 -0.1465
#[2,] 0.404602 0.39980 0.009961 0.03367 -0.10756 -0.1308 0.1439
#[3,] -0.001645 0.09859 0.021283 0.02397 -0.02767 0.1648 0.3207
# P.S.P.EPR. Q.H.Starts. K.US. M1 M2 P.WPI. Q.A.
#[1,] -0.1120 -0.02017 0.19737 0.19528 0.19789 0.19320 0.19179
#[2,] 0.1279 0.03917 -0.04176 -0.01451 -0.03248 0.06118 0.07664
#[3,] 0.3836 -0.46661 0.04462 -0.03176 0.04718 0.10505 -0.09728
# Q.I. O.B. P.FUELS. P.W.AG. P.W.MFG. Q.OIL. N.US. IMM.US.
#[1,] 0.19672 -0.1731 0.18336 0.19833 0.19895 -0.1126 0.19512 0.14399
#[2,] 0.03742 0.1857 0.02689 0.01310 0.01245 0.3121 0.07460 0.05456
#[3,] -0.06831 0.1097 0.25385 0.04888 0.02323 -0.1447 -0.06417 -0.13711
# U.US. CAPU EF Globalization CO2 Q.FOSSIL.
#[1,] 0.19673 -0.1406 0.18666 0.0818 0.1801 0.1295
#[2,] 0.04773 -0.1533 0.10962 -0.2964 0.1548 0.2830
#[3,] -0.05889 -0.1643 0.03031 0.3905 -0.1105 -0.1573
#
# Fraction of Variance
# [1] 0.6979 0.8536 0.9002 0.9353 0.9553 0.9716 0.9811 0.9873 0.9914 0.9951
#[11] 0.9969 0.9976 0.9982 0.9987 0.9990 0.9992 0.9994 0.9996 0.9997 0.9998
#[21] 0.9999 0.9999 0.9999 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
#
AIC <- function(model) {informationTestsCalculations(model)[3]}
require(dse)
require(matlab)
f <- matrix( c( 0.5993137, -0.08325704, 0.07420381, 0.1123508,
-0.4766593, 0.83054492, -0.07921798, -0.1929930,
-0.7525190, -0.18823708, 0.73844550, -0.3359805,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To Create Unstable Financial Cycles
# f[2,2] <- 1.122382
#
g <- matrix(c( 0.5913321, -0.22386288, 0.05433903,
0.6017352, -0.02270588, 0.11537732,
1.0628688 ,-0.13003713, 0.99187814,
0.000000, 0.0000000 , 0.000000
),byrow=TRUE,nrow=4,ncol=3)
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
USL20 <- SS(F=f,H=h,K=k,G=g,z0=c(5.299885, -5.977458, -3.899165, 1.0000000000),
output.names=c("US1","US2","US3"))
stability(m0 <- SS(F=f[1:3,1:3,drop=FALSE],Q=eye(3),R=eye(3),H=eye(3)))
print(USL20)
is.SS(USL20)
USL20.data <- simulate(USL20,input=WL20.fx)
tfplot(outputData(USL20.data))
AIC(l(USL20,USL20.data))
shockDecomposition(m0)