-
-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add G-H filter and Kalman filter #915
Conversation
Codecov Report
@@ Coverage Diff @@
## main #915 +/- ##
==========================================
+ Coverage 19.71% 19.84% +0.12%
==========================================
Files 398 402 +4
Lines 29950 30049 +99
==========================================
+ Hits 5904 5962 +58
- Misses 23473 23510 +37
- Partials 573 577 +4
Continue to review full report at Codecov.
|
- implement G-H (alpha beta) filter and Kalman filter - compare the predict accurateness with other indicator
0a0dd89
to
9c684c1
Compare
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
filter := &GHFilter{IntervalWindow: types.IntervalWindow{Window: tt.args.window}} | ||
ewma := &EWMA{IntervalWindow: types.IntervalWindow{Window: tt.args.window}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EWMA is widely used to calculate average price with less latency compare to SMA. Do we expect the comparison of ZLEMA?
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
filter := &KalmanFilter{IntervalWindow: types.IntervalWindow{Window: tt.args.window}} | ||
ewma := &EWMA{IntervalWindow: types.IntervalWindow{Window: tt.args.window}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, change to ZLEMA?
You can add these two indicators to the standardIndicator struct |
Observer filters are realtime estimation algorithms to measure the status changes in a noisy environment. These recursive filtering algorithms estimate the true target states by minimize the uncertainties from system noise and observation noise. Such technologies are useful in financial econometrics as estimators without any latency, and more accurate than moving average based indicators.
The G-H filter in this PR implement John Ehlers' work. The system uncertainty is defined as the change of middle prices of K-lines, and the observation uncertainty is the price range of each K-line. Instead of fixed alpha & beta of conventional G-H filter, these two factor are calculated using an exponential recursive method controlled by configured window length.
More generalized than G-H filter, Kalman filter replaces these update factors by an adaptive factor Kalman gain, calculates the gain from uncertainties of estimation and observation, and optimize the estimation base on the gain, the measurement, and the previous prediction. In our implementation, we add an additional factor
AdditionalSmoothWindow
in need of smoothness, and set to 0 (classic Kalman filter) by default.Estimation Accurateness
In this PR, tests are created to compare the estimation accurateness between the two filters and EMA by calculating the square errors.
References