# Teach a machine how to identify critical financial ratios: a decision trees approach

Updated: Jan 27, 2020

If you’ve been following __Stockomatics__ for a while, you’ll know that we’ve been sharing insights each week to help to shed some light on different long-term fundamental trends within the stock market, as identified by AI and Machine Learning.

In our __first article__, we focused on pricing and profitability. We __then focused__ on profitability and debt, yielding fascinating results. Today, we measure the impact of financial ratios on stocks performance. We did this by embracing the whole spectrum and considering 9 financial ratios for the whole American stock market.

Which financial ratios are the most important to watch before a purchase ? We let our machine learning model do the talking...

**1. First, we defined 9 meaningful financial ratios**

We defined 9 well-balanced financial ratios of 3 categories to obtain an harmonious snapshot of a company: **pricing**, **profitability** and **debt**:

**2. We parsed these ratios for all American companies in 2015**

**
**One example here is with **Intel (NASDAQ: INTC)** in 2015:

Then, we checked if this company has been **"performant"** (i.e: the price surged more than 20% in 5 years between 2015 and 2020):

Eventually, we attached all the 9 financial ratios and the performance label to the company:

We repeated this operation for every single company listed on the American stock market.

**3. We used a "Random Forests" algorithm to judge the importance of each ratio**

After labelling the whole dataset, how to determine which financial ratio has the most influence on the performance of stocks ?
We generated multiple "decisions trees" using a Machine Learning algorithm called "**Random Forests"**: the outcome is an evaluation of the importance of each financial ratio based on a myriad of subsets taken from the original dataset. These subsets will then be used to build trees on which the successful paths to performance will be counted and an "influence on the result" will be deduced in percentage.

The inputs of this algorithm are:

- **the features (financial ratios)**

-** the number of trees (n)**

-** the size of test subsets taken (s). **

For all financial ratios, a number of trees **n=100** and size of subsets **s=0.01% , **we obtain the following table of importances of financial ratios as output:

These calculations come with a level of precision based on the back testing of the model: in that case this is **75%. **This value is quite reasonable and converged (increasing** n **or modifying **s **would not lead to significantly better accuracy) however the choice of the financial ratios is quite critical. This will be further explored in an upcoming article.
Now let's have a look at the results themselves:** the pricing ratios have the strongest impact on performance**.

**
**The three pricing ratios first come all together, before the debts ratios and the profitability ratio. This is definitely a hint to their criticality. It's also interesting to see that the "**Price-To-Operating-Cash-Flow**" comes first as people tend to consider the "**Price-To-Earnings**" ratio as a reference.

**4. Conclusion**

This study was short and could lead to further research (e.g; the choice of financial ratios or the choice of numerical parameters). However, it looks like the "value" game (buying undervalued assets and selling them when they are overvalued) is not dead. **The pricing ratios are the most important things to look at when buying a stock for a 5-year investment**. Buy undervalued. Sell overvalued. And start by a pricing analysis when stock-picking.

To conclude, a little quote from the *Oracle of Omaha*:*
*

"Whether We’re Talking About Socks Or Stocks, I Like Buying Quality Merchandise When It Is Marked Down"Warren Buffet