How does one calculate a fair value for a futures contract whose underlying is an Index? For example, how would fair value for ES futures be calculated using the prices of the S&P 500 constituents? I know it's related to dividends and interest rate but not sure exactly how. Also, what if the index is based on commodities like precious metals or oil?
What your are looking is the cost of carry model. That is an equivalence relationship emerging from a no-arbitrage argument. The future price is linked to the current price with
Where $q$ is the percentage of the income streams, in your case the continuously compounded rate of the dividends. Equivalently, you can substract the present value of dividends from the current price.
If you are dealing with commodities, then you should add the costs associated with storage, freight rates and insurance of the underlying.