Skip to content
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

DEMA and TEMA - early calculations #770

Closed
mihakralj opened this issue Apr 13, 2022 · 5 comments
Closed

DEMA and TEMA - early calculations #770

mihakralj opened this issue Apr 13, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@mihakralj
Copy link
Contributor

Current implementation of DEMA/TEMA (Double and Triple EMAs) is unnecessarily laggy.

  • EMA: calculate SMA of initial [period] data and then calculate each subsequent value by using k=2.0/(p+1) weight.
  • DEMA: calculate SMA of initial [period], calculate EMA and EMA(EMA) of each next period
  • TEMA: calculate SMA, then calculate EMA, EMA(EMA) and EMA(EMA(EMA) of each next period

Implementation here is recalculating SMA of EMA (for DEMA), and SMA of EMA of EMA (for TEMA), generating usable bars 3*period later than it could. This same bug appears in TA-LIB, but is not present in Pandas-TA - or other libraries.

After about 60 bars (for DEMA) or 100 bars (for TEMA) both algos completely converge into a same series, so this issue is minor and visible only to users that would like to use TEMA as early as possible and not wait for 3*period of warmup data.

@mihakralj mihakralj added the bug Something isn't working label Apr 13, 2022
@DaveSkender
Copy link
Owner

DaveSkender commented Apr 13, 2022

I’ll take a look. Thanks for finding/posting. Sounds like there may be a mathematical shortcut to the same/sooner result with a shorter warmup window.

I usually source formulas from original authors, but suspect others may do it differently. These are on Wikipedia.

Note to self, while looking at this one:

  • consider renaming methods and make old obsoleted. These have bothered me for a while now. 🤪

@DaveSkender DaveSkender added enhancement New feature or request and removed bug Something isn't working labels Apr 13, 2022
@mihakralj
Copy link
Contributor Author

Check my validation tests here for DEMA/TEMA. They all pass (comparing my DEMA/TEMA with yours and with TA-LIB) - but I feed it 1,000 bars. Tests fail at 100-200 bars.

@DaveSkender
Copy link
Owner

Just took a look. I like the way you’re suggesting to shorten the warmup window. I’m simply reusing the existing EMA method to avoid duplicating code, but this improvement makes sense and still honors the fundamental math correctly.

@DaveSkender
Copy link
Owner

DaveSkender commented Apr 25, 2022

I'm running a convergence analysis on DEMA right now and starting earlier doesn't seem to improve the actual rate of convergence to accuracy at all. The only benefit is that you get more less-accurate warmup data. Though, it does run faster since this uses a single pass approach. I had two passes since I was just calling the EMA twice. The extra speed is probably worth the tradeoff.

This was referenced Apr 25, 2022
@DaveSkender
Copy link
Owner

This will be available in the next version.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

2 participants