So, the problem is to find a

polynomial p(x) whose values are specified at finitely many points, ie. p(x

_{i}) = f

_{i} (I'll say that there are n such points). To do this, all you need is the following simple trick:

If the polynomial functions p_{i}(x) are defined in the following manner:

p_{i}(x) = (product over j, j!=i) (x-x_{j})/(x_{i}-x_{j})

then p

_{i}(x

_{j}) = δ

_{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) f_{i}p_{i}(x), and then a simple check reveals that p(x_{i}) = f_{i}, 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 x_{i}, so is the zero polynomial).

As to whether the interpolation is any good elsewhere, it depends on how widely separated you x_{i} 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.