Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Is there an API for Weighted Moving average?

I am trying to play with different moving averages.

Some pointers here.
http://www.financialwisdomforum.org/gummy-stuff/MA-stuff.htm

And am trying to implement HullMA and MAg and I need Weighted moving average.

What is the best way to calculate these values?

Sarvi

3 responses

HullMA(HMA), Weighted moving average (WMA)
Thanks to Market Tech
https://www.quantopian.com/posts/trying-on-for-size-a-technical-framework

def CalculateHMA(context, data):  
    closeDeck = history(HMAPeriods * 2, "1d", "close_price")  
    closeDeck = closeDeck.dropna(axis=1)  
    closeDeck = closeDeck[[sid for sid in closeDeck if sid in data]]  
    wmaA      = closeDeck.apply(talib.MA,   timeperiod = HMAPeriods / 2, matype = MAType.WMA).dropna() * 2.0  
    wmaB      = closeDeck.apply(talib.MA,   timeperiod = HMAPeriods, matype = MAType.WMA).dropna()  
    wmaDiffs  = wmaA - wmaB  
    hma       = wmaDiffs.apply(talib.MA, timeperiod = math.sqrt(HMAPeriods), matype = MAType.WMA)  
    for stock in closeDeck:  
        context.S[stock].Trigger += 1 if hma[stock][-1] > hma[stock][-2] else 0  
        context.S[stock].HMA = hma[stock][-1]  

Quantopian has talib module supported, it has WMA implemented
https://github.com/mrjbq7/ta-lib