U.S. Bank National Association analyzes sampled risk and pricing curves whose exact integrals may not be available in closed form. Implement composite Simpson's rule to approximate the definite integral of a curve from a to b.
Write integrate_simpson(values, a, b, n), where values is an array of n + 1 numeric samples. The samples are ordered from left to right and represent f(a + i * h), where h = (b - a) / n. Return the numerical approximation as a floating-point number.
Composite Simpson's rule is:
integral = (h / 3) * (f(a) + f(b) + 4 * sum(odd-indexed samples) + 2 * sum(even-indexed interior samples))
def integrate_simpson(values, a, b, n):