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

ALMA calculation does not prepend with NA's #29

Closed
marksimmonds opened this issue Jun 20, 2016 · 1 comment
Closed

ALMA calculation does not prepend with NA's #29

marksimmonds opened this issue Jun 20, 2016 · 1 comment
Assignees
Labels
Milestone

Comments

@marksimmonds
Copy link

marksimmonds commented Jun 20, 2016

Hi there, when calculating the ALMA moving average, the resulting vector is shorter than the original data by 'n' where n is the length of the moving average..... Checking this against other moving average types, it seems to be that the ALMA resultant vector does not pad the start of the results with an NA.

HTH

@joshuaulrich
Copy link
Owner

joshuaulrich commented Jun 20, 2016

Thanks for the report. Looks like this is due to the difference in rollapply.default and rollapply.xts when it comes to prepending the result with NA. I assume xts objects were used when ALMA was originally written, and NA are prepended in that case.

require(TTR)
require(xts)
data(ttrc)
x <- xts(ttrc[,-1], ttrc[,1]
str(ALMA(ttrc[,"Close"]))
#  num [1:5542] 3.2 3.24 3.28 3.29 3.28 ...
str(ALMA(x[,"Close"]))
# An ‘xts’ object on 1985-01-02/2006-12-29 containing:
#   Data: num [1:5550, 1] NA NA NA NA NA ...
#  - attr(*, "dimnames")=List of 2
#   ..$ : NULL
#   ..$ : chr "Close"
#   Indexed by objects of class: [Date] TZ: UTC
#   xts Attributes:  
#  NULL

The fix might be as easy as setting fill = NA in the call to rollapply.

@joshuaulrich joshuaulrich self-assigned this Jun 20, 2016
@joshuaulrich joshuaulrich added this to the 0.24.1 milestone Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants