Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WMA <- function(L, data){
- wma_w <- function(L,n)
- {
- if((n >= 0)&(n < L)) (2/(L*(L+1)))*(L-n)
- else 0
- }
- x <- vector(mode="numeric", length=NROW(data))
- for (i in 1:NROW(data)){
- if (i<L) x[i] <- NA
- else {
- value = 0;
- counter = 0;
- for (j in i:(i-L+1)){
- value = value + data[j] * wma_w(L,counter)
- counter = counter + 1;
- }
- x[i]<-value;
- }
- }
- return(x)
- }
- Quotes_ORCL[,11] <- WMA(10, Quotes_ORCL[, 2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement