Google Answers Logo
View Question
 
Q: Kalman Filter implementation ( No Answer,   2 Comments )
Question  
Subject: Kalman Filter implementation
Category: Science > Math
Asked by: finmodeler-ga
List Price: $100.00
Posted: 07 Aug 2004 09:12 PDT
Expires: 06 Sep 2004 09:12 PDT
Question ID: 384718
Question for mathtalk-ga please.

Some time ago you answered a question on implementing Kalman filtering
(posed by asiatechnicals-ga).  I am developing an implementation of a
model for commodity prices, and I need some help in developing an
agorithm to support testing of my implementation with real data.

I am proficient in Excel and VBA (so would prefer to work in that
platform) and I have some background in econometrics and mathematical
statistics (but very little background with Kalman filtering).

My question is: Help me implement a Kalman filter in Excel/VBA that
will estimate the parameters of given stochastic process with Maximum
Likelihood techniques.  I have worked through and understood the model
you developed for asiatechnicals-ga, and this could be an extension of
that.  The differences in this case are:

1) the data needs to be a time series of commodity futures prices,
with several different maturities for each time.  I can send you an
example data set.

2) the stochastic process for the evolution of futures prices is
known, but the parameters need to be estimated (using maximum
likelihood).  I will give you the state-space formulation of the
particular stochastic process I am using.

The deliverables are: Similar to what you developed for
asistechnicals-ga - A file, VBA listing, detailed and simple
instructions for entering formulae, or whatever it takes for me to
have a working, modifiable, Excel implementation.

Fees
====

I am offering a rate of $20 per hour, on the basis of five chargeable
hours work ($100).  I am willing to negotiate if the work takes longer
than I have anticipated.

Request for Question Clarification by mathtalk-ga on 07 Aug 2004 14:20 PDT
Hi, finmodeler-ga:

Estimating the parameters is the hard part, isn't it?  I'm not sure
how I can best help.  If you describe the stochastic process that
models the pricing and post a link where I can download a data sample,
I'll be glad to take a look.

regards, mathtalk-ga

Clarification of Question by finmodeler-ga on 07 Aug 2004 15:06 PDT
I have an excel file with data, as well as a pdf file that contains
the information about the stochastic process, but can you tell me how
best to get them to you?  Is there a google address I could e-mail
them to?

Request for Question Clarification by mathtalk-ga on 07 Aug 2004 20:46 PDT
Alas, there is no email address to which you can send these things. 
The approach I take, as in the Question posed by asiatechnicals-ga, is
to place the files on a Web server from which they can be downloaded.

There are some sites which will allow you to upload files where others
can download them.  I guess the first thing to clarify is how big your
files are.  Then we can find a suitable "host" for them.

regards, mathtalk-ga

Clarification of Question by finmodeler-ga on 08 Aug 2004 07:01 PDT
The data file is not very big (37KB).  The pdf file contining the paper is 0.85MB.

Request for Question Clarification by mathtalk-ga on 09 Aug 2004 07:22 PDT
Hi, finmodeler-ga:

Is it possible to post a description of the pricing model here?  I
realize that it can be a challenge to use simple ASCII text to
represent mathematical formulas; you may get some ideas for doing this
from my earlier Answer on Kalman filtering.

There are a number of sites that provide "free file hosting", and I'm
asking around to see if there are some recommendable ones.

regards, mathtalk-ga

Clarification of Question by finmodeler-ga on 09 Aug 2004 07:55 PDT
I would first rather exhaust the possibilities for getting the
information to you in a more user-friendly format, because there is a
fair amount of it and it is critical to have it all correct.

I sent an e-mail to google user support to ask it they could provide
me with an address to send the attachments, which could then be
forwarded to you.  I'm sort of surprised they haven't already set
something like this up.  The second option is for me to set up a
temporary web page on my DSL provider's server to post the files to
and then provide you with a link.

If I don't hear back from Google user support, I'll proceed with the
web page later today.

Clarification of Question by finmodeler-ga on 09 Aug 2004 18:01 PDT
mathtalk-ga,

Here is a link to the data.  I has been cut and pasted into the model
you created earlier:  http://finmodler.4t.com/Kalman%20filter.xls

The information on the stochastic process and state/space formulation
is in a pdf file at this link:
http://finmodler.4t.com/Parameter%20Estimation%20-%20S%26S.pdf

Please let me know if you have any trouble accessing these, or if I
can clarify anything.

Thanks,

finmodler-ga

Clarification of Question by finmodeler-ga on 09 Aug 2004 20:00 PDT
There were errors in the above links - please use this instead:

http://finmodler.4t.com

Request for Question Clarification by mathtalk-ga on 09 Aug 2004 20:15 PDT
Okay, nice work, I got them!

regards, mathtalk-ga

Clarification of Question by finmodeler-ga on 15 Aug 2004 20:08 PDT
Hi Mathtalk-ga,

At the link above I have posted an update to the Kalman Filter model. 
I'm still working with the template you provided in your earlier
answer on this topic.  I don't think there's much chance I can work
this out completely without assistance, but at least the exercise will
help with my understanding.

What I first did was to link the data on two of the time series (1 mo.
futures, 3 mo. futures) into the model, and then begin to change the
model from a smoothing/fitting application to one for estimating the
parameters of the given stochastic process.  You'll also note I
switched your nomenclature a bit to match the process information I
gave you in the pdf file.

I have attempted to label sections of the sheet to show the flow of
updating the state value estimates.  There are new columns added for
the mean and covariance of the state variables, as well as for the
measurement errors and their covariance matrix.  At the top of the
sheet, I also added a section for the parameters of the stochastic
process, and then set the parameters and covariance matrices of the
measurement and transition equations to calculate directly from the
parameters.  So now everything starts with the parameters.  Finally,
the log likelihood equation is entered as the target for maximization
(by varying the parameters).  Unfortunately, when I tried to solve
using the Solver function in Excel, I got results that are obviously
wrong, so there is a bust somewhere in my approach or calculations.

I doubt that any of this will be of any use to you, but I'm sending
the link just in case.  Let me know if you have made any progress, or
have any needs for clarification.

Regards,

finmodler-ga

Request for Question Clarification by mathtalk-ga on 16 Aug 2004 06:09 PDT
Hi, finmodeler-ga:

I got the updated spreadsheet.  I'll post some requests for
clarification later today once I have a chance to look over it.

thanks, mathtalk-ga

Clarification of Question by finmodeler-ga on 17 Aug 2004 19:59 PDT
Mathtalk-ga,

I don't know if I am close to a solution, or off in the weeds, but I
am definitely stuck.  Let me know how you are progressing.

Thanks,

finmodler-ga

Request for Question Clarification by mathtalk-ga on 18 Aug 2004 04:48 PDT
It's a bit basic, but is there a formula missing at the top of page 2
in the PDF file?  It looks like at the first "break" in the text where
the "mean rebounding" effect is going to be modelled, there is a
missing formula, followed by "where [kappa] represents the
mean-reversion rate".

The "missing" formula seems to be called the "Ornstein-Uhlenbeck process".

Of course the formula might be there, but I'm missing a font that
Acrobat Reader needs?

regards, mathtalk-ga

Clarification of Question by finmodeler-ga on 18 Aug 2004 05:05 PDT
mathtalk-ga,

The formula that is supposed to follow the : on the very top of page 2
somehow floated back to the very bottom of page 1 (perhaps in the
translation to pdf format).  So, the formula dX=-KXdt+sigma*dz should
appear after the :

Sorry for the confusion - I should have caught this before posting.

Regards,

finmodler-ga

Clarification of Question by finmodeler-ga on 28 Aug 2004 12:25 PDT
Hi Mathtalk-ga,

Have you been able to make any progress on this?  If you're still
working on it, then I have underestimated the time required and need
to revise the price.  If you're not, then I need to withdraw the
question and figure out how to compensate you for your time.

Thanks,

finmodler-ga

Request for Question Clarification by mathtalk-ga on 28 Aug 2004 18:28 PDT
Hi, finmodeler-ga:

I am primarily motivated to continue working on a problem of this
type, which requires some "learning" on my part, because of the
opportunity not only to learn something new for myself but to teach
others.

The price you posted is quite generous in the scheme of Google Answers
requests, and I would refer you to the guidelines which state that
Researchers are not to post partial answers.  So bear with me as we
get through the end of the month, and I'll try to produce something we
can both be happy with.

Of course you are able to Close (Expire) the Question at any time
prior to an Answer being posted, and if you are no longer interested
in an Answer, that would be the appropriate action.  The guidelines
being what they are, one can only "afford" to undertake a problem like
this one on the basis of a special interest.

regards, mathtalk-ga

Clarification of Question by finmodeler-ga on 28 Aug 2004 21:05 PDT
Mathtalk-ga,

That's fine, just wanted to get some idea on whether you were
progressing and the the amount of your time that is being required.  I
continue to be interested in the problem, but I also recognize that
this is a fairly challenging one.  Let me know if and when it would be
appropriate to extend the expiration date (possible?) or to re-pose
the question.

Regards,

finmodler-ga
Answer  
There is no answer at this time.

Comments  
Subject: Re: Kalman Filter implementation
From: mathtalk-ga on 06 Sep 2004 16:06 PDT
 
My impression is that estimating parameters of a system which exhibits
"rebound" (toward a mean trendline) as described in the PDF requires
more state variables to be modelled.

The original spreadsheet involved two "commodity" prices, but the
exercise was mainly intended to demonstrate the estimation of trends
and correlations (or anti-correlations) between the two series.

Our model system was then a "simple" first order system of ODE's,
involving the commodity prices and their rates of increase (first
derivatives in time).  I believe the correct model in this exercise is
either a second order system _or_ equivalently a larger first order
system of ODE's in which the underlying variables represent prices,
first derivatives, and second derivatives with respect to time.

The new spreadsheet is nicely formatted, but as I think could be
observed in the original spreadsheet, the legibility of the Excel
layout is already taxed to accomodate the relatively compact 2x2
matrix formulas.

I suspect a transition to VBA programming has become something of a
necessity to cleanly handle the additional state variables.

regards, mathtalk-ga
Subject: Re: Kalman Filter implementation
From: sunbal-ga on 13 Jul 2005 01:52 PDT
 
hi finmodeler-ga
Having much the same problem could it be possible to get these 2 files
you posted ( xls and pdf )
thk you

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy