I'm using the MACD function from the talib library. http://www.tadoc.org/indicator/MACD.htm
The function's output is based on moving average of the input values.
Let's create function inputs:
close = np.array([ 2930.8, 2926.3, 2941.5, 2942.9, 2948.5, 2923.1, 2917.6,
2947.6, 2932.4, 2890.8, 2887.2, 2872.7, 2886.9, 2807.1,
2839.2, 2855. , 2878.6, 2862. , 2843.9, 2866.1, 2857.4,
2819.4, 2831.8, 2805.1, 2780.1, 2790.4, 2752.6, 2749.6,
2804.9, 2827.7, 2845.7, 2874.9, 2889.2, 2886.9, 2881. ,
2898.4, 2894.8, 2896.3, 2926.2, 2933.4, 2960. , 2950.6,
2952.1, 2922.1, 2917.9, 2930.9, 2944.2, 2967.7, 2979.6,
3000.3])
index = pd.date_range('2019-04-24','2019-07-02', freq = 'B')
fast_period, slow_period, signal_period = 3, 10, 1
Let's run the function:
import talib as ta
macd_histogram = pd.DataFrame({'macd_hist': ta.MACD(close, fast_period, slow_period, signal_period)[2]}, index = index)
Let's check the last few values of the output:
print(macd_histogram[-3:])
2019-06-28 -11.932
2019-07-01 90723585644794610874060269361590083028296154282...
2019-07-02 0.000
Freq: B, Name: macd_hist, dtype: float64
Issue: As you can see, those last two values are obviously distorted.
let's redo the exact same process:
macd_histogram = pd.DataFrame({'macd_hist': ta.MACD(close, fast_period, slow_period, signal_period)[2]}, index = index)
print(macd_histogram[-3:])
2019-06-28 -11.932
2019-07-01 24.066
2019-07-02 30.652
Freq: B, Name: macd_hist, dtype: float64
This time, the last two values seem more likely to be correctly calculated.
Let's try one more time.
macd_histogram = pd.DataFrame({'macd_hist': ta.MACD(close, fast_period, slow_period, signal_period)[2]}, index = index)
print(macd_histogram[-3:])
macd_hist
2019-06-28 -11.932
2019-07-01 0.000
2019-07-02 0.000
Even more inconsistency!