Optimal Pairs Trading: Static and Dynamic Models