All problems
MACD Line
Problem
Compute the MACD line as the difference between the final values of two exponential moving averages of the price series with spans short_span and long_span. Each EMA uses smoothing factor 2 / (span + 1) and is initialized with the first price.
Return 0.0 for an empty series.
Hint
The shorter EMA reacts faster, so a rising market gives a positive MACD.
Test cases
case 1
in: [[1,2,3,4,5],2,3]
expected: 0.4436728395061724
case 2
in: [[5,5,5],12,26]
expected: 0
case 3
in: [[10],3,5]
expected: 0
case 4
in: [[10,9,8,7,6],2,4]
expected: -0.8117728395061725
Starter codePython
def macd_line(prices, short_span, long_span):
# Your code here
pass4 test cases · run your code against them in the editor