How to Backtest Stock Fundamentals Using Portfolio123

I have received several requests to provide a tutorial on how I backtest stock fundamentals using Portfolio123. My recent stock fundamental backtests have included shareholder yieldfree cash flow to enterprise value, and ROIC. Using this tutorial, you can learn how to run your own backtests to get the quintile performance results of your favorite stock fundamentals. Stop making investment decisions in the dark and learn what stock fundamentals actually provide valuable information.

Step 1: Getting started with Portfolio123

The first step is to get a free free 30-day trial at Portfolio123. You can do that by clicking on the previous link to Portfolio123 and then click on the Sign Up button on the top right side of the webpage. Once you get your username and password, log into Portfolio123.

Step 2: Create a New Stock Screen on Portfolio123

Next, look for the Screen menu and then select “New Stock Screen” as shown in the screenshot image below.

Create New Stock Screen menu
Create New Stock Screen menu

After you click on the New Stock Screen, you will see the following New Screen webpage:

Portfolio123 New Stock Screen page
Portfolio123 New Screen page

Step 3: Add the filter rules

In the blank field under Long Rules and just to the right of the green dot, you want to enter your first filter rule. You will likely want to filter out Over-The-Counter (OTC) stocks that are not traded on the major exchanges. To do this, you will want to type in the following rule:

Universe(NOOTC) = TRUE  // Exclude Over-The-Counter stocks not traded on the major exchanges

By the way, everything after // is not evaluated by the system so you can enter notes describing your rule using this syntax.

Add Free Form Rule button
Add Free Form Rule button

After entering this first rule, you will want to click on the ADD FREE FORM RULE button circled in red in the screenshot above. In the new blank form box add the following rule to exclude ADRs (American Depositary Receipt) to avoid foreign listed stocks that may have different accounting standards that may cause issues with stock fundamental backtesting:

Universe($ADR) = FALSE //Exclude ADRs to avoid data issues

Then add another new free form rule using the ADD FREE FORM RULE button. Now we want to filter out low liquidity stocks since those stock prices do not always represent what an actual stock buyer or seller might actually experience in a trade.  The rather complicated rule I now use filters out stocks that do not have 2 month daily minimum volume greater than $100,000 worth of shares traded.  The rule you enter is as follows:

LoopSum(“Vol(CTR) * Close(CTR) > 100000, 42) = 42 //2 Month daily minimum volume must be  > $100k

Then add another new free form rule using the ADD FREE FORM RULE button. We want to exclude nano-cap stocks due to data quality and business quality issues.  The following rule does that:

MktCap > 50 // Exclude nano-cap stocks

Finally, add another new free form rule using the ADD FREE FORM RULE button to exclude penny stocks.  Penny stocks have a history of being associated with stock manipulation and fraud. Enter the following rule to exclude stocks trading below a dollar:

close(0) > 1 // Exclude penny stocks

Now you list of rules should look like the screenshot below:

Basic stock screen filters

Step 4: Test the stock fundamental

The next step is to select the stock fundamental you are interested in testing. There is a search box in the area above the list of filter rules you just entered. Just as an example, search for the “Price to Earnings” ratio using the search box as depicted in the image below.

Adding backtest rules to Portfolio123

Select the version of the version of the Price to Earnings ratio you are interested in testing.  For this example, I selected the Price to Earnings (PE) Incl Xor (including extraordinary items), which is highlighted in the image above.  Then select the keyword for that factor using the WORDS box to the right. If you double click PEInclXorTTM, it should enter that term in the rules form below. You will first want to enter a rule that ensures that data exists for the fundamental you are testing, PEInclXorTTM in this example.  The rule for that is as follows:

PEInclXorTTM != NA // Has data for the fundamental being tested

Then you will want to rank all the stocks that remain after the filters and select the bottom 20 percent (i.e., the first quintile).  The following rule does that:

FRank(“PEInclXorTTM”,#Previous,#DESC) <= 20 //Select stocks in the 1st quintile (20th percentile)

Finally, I add a rule to provide the median value of the stock fundamental being tested in the results.  The following rule does that:

ShowVar(@PEInclXorTTMMedian,FMedian(“PEInclXorTTM”,#Previous)) //Show median value

Step 5: Run the screen

Now that all the rules have been added, you can hit the RUN SCREEN button as shown in the image below:

Run Screen button on Portfolio123

Running the screen will temporarily save your progress. However, before you jump to the results, you will want to adjust the screen settings.  Click on the SETTINGS tab that is circled in the screenshot below.

Screen results and Setting tab location

3 thoughts on “How to Backtest Stock Fundamentals Using Portfolio123

  • September 7, 2016 at 6:24 pm

    I have a question. How does one account for delisted or failing companies in this or any backtest?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.