[R-SIG-Finance] Estimating a one-factor model using the DLM package
Paul Teetor
paulteetor at yahoo.com
Wed Feb 8 02:46:38 CET 2017
Hannu,
The MARSS package could solve your problem, but it seems like over-kill for a simple model like this.
I wrote some R code to demonstrate using dlm to fit your model. You can see the code here.
http://bit.ly/spreadModel-dlm
The code fits all three parameters: a, b, and c; plus the variances and initial value.
I did not have much time to test the code, but it seems to run correctly. To use dlm, I
had to put your model into this matrix form:
# _ _
# | |
# y[t] = [a, b] * | 1 | + u[t]
# | |
# | s[t] |
# |_ _|
#
# _ _ _ _ _ _ _ _
# | | | | | | | |
# | 1 | | 1 0 | | 1 | | 0 |
# | | = | | * | | + | |
# | s[t] | | 0 c | | s[t-1] | | v[t] |
# |_ _| |_ _| |_ _| |_ _|
#
Good luck. I hope your model works well.
Paul
Paul Teetor, Elgin, IL USA
http://quantdevel.com/public
On Tuesday, February 7, 2017 10:57 AM, Hannu Kahra <hkahra at gmail.com> wrote:
I specify the problem more clearly. My model is
y(t) = a + b*s(t) + u(t)
s(t) = c*s(t-1) + v(t)
that is a stochastic linear trend model in the DLM package obtained by
setting dlmModPoly(order = 2). The parameters b and c are fixed to 1 by
construction. In my problem I can allow b = 1, but I would like to estimate
c in the state equation. In other applications, I want to estimate
parameter b in the signal equation, as well.
I have had a look at the MARSS package and it seems that b and c can be
free parameters in estimation.
Hannu
On Tue, Feb 7, 2017 at 3:53 PM, ce <zadig_1 at excite.com> wrote:
>
> Not sure what you want to do but dlmMLE function would estimate some
> parameters to start, and dlmFilter and dlmForecast would predict expected
> values. DLM would need some study .
> Documents in https://cran.r-project.org/package=dlm are a good start ,
> also the book "Dynamic Linear Models with R", ISBN 978-0-387-77237-0
> e-ISBN 978-0-387-77238-7
>
> -----Original Message-----
> From: "Hannu Kahra" [hkahra at gmail.com]
> Date: 02/05/2017 11:19 AM
> To: r-sig-finance at r-project.org
> Subject: [R-SIG-Finance] Estimating a one-factor model using the DLM
> package
>
> Hi,
>
> I am trying to estimate a one-factor model of the spread y(t) between two
> interest rates
>
> y(t) = a + b*s(t) + u(t)
> s(t) = c*s(t-1) + v(t)
>
> using the DLM package in R. Is it possible to estimate the parameters a, b,
> c, and var(u(t)). Var(v(t)) = 1.
>
> I have EViews code for that and I want to replicate it using R.
>
> Hannu
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org 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.
>
>
>
>
[[alternative HTML version deleted]]
_______________________________________________
R-SIG-Finance at r-project.org 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.
More information about the R-SIG-Finance
mailing list