Cointegration and the optimal hedge ratio: the general case