Sales Size for Ranking a Stock Universe - Template Fundamental Algo

Many of our funded authors have relied upon price driven strategies. As we continue to evaluate and add algorithms to our portfolio, we will be especially interested in new strategies that take advantage of a broader range of fundamental factors.

# Sales Size

This is a valuation metric. We expect companies that generate more revenue per dollar of market cap to generate outsized returns compared to a company of comparable size that generates less revenue. Our factor is calculated as the sale of revenue from goods and services over the last twelve months divided by market cap. We would naturally expect larger companies to generate more raw sales revenue than smaller companies, so we try to remove that from the equation and get at pure value.

As we look to expand the set of algorithms receiving allocations over the next few months we expect to give preference to new ideas that take advantage of a broader range of fundamental factors.

To get started, clone this algorithm, improve it with your own ideas, and submit it to the Quantopian Contest.

N.B. As implemented here, this algo doesn't fully meet all of the criteria for entry in the daily contest so we're leaving that as an "exercise for the reader".

# Fundamental Sample Strategies Library

To see all of our fundamental sample strategies, please visit our library post. We will be adding more templates in the future, so keep an eye on the "Algo Template" tag in the Quantopian forums: https://www.quantopian.com/posts/tag/Algo-Template/newest.

Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
 Returns 1 Month 3 Month 6 Month 12 Month
 Alpha 1 Month 3 Month 6 Month 12 Month
 Beta 1 Month 3 Month 6 Month 12 Month
 Sharpe 1 Month 3 Month 6 Month 12 Month
 Sortino 1 Month 3 Month 6 Month 12 Month
 Volatility 1 Month 3 Month 6 Month 12 Month
 Max Drawdown 1 Month 3 Month 6 Month 12 Month
import numpy as np
import quantopian.algorithm as algo
import quantopian.optimize as opt
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data import factset

OUTLIER_THRESHOLD = 3 # Maximum zscore that is not an outlier
ZERO_THRESHOLD = 0.1 # Minimum zscore we allow before dropping security

def initialize(context):
algo.attach_pipeline(make_pipeline(), 'alpha_factor_template')

# Schedule our rebalance function
algo.schedule_function(func=rebalance,
date_rule=algo.date_rules.week_start(),
time_rule=algo.time_rules.market_open(),
half_days=True)

# Record our portfolio variables at the end of day
algo.schedule_function(func=record_vars,
date_rule=algo.date_rules.every_day(),
time_rule=algo.time_rules.market_close(),
half_days=True)

def make_pipeline():
# Setting up the variables
revenue_ltm = factset.Fundamentals.sales_ltm.latest/\
factset.Fundamentals.mkt_val_public.latest
alpha_factor = revenue_ltm.log()

# Standardized logic for each input factor after this point
alpha_w = alpha_factor.winsorize(
min_percentile=0.02,
max_percentile=0.98,
)
alpha_z = alpha_w.zscore()

outlier_filter = alpha_z.abs() < OUTLIER_THRESHOLD
non_zero_filter = alpha_z.abs() > ZERO_THRESHOLD

outlier_filter & \
non_zero_filter

pipe = Pipeline(
columns={
'alpha_z': alpha_z,
},
screen=universe
)
return pipe

context.pipeline_data = algo.pipeline_output('alpha_factor_template')

def record_vars(context, data):
# Plot the number of positions over time.
algo.record(num_positions=len(context.portfolio.positions))
algo.record(leverage=context.account.leverage)

def rebalance(context, data):
# Retrieve pipeline output
pipeline_data = context.pipeline_data

alpha_weight = pipeline_data['alpha_z']
alpha_weight_norm = alpha_weight / alpha_weight.abs().sum()

objective = opt.TargetWeights(alpha_weight_norm)

# No constraints, want all assets allocated to
constraints = []

algo.order_optimal_portfolio(
objective=objective,
constraints=constraints
)
There was a runtime error.
Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

9 responses

IMO algo trading can find edge with respect to technicals, but not with so much with fundamentals. I'd be surprised if a successful algo can be built using just fundamentals. I personally don't see much value in the factset data because it's stale and only captured on a qtrly or yrly basis... even the valuation multiples i believe aren't calculated using current price. I could be proven wrong, but imho focusing on fundamental data is a distraction.

Take a look at pre-2016 FCF yield as a factor, that was pretty successful. Based on my experience, technicals could just as easily be replaced with a coin flip. In order to find alpha you need to do something smart, something different that people won't have thought of before in an attempt to carve out your niche. Blindly following a technical indicator (or a combination of indicators) won't do much, nor will blindly following any factor (including fundamental) that millions of people are aware of.

You're going to struggle to find a technical or fundamental factor that will give you an edge once slippage and commission is factored in, ignore the distractions and carve out your niche.

Hi Jay Ross

I respect your opinion, however there are hedge funds who do use fundamental data and are succesful ( see 2sigma and AQR for example)
You should their blog posts. Regarding the fact that the valuation multiples are not calculated using current price, it's easy to calculate it yourself (They often perform better using current price).

Hi Pieter, it was my understanding that 2sigma, and AQR primarily have been building algos around technical analysis, but I can be wrong and things may have changed, but those blog posts do seem more oriented towards TA. Also take a look at job postings for those firms, they're not looking for CFAs. I've worked at HFs which employ very successful algos and they were all focused on technicals. The bulk of any Quants success in general, I am willing to bet has come from trading on technicals. Humans have more edge in fundamental investing because they can source more information and form opinions based on a variety of non-public information.

@Quant Trader - ill take a look at FCF yield, thanks

As far as I've been able to surmise, AQR is primarily based around factor investing (momentum, size, value etc) not technicals and Two Sigma does most things, but their more popular fund is futures arbitrage I think?

Re: AQR, Cliff wrote his thesis on momentum investing... which is technical analysis.

While nobody today runs mutual funds by seeking stocks that exhibit candlestick or head-and-shoulder patterns, technical analysis by another name remains alive and well. Today, it is called momentum investing. To be sure, momentum investing is a dressed-up version of technical analysis, replete with academic support and the attempt to explain why the strategy is a "risk factor," but it is nonetheless technical analysis: a signal based solely on a security's price behavior. The idea, of course, is nothing new. Back in the day, the approach was called either price momentum or relative strength--the latter being such a popular term that in the 1980s, newcomer Investors Business Daily trumpeted its relative-strength data as being a prime advantage over incumbent The Wall Street Journal. Whatever its name, favoring stocks that had led the way over the previous several months--and avoiding those that had lagged--was popular long before the academics offered proof. Which, surprisingly, they did. Ironically, among the early proponents of momentum was a student of Gene Fama's, Cliff Asness (founder of AQR), who documented the strategy's success in his 1995 doctoral thesis.

Trust me, both are using more Technicals than Fundamentals. I should be clear though, over longer time horizons technical analysis becomes less successful and is most optimal for intraday strategies. The opposite is true of Fundamental strategies.

Oh right, if we're including factors such as mean reversion and momentum in the 'technicals sphere' I rescind my previous statement that 'technicals could just as easily be replaced with a coin flip'. I naively assumed you were talking about chart patterns.

I'd say it depends on the time horizon. "The market in the short term is a voting machine, in the long term its a weighing machine". To the effect that fundamentals matter, they certainly matter more in the long run because they directly indicate a company's ability to both weather storms and to drive growth through asset monetization efficiently.

But from what I've seen so far on all the strategies pertaining to fundamentals on Quantopian, in the short term, they are on par with chance (like in the the Machine Learning Tutorial). This is also why Graham and Buffett never engaged in short-term trading, they knew that their skill sets gave them an advantage for picking the best weights for the weighing machine rather than votes in the voting machine.

In shorter term horizons, from what I can see, technical indicators and and pricing action (such as bid/ask spreads, volume, momentum, support/resistance levels, etc.) are more robust indicators.

Short term horizons buy and sell the sizzle, long term horizons buy and sell the steak.

@Jay Ross - Just look at ARQ publications. It is quite evident that they use fundamental data extensively. It's hard to manage large sums of assets using just technical signals.