Let xj (for j = 1,…,n) denote the maximum possible return the investors can make if they sell the stock on day j. Note that x1 = 0. Now, in the optimal way of selling the stock on day j. the investors were either holding it on day j-1 or there weren’t. if they weren’t ,then xj=0. If they were then xj = xj-1+(p(j)-p(j-1)). Thus , we have