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]] _______________________________________________ [hidden email] 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. |
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" [[hidden email]] Date: 02/05/2017 11:19 AM To: [hidden email] 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]] _______________________________________________ [hidden email] 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. _______________________________________________ [hidden email] 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. |
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 <[hidden email]> 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" [[hidden email]] > Date: 02/05/2017 11:19 AM > To: [hidden email] > 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]] > > _______________________________________________ > [hidden email] 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]] _______________________________________________ [hidden email] 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. |
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 <[hidden email]> 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 <[hidden email]> 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" [[hidden email]] > Date: 02/05/2017 11:19 AM > To: [hidden email] > 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]] > > _______________________________________________ > [hidden email] 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]] _______________________________________________ [hidden email] 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. _______________________________________________ [hidden email] 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. |
Oops. I see that my "ASCII TeX" depiction of the matrix form got scrambled. Oh well. If you follow the link, you can see the matrix form there.
Paul Teetor, Elgin, IL USA http://quantdevel.com/public On Tuesday, February 7, 2017 7:49 PM, Paul Teetor via R-SIG-Finance <[hidden email]> wrote: 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 <[hidden email]> 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 <[hidden email]> 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" [[hidden email]] > Date: 02/05/2017 11:19 AM > To: [hidden email] > 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]] > > _______________________________________________ > [hidden email] 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]] _______________________________________________ [hidden email] 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. _______________________________________________ [hidden email] 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. _______________________________________________ [hidden email] 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. |
Free forum by Nabble | Edit this page |