In my graduate financial stats class, we had a big project to implement some basic portfolio theory. We were told to ignore transaction costs in the class model. I wanted to try to account for these costs. In the end, I had a model that performed well on a long time scale, over many decades. It appeared at first to beat the market, but I concluded that this is probably survivorship bias.
The full code is available here, in R. Unfortunately this is old code, and is not very readable.
I started with standard Modern Portfolio Theory, with some chosen risk tolerance; I used R's quadprog package for the minimization. I estimated expected log-returns and covariance matrix by a moving average of past log-returns and covariance.
I accounted for transaction costs by (1) including them in my simulations, (2) I optimized with and without changing each possible stock and took the greater of the optimizations, and (3) attempted to account for future costs. My thought for the last point was that I could attempt to maximize the lifetime value of the stock. I assumed that I would hold the stock for x weeks, where x was geometrically distributed with parameter alpha. I said then that given a one week expected log-return of E, I should expect a lifetime log-return of
And if I expected a one-week variance of V, the I should (I had argued) expect an n-week variance of nV, and a lifetime variance of
I think that this does a nice enough job at addressing transaction costs. My idea for calculating lifetime value of a stock has a couple of shortcomings: For one, although it's a novel idea, the net effect seems to be merely adjusting the risk tolerance as a function of alpha. Secondly, the assumptions that the lifetime of the stock would be geometric and iid are maybe too strong. Finally, I calculated the variation as the expected value of variance, but I should have added the variance of the expected value, per the law of total variance.
If I were to revisit this, I would focus on more maintainable code, but a better lesson is to not expect to beat the market through simple formulas.