1

Someone gave me a problem from a textbook that I can't figure out. It is:

Let's say that you have a stock STOK that you are set on investing all of your money in for a month (days 0...30), and at the end of the month you can't hold any of the stock. You have m money. For any day d the price of STOK is p(d), and on any day you can either buy or sell stock. However, there is a limit, l(d), to how much stock you can buy and sell in one day (it's the same for buying and selling). You can buy non-integer units of stock if you want, for ease of calculation. Given these functions, how do you schedule a purchase plan to maximize your profit?

The naive solution: Every day buy as much stock as you can under the following constraints: If you are unable to sell all of your stock by the sell date do not buy any more; If you are out of money, do not buy any more. When you reach the point where you must begin selling stock (this is known, for you know the stock prices in advance) then sell as much as you can every day. This solution doesn't work, however, because what if the stock dips at the beginning of the month then soars after the first five days?

This smells like dynamic programming, but the fact that the stock price isn't monotone makes it hard. Brute force is clearly out given the continuous nature of the problem. Any solutions?

4

1 回答 1

1

如果您事先知道股票价格,这听起来很像递归(蛮力)中的问题。您构建了一组每日股票价格、每日限制、每日手头现金和每日拥有的股票。使用接受每个数组作为参数的递归函数。如果月底的现金大于起始现金,则选择未标记的可能天对,标记一次买入和一次卖出,更新所有数组,执行适当的限制并递归,将数组集保存为新的最大值,将数组重置为起点,选择接下来的几天并继续,直到所有尝试都已尝试。

于 2013-08-14T04:10:47.643 回答