Let's say we have a stock which our only actions are buy, sell and hold (with or without shorting).

If we have sufficient past data of the stock, how can you determine the optimal trading action every time-stamp in the past in an efficient or even optimal way? Transaction costs, bid-ask spread and slippage would definitely have to be included.

I can think of this as a black-box optimization problem, but the search space is large, so the search would be inefficient.

I tried to search the literature for pointers, but nothing came out of it. Has anyone researched good ways to do this?

• You're kidding, right? – Dan Bron Jun 3 '14 at 23:24
• @DanBron This isn't a silly question, as it's not as simple as finding the local min/max. – user2763361 Jun 4 '14 at 7:41
• Dan, if it is so easy, why don't you make it clear? Indeed, if we had no kind of transaction costs, it would be something like buying at local minimums and selling at local maximums. With transaction costs it's a little bit more complicated. And then if you think that not all profitable trades were good actions (due to risk and volatility), you have a really hard problem! – Pedro Tabacof Jun 4 '14 at 13:52
• You need to clarify the question. You could mean two things. (1) How do you determine what would have worked best if you had know the price path in advance, given some model of slippage and transaction costs, etc, or: (2) How do I use this information in research to determine a good strategy for the future. (1) is an interesting question, (2) does not belong here. – user2763361 Jun 4 '14 at 14:34
• My question is definitely (1). – Pedro Tabacof Jun 4 '14 at 14:54

The specific procedure depends on details of the problem such as

1. What is the objective function? Sharpe ratio? Terminal wealth?
2. What is the model of transaction costs?
3. What is the data resolution? (If it's very high the problem may become challenging computationally).

There are many papers, e.g. this one, that solve various problems of this sort. These are most certainly not black-box optimization problems. There are specific, and well-motivated objective functions, constraints, and dynamics. You should understand that, in general, the size of the search space is not a good guide as to whether the problem can be solved efficiently or not. Brute force exhaustive search is almost never utilized for non-trivial optimization problems. It is often the case that a problem over an infinite set (e.g a linear program) is much easier than a problem over a finite set (e.g. an integer program).

I think what you're trying to do is to construct a portfolio from inside out, i.e. picking stocks based on idiosyncratic factors. I have never heard anyone (within the industry) succeed with this, and, to my knowledge, the literature in this direction is pretty slim.

The main reason is that in finance, the Markowitz approach is dominant to this day. Put simply, because a portfolio holds a variety of stocks, you always have to consider how they interact, that is, consider their correlation. As volatility is not additive (partly due to correlation), you should not invest in stocks by looking at them individually, but consider the entire portfolio. If a stock is negatively correlated with another, their movements will cancel out, so if your knowledge of the future is incomplete, it will enhance the portfolio as a whole.

The closest thing to what you intend would probably be fundamental analysis, but the research does not show consistent outperformance afaik. Alternatively, look into smart beta asset allocation, which considers underlying risk factors for portfolio consruction.

you can smooth your data and then find the zeros of the slope of the smoothed data. You can adjust for the costs with the degree of smoothing.