In June I start teaching a new class called Algorithmic Trading. It's a two-week summer elective at our business school, meets almost every day, and about 35 students have signed up.

Here's how I describe algorithmic trading to a beginner. Instead of hearing about a company on the news or liking their products and buying the stock that way, you look at the numbers. You write programs that look at data, learn what causes stock prices to go up or down, and then decide when to buy and sell. We're using Python mainly, plus libraries inside it.

I ran a hedge fund three years ago. I did AI on Wall Street way before it was cool. And then I had the opportunity to teach this class.

The opening line

On day one I tell the students this:

“I'll be teaching some techniques. The key thing is that none of them work, of course, because if it was as easy as taking a two-week class, you could beat the market. The market is a big computing machine that is there to make sure that doesn't happen.”

The class is still worth taking. Python is useful, the techniques are interesting, and understanding why these strategies fail is a real piece of education.

Backtesting fools you

The second thing I teach is how to test a strategy. You have to be very careful about testing the strategy, because it's very, very easy to fool yourself.

Typically what people will do is test a strategy over a 10-year period and see that it performs really well. But if the strategy was optimized on that same data, of course it's going to do well. You have to test it on data it hasn't seen.

What's very common is that during the period the strategy has seen, it performs brilliantly, and then in the next five years it loses money. It's very, very easy to fool yourself.

So when you see those ads on television where some guy bought a stock and made a thousand percent, watch out. On historical data it's very easy to make money. The hard part is figuring out what's going to happen in the future. Things are changing all the time, and because conditions aren't stable, it's very difficult to build trading strategies that work over time.

What I actually do with my money

What I do is invest in a very broadly diversified mutual fund that owns 10,000 stocks from around the world. It owns a little bit of NVIDIA, and it owns a little bit of some company in Indonesia that no one has ever heard of, and et cetera, et cetera.

No matter what happens, I basically get the average return that everyone else around the world gets. That turns out to be better than 90 to 95% of what people get, because people will do things like trade and then incur transaction costs and lose money. The technique actually outperforms most people.

Why a 20-year-old invests differently than an 80-year-old

The third thing I teach is risk. Everyone is taught that you reduce your risk as you age, but most people don't know why that is.

Everyone knows a 20-year-old invests differently than an 80-year-old. The 80-year-old invests at a much lower risk. When you ask people why, they say something like, well, 80-year-olds are more conservative, or they want to make sure they have income.

The actual reason is different. The 20-year-old still has a long life ahead of them of getting income from a job. That income is steady. It's not as volatile as the stock market. If you think about it as a whole portfolio, the 20-year-old can afford to be aggressive in stocks because the income side is stable.

The 80-year-old is retired and has no income coming in. There's no steady thing on the other side. If they're aggressive in the stock market, the whole portfolio swings up and down. That's why they need to reduce risk. The math gets harder when the job market on the income side isn't as steady as the textbooks assume.

The real lesson

So that's what the class comes down to.

The most important thing to learn is that you can't beat the stock market, and so you should just decide on your asset allocation and then move forward.

I'll teach Python and the techniques, and I'll show you why backtests lie. By the end of two weeks, the students who were paying attention will understand that you can't beat the market. You just have to decide on your asset allocation and move forward.