QuantEcon.jl icon indicating copy to clipboard operation
QuantEcon.jl copied to clipboard

add Baxter King filter

Open Shunsuke-Hori opened this issue 7 years ago • 8 comments

test is added too

Shunsuke-Hori avatar Oct 08 '18 16:10 Shunsuke-Hori

Codecov Report

Merging #223 into master will decrease coverage by 0.01%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #223      +/-   ##
==========================================
- Coverage   95.87%   95.86%   -0.02%     
==========================================
  Files          25       25              
  Lines        1067     1063       -4     
==========================================
- Hits         1023     1019       -4     
  Misses         44       44
Impacted Files Coverage Δ
src/filter.jl 100% <100%> (ø) :arrow_up:
src/util.jl 98.14% <0%> (-0.07%) :arrow_down:
src/markov/markov_approx.jl 98.37% <0%> (-0.04%) :arrow_down:
src/markov/ddp.jl 98.63% <0%> (-0.02%) :arrow_down:
src/arma.jl 100% <0%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7fc1254...63ba102. Read the comment docs.

codecov-io avatar Oct 08 '18 16:10 codecov-io

Hi @Shunsuke-Hori thanks for submitting!

I googled for some references on the BK filter equations and found conflicting evidence.

Two references are

  • http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.197.8691&rep=rep1&type=pdf
  • http://help.prognoz.com/en/mergedProjects/Lib/02_time_series_analysis/uimodelling_baxterkingfilter.htm

A few differences:

  • the html page only divides b[2:end] by (2K+1), but keeps b[1] without dividing
  • The pdf has a negative sign in front of theta, while the html page keeps it positive.

your code seems to more closely follow the pdf, but I'm not sure.

What reference did you use? How do we know which is correct?

sglyon avatar Oct 09 '18 12:10 sglyon

@sglyon Thank you for the review.

I first looked the html but since the output was not same as python's, I switched to the pdf.

I checked the original paper and it seems the pdf is consistent with the paper (although, honestly, I mindlessly trusted the result of `bk_filter' of python when I wrote the code)

Shunsuke-Hori avatar Oct 09 '18 16:10 Shunsuke-Hori

Hi @Shunsuke-Hori I had a look at the code. It seems perfectly in line with http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.197.8691&rep=rep1&type=pdf The second reference http://help.prognoz.com/en/mergedProjects/Lib/02_time_series_analysis/uimodelling_baxterkingfilter.htm seems not to be online any more. Further the original reference https://www.mitpressjournals.org/doi/abs/10.1162/003465399558454?casa_token=pfn7A97wi0QAAAAA:78AlfSOyiz__a6_snyH7jwydLu8uGZV-U3ZVY5Vo3dTi0r7da5uuVtUyUR87-uZBAuarQAYMiywJ76o is not publicy available (MIT press). I try to get my hands on that at some point. The implementation gives the same result as the python implementation in https://www.statsmodels.org/stable/generated/statsmodels.tsa.filters.bk_filter.bkfilter.html#statsmodels.tsa.filters.bk_filter.bkfilter

So I think, it is fine.

andi3141 avatar Sep 25 '20 13:09 andi3141

Many thanks @andi3141 for your review. This looks good to me too (aside from very minor comment above).

jstac avatar Sep 25 '20 21:09 jstac

Codecov Report

Merging #223 into master will decrease coverage by 0.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #223      +/-   ##
==========================================
- Coverage   95.87%   95.86%   -0.02%     
==========================================
  Files          25       25              
  Lines        1067     1063       -4     
==========================================
- Hits         1023     1019       -4     
  Misses         44       44              
Impacted Files Coverage Δ
src/filter.jl 100.00% <100.00%> (ø)
src/util.jl 98.14% <0.00%> (-0.07%) :arrow_down:
src/markov/markov_approx.jl 98.37% <0.00%> (-0.04%) :arrow_down:
src/markov/ddp.jl 98.63% <0.00%> (-0.02%) :arrow_down:
src/arma.jl 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7fc1254...bf39218. Read the comment docs.

codecov-commenter avatar Sep 26 '20 19:09 codecov-commenter

Thank you for reviewing, @andi3141 and @jstac

I fixed the grammar.

Shunsuke-Hori avatar Sep 26 '20 20:09 Shunsuke-Hori

Looks good to me. Over to you @sglyon

jstac avatar Sep 26 '20 23:09 jstac