Using ETF Internal Analytics to Identify Mean Reversion Opportunities (python)

Using ETF Internal Analytics to Identify Mean Reversion Opportunities (python)

Since I started producing the following graphic for the ETF Internal Analytics product, I found the weekly return bin information compelling. I became curious about whether there was an opportunity to be exploited in the distribution patterns. I distilled all the questions I had into two: 

  1. Does the percentage of ETF component stocks at various return levels provide actionable information?
  2. Can a long-short market-neutral strategy be constructed by analyzing the relative return dispersion of each ETF's stock components?

To answer these questions I used a combination of tools/data sources including State Street's SPDR Holdings data, the Yahoo Finance API, and Python. 

Read More

GET FREE FINANCIAL DATA W/ PYTHON (EARNINGS ESTIMATES-FROM YAHOO FINANCE)

Today I present a simple function to extract Earnings Estimates from Yahoo Finance. If you have any questions feel free to leave it in the comments. 

This code uses Python 3 on Windows 8.1 but could be easily adapted for Python 2 by changing the 'urllib' import. 

First we import the necessary packages into our programming environment. 


import pandas as pd
import urllib as u
from bs4 import BeautifulSoup as bs
import warnings
warnings.filterwarnings("ignore")

I also suppress warnings for the deprecation warning for the Pandas "Dataframe.convert_objects()"method within the scraper function that follows. 

This function takes the Yahoo Finance URL with our symbol of interest and uses BeautifulSoup to parse the resulting HTML. I also added some formatting code to clean up the readability of the headers. 


def _get_eps_estimates(url):
    try:
        html_source = u.request.urlopen(url).read()
        soup = bs(html_source, 'lxml')
        # 
        # table
        table = soup.find_all('table', attrs={'class': 'yfnc_tableout1'})
        header = [th.text for th in table[0].find_all(class_='yfnc_tablehead1')]
        header_title = header[0]
        header_cols = header[1:5]
        index_row_labels = header[-5:]
        body = [[td.text for td in row.select('td')] for row in table[0].find_all('tr')]
        body = body[1:]
        df = pd.DataFrame.from_records(body)
        df = df.ix[:, 1:]
        df.index = index_row_labels
        header_cols = pd.Series(header_cols)
        header_cols = header_cols.str.replace(
            'Year', 'Year ').str.replace('Qtr.', 'Qtr. ')
        df.columns = header_cols
        eps_est = df.convert_objects(convert_numeric=True)
    except Exception as e:
        print(e)
    return eps_est

Now let's test the function using the proper URL. I'm using the symbol 'SWKS' in this example.


symbol = 'SWKS'

base_url = r'http://finance.yahoo.com/q/ae?s={}+Analyst+Estimates'.format(symbol)
eps_est = _get_eps_estimates(base_url)
eps_est

Your output should appear like the following:

COMPOSITE MACRO ETF WEEKLY IMPLIED COST-OF-CAPITAL ESTIMATES VS. CUMULATIVE RETURNS (12/13/15)

WHAT IS THE "IMPLIED COST OF CAPITAL (ICC)" MODEL?

“In accounting and finance the implied cost of equity capital (ICC)—defined as the internal rate of return that equates the current stock price to discounted expected future dividends—is an increasingly popular class of proxies for the expected rate of equity returns. ”

— CHARLES C. Y. WANG; an assistant professor of business administration in the Accounting and Management Unit at Harvard Business School

The basic concept of the ICC model is that it is a forward looking estimate of the implied earnings growth rate of stock given the current stock price. It is calculated using a combination of equity book value and earnings forecasts.

To see a more involved explanation of the previous model I used see here.  

In the past I used a Multi-Stage Residual Income Model. However, this time around I've decided to use a simpler Single-Stage Residual Income Model for these estimates. I chose this because I believe the additional complexity is not warranted given my purpose which I will elaborate on further.

The Single-Stage Residual Income Model as defined by the CFA Institute is the following:

source: CFA Institute

'V' is the stock price at time 0, 'B' is the book value of equity at time 0, 'ROE' is return on equity, 'g' is an assumed long term growth rate and 'r' is the cost of equity/capital. The ICC model essentially solves for 'r' given the other inputs. 

WHY USE THE IMPLIED COST OF CAPITAL MODEL?

There is ongoing debate regarding the ICC model's application and accuracy as a proxy for expected returns as quoted by Charles C. Y. Wang. As an investor/trader I'm less interested in the academic debate and more intrigued by the intuition behind the model and its practical application as a relative value tool. 

I use the ICC model as a relative value measure to identify analyst/institutional expectations and sentiment between different market sectors at a point in time. 

For this purpose I believe it provides great insight. 

COMPOSITE ETF COMPONENTS FOR ICC ESTIMATES

Z-SCORE ICC ESTIMATES AND CUMULATIVE RETURNS COMPARISON CHART

The below plot gives visual representation of the ICC estimates. I z-scored both year-to-date cumulative returns and the ICC estimates so we can view them on the same scale. Examining this chart allows investors to quickly determine which market sectors are outperforming (underperforming) their respective Implied Cost of Capital Estimates. 

The extreme cases show where there are disconnects between the analyst community's forward earnings expectations and actual market performance. The plot is sorted left to right by ascending ICC estimates.

YEAR-TO-DATE LAST 247 TRADING DAYS 

Data Sources: YCharts.com, Yahoo Finance

Data Sources: YCharts.com, Yahoo Finance

LAST 126 TRADING DAYS

Data Sources: YCharts.com, Yahoo Finance

Data Sources: YCharts.com, Yahoo Finance

LAST 63 TRADING DAYS

Data Sources: YCharts.com, Yahoo Finance

Data Sources: YCharts.com, Yahoo Finance

LAST 21 TRADING DAYS

Data Sources: YCharts.com, Yahoo Finance

Data Sources: YCharts.com, Yahoo Finance

LAST 10 TRADING DAYS

Data Sources: YCharts.com, Yahoo Finance

Data Sources: YCharts.com, Yahoo Finance

CATEGORY AVERAGE ICC ESTIMATES

Long term growth rate (g) is assumed to be 2.5% reflective of our low growth high debt economic environment. 

ALL ETF ICC ESTIMATES BY CATEGORY

COMPOSITE MACRO ETF WEEKLY IMPLIED COST OF CAPITAL ESTIMATES vs. CUMULATIVE RETURNS (11/07/15)

WHAT IS THE "IMPLIED COST OF CAPITAL (ICC)" MODEL?

“In accounting and finance the implied cost of equity capital (ICC)—defined as the internal rate of return that equates the current stock price to discounted expected future dividends—is an increasingly popular class of proxies for the expected rate of equity returns. ”

— CHARLES C. Y. WANG; an assistant professor of business administration in the Accounting and Management Unit at Harvard Business School

The basic concept of the ICC model is that it is a forward looking estimate of the implied earnings growth rate of an equity security that is calculated using a combination of book value of equity and earnings forecasts.

To see a more involved explanation of the previous model I used see here.  

In the past I used a Multi-Stage Residual Income Model. However, this time around I've decided to use a simpler Single-Stage Residual Income Model for these estimates. I chose this because I believe the additional complexity is not warranted given my purpose which I will elaborate on further.

The Single-Stage Residual Income Model as defined by the CFA Institute is the following:

source: CFA Institute

'V' is the stock price at time 0, 'B' is the book value of equity at time 0, 'ROE' is return on equity, 'g' is an assumed long term growth rate and 'r' is the cost of equity/capital. The ICC model essentially solves for 'r' given the other inputs. 

WHY USE THE IMPLIED COST OF CAPITAL MODEL?

There is ongoing debate regarding the ICC model's application and accuracy as a proxy for expected returns as quoted by Charles C. Y. Wang. As an investor/trader I'm less interested in the academic debate and more intrigued by the intuition behind the model and its practical application as a relative value tool. 

I use the ICC model as a relative value measure to identify analyst/institutional expectations and sentiment between different market sectors at a point in time. 

For this purpose I believe it provides great insight. 

Z-SCORE ICC ESTIMATES AND CUMULATIVE RETURNS COMPARISON CHART

The below plot gives visual representation of the ICC estimates. I z-scored both year-to-date cumulative returns and the ICC estimates so we can view them on the same scale. Examining this chart allows investors to quickly determine which market sectors are outperforming (underperforming) their respective Implied Cost of Capital Estimates. 

The extreme cases show where there are disconnects between the analyst community's forward earnings expectations and actual market performance. The plot is sorted left to right by ascending ICC estimates.

year-to-date last 222 trading days 

Data Sources: YCharts.com, Yahoo Finance

Data Sources: YCharts.com, Yahoo Finance

last 126 trading days

Data Sources: YCharts.com, Yahoo Finance

Data Sources: YCharts.com, Yahoo Finance

last 63 trading days

Data Sources: YCharts.com, Yahoo Finance

Data Sources: YCharts.com, Yahoo Finance

last 21 trading days

Data Sources: YCharts.com, Yahoo Finance

Data Sources: YCharts.com, Yahoo Finance

last 10 trading days

Data Sources: YCharts.com, Yahoo Finance

Data Sources: YCharts.com, Yahoo Finance

CATEGORY AVERAGE ICC ESTIMATES

Long term growth rate (g) is assumed to be 2.5% reflective of our low growth high debt economic environment. 

ALL ETF ICC ESTIMATES BY CATEGORY

COMPOSITE MACRO ETF IMPLIED COST OF CAPITAL ESTIMATES

Earlier this year I used to publish a bi-weekly article using the "Implied Cost of Capital" model as an ETF relative value estimation tool. Unfortunately State Street began reporting obvious erroneous data points and eventually stopped providing certain fundamental data altogether. As a result I had to suspend publishing of my ICC estimates. 

Well thanks to YCharts.com and their excellent site I was able to find the requisite data needed to begin publishing my model estimates again. 

what is the "implied cost of capital (ICC)" model?

In accounting and finance the implied cost of equity capital (ICC)—defined as the internal rate of return that equates the current stock price to discounted expected future dividends—is an increasingly popular class of proxies for the expected rate of equity returns.
— CHARLES C. Y. WANG; an assistant professor of business administration in the Accounting and Management Unit at Harvard Business School

The basic concept of the ICC model is that it is a forward looking estimate of the implied earnings growth rate of an equity security that is calculated using a combination of book value of equity and earnings forecasts.

To see a more involved explanation of the previous model I used see here.  

In the past I used a Multi-Stage Residual Income Model. However, this time around I've decided to use a simpler Single-Stage Residual Income Model for these estimates. I chose this because I believe the additional complexity is not warranted given my purpose which I will elaborate on further.

The Single-Stage Residual Income Model as defined by the CFA Institute is the following:

source: CFA Institute

'V' is the stock price at time 0, 'B' is the book value of equity at time 0, 'ROE' is return on equity, 'g' is an assumed long term growth rate and 'r' is the cost of equity/capital. The ICC model essentially solves for 'r' given the other inputs. 

why use the implied cost of capital model?

There is ongoing debate regarding the ICC model's application and accuracy as a proxy for expected returns as quoted by Charles C. Y. Wang. As an investor/trader I'm less interested in the academic debate and more intrigued by the intuition behind the model and its practical application as a relative value tool. 

I use the ICC model as a relative value measure to identify analyst/institutional expectations and sentiment between different market sectors at a point in time. 

For this purpose I believe it provides great insight. 

 

category average icc estimates

Long term growth rate (g) is assumed to be 2.5% reflective of our low growth high debt economic environment. 

 

all etf icc estimates by category

 

z-Score icc estimates and cumulative returns comparison chart

The below plot gives visual representation of the ICC estimates. I z-scored both year-to-date cumulative returns and the ICC estimates so we can view them on the same scale. Examining this chart allows investors to quickly determine which market sectors are outperforming (underperforming) their respective Implied Cost of Capital Estimates. 

The extreme cases show where there are disconnects between the analyst community's forward earnings expectations and actual market performance. The plot is sorted left to right by ascending ICC estimates.

Data Sources: YCharts.com, Yahoo Finance

Data Sources: YCharts.com, Yahoo Finance