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

ENH: add "adjust" parameter to ewmvar(), ewmstd(), ewmvol(), ewmcov(), and ewmcorr() #7911

Closed
seth-p opened this issue Aug 4, 2014 · 3 comments · Fixed by #7926
Closed
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff API Design Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@seth-p
Copy link
Contributor

seth-p commented Aug 4, 2014

Currently ewma() has an adjust parameter (affecting how the weights are calculated) whereas all the other ewm*() functions do not. When they call ewma(), adjust is implicitly set to its default value, True. This is probably fine in most cases, but if ewma() is going to expose the adjust parameter, the other ewm*() should as well.

For clarity, here's the description of the adjust parameter in _ewm_notes:

When adjust is True (default), weighted averages are calculated using weights
    (1-alpha)**(n-1), (1-alpha)**(n-2), ..., 1-alpha, 1.

When adjust is False, weighted averages are calculated recursively as:
    weighted_average[0] = arg[0];
    weighted_average[i] = (1-alpha)*weighted_average[i-1] + alpha*arg[i].

On a related note, I'm not sure what the policy/practice is for reordering parameters, but if it's not too strict I'd like to reorder the ewm*() parameters just a little so that (i) freq and how are next to each other, and (ii) adjust and ignore_na are next to each other.

@seth-p seth-p changed the title ENH: add "adjust" parameter to ewmvar(), ewmstd(), ewmvol(), ewmcov(), and ewmcorr() ENH: add "adjust" parameter to ewmvar(), ewmstd(), ewmvol(), ewmcov(), and ewmcorr() Aug 4, 2014
@seth-p
Copy link
Contributor Author

seth-p commented Aug 4, 2014

Note that even though all the ewm*() functions other than ewma() lack an adjust parameter, their doc strings say that they have one. (This is from the definition of _ewm_kw.)

@seth-p
Copy link
Contributor Author

seth-p commented Aug 4, 2014

CC'ing @snth and @jaimefrio, who appear to have worked on this/related code.

@seth-p
Copy link
Contributor Author

seth-p commented Aug 4, 2014

Along the same lines, should the rolling_var/std/cov() and expanding_var/std/cov() have a ddof parameter the way Series.var/std() do (though Series.cov does not)? They're all labeled "unbiased", and appear to effectively use ddof=1, so nothing is wrong, but I don't see why the treatment of ddof can't be uniform.

And similar my comment above on parameter order, for these functions too I'd like to reorder things a bit, e.g. so that freq and how are next to each other...

@jreback jreback added this to the 0.15.0 milestone Aug 5, 2014
Aprataksh pushed a commit to Aprataksh/Munafa that referenced this issue Jun 13, 2018
in the daily closing hired with MACD strategy, we use a scanner to look for stocks which are closing higher on an end of day basis for a user specified number of days. We then purchase a stock when there is an MACD crossover from below-the MACD line crosses the signal line from below.

The stock is sold if the target price is met or there is a stoploss or on the end of day of the t+n days specified by the user. For example, if the user specifies three days, we will continue to look for opportunities to sell the stock purchased on the first day until the third day. We will not make any purchases on the second or third day. The purchase will will be limited to the first day

while verifying the code, it was discovered that the MACD values but not been calculated correctly. After doing the calculation by hand and then investigating this mode, it seems that we have two add an additional parameter of alpha = false in order to calculate the EMA.
More information for this parameter is can be found at pandas-dev/pandas#7911

Given the confusion surrounding this issue, it may be useful to investigate other ways to calculate the EMA

Also, the MACD line is calculated as fast EMA minus low EMA and not as the other way round which was in the squad that was submitted the first time

This code has been authored by Aprataksh Anand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff API Design Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
2 participants