OK! Here are some codes to help you understand my previous questions:
library(mgcv)
library(tseries)
# download some test data from YAHOO
spc <- get.hist.quote(instrument = "^gspc", start = "2000-01-01", quote = "Close")
ibm <- get.hist.quote(instrument = "ibm", start = "2000-01-01", quote = "AdjClose")
t30 <- get.hist.quote(instrument = "^TYX", start = "2000-01-01", quote = "Close")
RM <- (diff(log(spc)) - t30 / 365)*100.0 # let's say this is excess market return
R_IBM <- (diff(log(ibm)) - t30 / 365)*100.0 # individual stock's excess return
t <- 1:length(RM) # time trend
output <- gam(R_IBM ~ RM + s(t, by=RM)) # the code in the paper
plot(output, rug=F, ylab="Time-Varying Beta") # beta looks two low
output <- gam(R_IBM ~ s(t, by=RM))
plot(output, rug=F, ylab="Time-Varying Beta")
# now reasonable but I want time-axis like 2000 2001 ... 2010
Any help would be appreciated!
? ? ? ?[[alternative HTML version deleted]]
_______________________________________________
R-SIG-Finance at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Just a quick note to point out that your code didn't run for me.
- Mark
library(mgcv)
This is mgcv 1.6-1. For overview type `help("mgcv-package")'.
library(tseries)
Loading required package: quadprog
Loading required package: zoo
?tseries? version: 0.10-22
?tseries? is a package for time series analysis and computational
finance.
See ?library(help="tseries")? for details.
Warning messages:
1: package 'tseries' was built under R version 2.11.1
2: package 'zoo' was built under R version 2.11.1
# download some test data from YAHOO
spc <- get.hist.quote(instrument = "^gspc", start = "2000-01-01", quote = "Close")