I Built an Artificial-Intelligence System for Investing -- and It Showed How Smart Warren Buffett Is

I was curious.

The idea of driverless cars has been, and still is, fascinating to me. And so is the technology that makes driverless cars possible -- artificial intelligence (AI). Like many, I grew up enjoying books, movies, and TV shows that featured machines that could think in similar ways as humans. But what was once science fiction has now become reality.

A couple of years ago, I began a quest to really understand how AI works. I already knew the general concepts, but I wanted to delve into the nitty-gritty of one of the most revolutionary technologies of all time. So I read everything I could get my hands on, from fairly high-level books to textbooks to websites geared toward AI developers.

Along the way, I decided to build my own AI system. One thing even more interesting to me than AI is investing, so I decided to combine the two and develop an AI system that could make investment recommendations. That system is now up and running. And it told me just how smart Warren Buffett really is.

Neurons are the bomb

AI includes quite a few approaches. One that especially intrigued me was artificial neural networks. The idea for artificial neural networks originated back in the 1940s, when a neurophysiologist and a mathematician teamed up to write a paper about how neurons in the human brain might work. Based on their research, they built a simple neural network using electrical circuits.

Fast-forward to today. Artificial neural networks are used in many AI applications. Facebook (NASDAQ: FB), for example, uses neural networks in recognizing the faces of people in photos and to decide which advertisements to display to which users. Apple (NASDAQ: AAPL) uses neural networks to enable Siri to recognize what people ask and respond to questions.

Artificial neural networks work in a similar way that your neurons do. Each neuron is connected to multiple other neurons. When there is input (for example, a bee sting), the neuron transmits a signal to the neurons to which it's linked. In artificial neural networks, though, the inputs are data -- like images and speech. The artificial neural network learns from when it gets things wrong, self-adjusts, and gets better at recognition the more data it handles.

My artificial neural network was child's play compared to what Apple and Facebook use. I created a relatively simple network that received financial input. This input included price, earnings, and valuation history for the S&P 500 index. I also threw consumer price index (CPI) data, prime lending rates, three-month Treasury bill rates, industrial productivity index data, unemployment rates, and other financial data into the mix.

The kind of artificial neural network I built used what's called "supervised learning," where the AI system is trained using a lot of data for which the desired outputs are known. I trained my system using over 50 years of data, going back to the 1940s. I then tested it using data from 2000 through today.

The Buffett-bot

What I wanted the artificial neural network to determine was whether a person should be invested in the S&P 500 or in cash on a month-by-month basis. After a few stumbles along the way, I finally received an answer from the AI system. That answer was: Always be invested in stocks.

I ran that system all kinds of ways. I pared down the inputs. I changed out some data for other data. I experimented with several variables that the AI experts recommend tweaking. And the answer always came back the same.

It occurred to me that my AI system was basically saying to do what legendary investor Warren Buffett wrote in his letter to Berkshire Hathaway (NYSE: BRK-A) (NYSE: BRK-B) shareholders in 2014. He related what the instructions in his will for the trustee of his estate to follow upon his death: Invest most of the money in an S&P 500 index fund and let it ride.

Here's the really interesting part. I examined in more detail the recommendations from the artificial neural network. The system had more confidence in being in stocks when the market was going down and less confidence when the market was going up. That's basically what Buffett had in mind when he said to "be fearful when others are greedy and greedy when others are fearful." I realized that I had created a "Buffett-bot"!

Intelligent approach -- artificial or not

The more you think about it, though, the more my AI system -- and Warren Buffett -- makes sense. Historically, the stock market has risen a lot more months than it's fallen. Every time the market has fallen, it's come roaring back. There's every reason in the world to be confident when the market is down, because better days will surely be ahead. That's been Buffett's philosophy his entire career.

Of course, Buffett hasn't followed the advice that he is leaving for his heirs. Instead of parking his money in an S&P 500 index fund, he has used Berkshire Hathaway as a vehicle to build his own investment fund of sorts. If you pick the right stocks, your success will be even greater than going only with the S&P 500. Buffett's track record proves the point.

I haven't asked my AI system yet, by the way, which stocks it would recommend. My hunch is that, if it's as smart as I think it is, it would come up with suggestions pretty close to the stock picks made by The Motley Fool's investing newsletters, which have trounced the S&P 500's performance. (For what it's worth, The Motley Fool long ago recommended several stocks of AI leaders, including both Apple and Facebook, as well as Buffett's Berkshire Hathaway.)

What's the key takeaway from my experiment with AI? Invest in stocks, stay invested in stocks, and buy even more when others are too afraid to do so. The concept applies to the S&P 500 or solid individual stocks like The Motley Fool recommends. That's an intelligent approach -- whether the intelligence is artificial or not.

10 stocks we like better than Berkshire Hathaway (A shares)When investing geniuses David and Tom Gardner have a stock tip, it can pay to listen. After all, the newsletter they have run for over a decade, Motley Fool Stock Advisor, has tripled the market.*

David and Tom just revealed what they believe are the 10 best stocks for investors to buy right now... and Berkshire Hathaway (A shares) wasn't one of them! That's right -- they think these 10 stocks are even better buys.

Click here to learn about these picks!

*Stock Advisor returns as of August 1, 2017

Keith Speights owns shares of Apple and Facebook. The Motley Fool owns shares of and recommends Apple, Berkshire Hathaway (B shares), and Facebook. The Motley Fool has a disclosure policy.