So, the problem is to find a polynomial
p(x) whose values are specified at finitely many points, ie. p(xi
) = fi
(I'll say that there are n such points). To do this, all you need is the following simple trick:
If the polynomial functions pi(x) are defined in the following manner:
pi(x) = (product over j, j!=i) (x-xj)/(xi-xj)
) = δij
(n.b. each of these polynomials are of order n-1).
Given this, simply define the required polynomial as p(x) = (sum over i) fipi(x), and then a simple check reveals that p(xi) = fi, as intended. The p(x) is of order n-1, and is the unique polynomial of this order satisfying the condition (since if p(x) and q(x) both do, then (p-q)(x) has n zeros at the xi, so is the zero polynomial).
As to whether the interpolation is any good elsewhere, it depends on how widely separated you xi values are - in short, if they're all bunched up together, then further away from the points, p(x) will be either growning or shrinking enormously, so it's not you're best bet for predicting stock market prices.