Is it possible to calculate (in a reasonable amount of time) the maximum profit, and strategy you could have used for history data?

So for example buy day 1, sell day 10, buy again day 15, sell day 31 would give the most profit you could have made if you know all the prices.

I would like to use this to backtest against. So you could say I have made 10%, and the best possible gain is 20%.

You could of course simply calculate all the options, but this seems very inperformant, is there a faster way to calculate the optimal strategy?

  • 3
    Are you just using a fixed transaction cost and fixed investment amount? The best strategy in hindsight would always be investing all you have in one thing at a time, so for any given period you just need to find the greatest delta and compare against all subsets to see if changing position over the period would be better. No small task for longer periods. – Hart CO Jan 21 '18 at 15:34
  • @HartCO "Investing all you have in one thing at a time" ignores the market reaction. – Franck Dernoncourt Jan 21 '18 at 19:29
  • 1
    @FranckDernoncourt Yep... no alternate universe we have access to do proper testing, so best we can do is ignore reality to some extent. – Hart CO Jan 21 '18 at 19:39

Get a list of every stock that was being traded during the time period, and how much each went up or down every day. Find the one whose value went up the most each day. Say ABC Company went up the most on day 1, DEF Inc went up the most on day 2, etc. If you had spent all your available cash to buy ABC on day 1, sold it on day 2 and bought DEF, etc, you would have the maximum possible profit.

Of course this assumes that the amount that you are investing is not large enough that your buys and sells make a measurable difference in the market. If you're investing a billion dollars, then you would have to somehow determine how much your transactions would have changed the market. In real life there's no way you could know that.

And frankly, I think the exercise would be useless. In any given day there are always stocks that have some ridiculous increase in price because of one factor or another, or just statistical noise. Like I see that on January 18, J Alexander went up an incredible 9% in one day. Magnachip Semiconductors went up 11%. And Five Oaks Investments went up 27%! If you really could predict the one stock whose value will increase the most tomorrow, and you could consistently do this every day, you could have profits of at least 10% PER DAY, or approximately 128 quadrillion percent per year with compounding. The catch, of course, is that no one can predict what stock is going to go up the most every day for a year.

Well, I just checked and find that all the stocks on all the stock exchanges in the world are worth a total of about $70 trillion. So if you started with $1,000 and made 10% per day profit, after 262 days you would own all the stock in all the publicly traded companies in the world. After that you presumably couldn't make any more money trading because there is no one to trade with. You own it all.

So you really need a more realistic standard. What's the most I could have realistically made if I ... but if I what? What's the plausible expectation versus the maximum amount theoretically possible? I don't know how you could determine that, or what the criteria would be. Maybe a realistic standard to compare to would be, What was the highest return earned by any mutual fund on the market? Or something like that.


Firstly, this is not back-testing. Back-testing is when you have a strategy that picks what to buy and when to buy and sell it, and you back test it against historical data to see how it performs. The word you're probably looking for is benchmark against.

And yes, you can simply do this by looking at the charts and pretend you bought ever time there was a peak and sell whenever there was a trough for the period you were looking at.


Yes. Many economists have studied it. You'll "just" need a Really Big Spreadsheet with all prices for all the stocks you care about for the time span you care about (including intraday prices), plus dividends, splits, etc, etc and the mathematical skill to crunch it all properly.


This is not back-testing. It's curve fitting, aka optimization.

Back-testing is when you have a strategy and you test a data string to see the results.

The problem with your hypothesis is that you don't have the benefit of knowing where the future price peaks and valleys will be, nor will the historical pattern repeat itself. So it's all guesswork.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.