stock buying dynamic programming