September 9

18 comments

# Can You Short The S&P Successfully?

By David Bergstrom

September 9, 2019

Build Alpha, Dave Bergstrom, EasyLanguage

A short signal for the S&P500? Believe it or not, some do exist. Although these can often be hard to find they can also contribute greatly to your success – so tons of traders search endlessly for a complimentary short system or two for their portfolios.

I want to talk about a simple short edge that I have recently been tweeting about for the past year or so as it has been an interesting signal as of late. It is nothing more than a short signal – not a complete system! The sample size is not great, but it is still noteworthy.

### Sigma Score

The raw signal itself is just a +2 sigma move based on rolling 20 day (historical) volatility. A sigma score or “z score” is simply a way to express something in terms of standard deviation units. For example, a sigma of 1.5 signifies a value that would allow us to fit 1.5 standard deviations between the mean and the current value. Note: That mean is zero in this case due to standardization.

The trading idea being that the market has moved up too much too fast and some short-term pause or price retraction could be expected.

So how do we calculate sigma score? Below is simple python code using Build Alpha’s python environment for creating custom signals. (Another example: buildalpha.com/python)

Step 1. Calculate the natural log of one bar price changes
Step 2. Calculate the rolling average of the price changes
Step 3.  Calculate the rolling standard deviation of the price changes
Step 4. Calculate the Z score or sigma score which is defined as z = (value – average) / standard deviation.
Step 5.Create python list named Signal that contains 1 for true signal or 0 for false signal.

There is also an ELD with TradeStation code attached that contains a simple function for sigma_score(lookback) that will do the same calculation.

### Performance

Below you can see the equity curve from 2002 to 2018 if one were to have sold short (1 contract) all +2 sigma score days and hold exactly for one trading day (entry and exit both executed next bar open). No stop or profit target included.

It is not an excellent edge by any means, but a short signal to persist while the market has gone straight up is always worth keeping tabs on. Below you can see the e-ratio for this event. (Learn more about eratio here: buildalpha.com/eratio).

You can see it peaks at 1 bar hold but maintains almost 0.30 units of volatility over normal (1.00) so longer hold times might not be out of the question for this edge – but that will be left for further research. A better idea might be to use this daily signal as a multi-timeframe filter for some intraday short systems as the peak is clearly at x = 1.

I am a quantitative trader with a high frequency,  market-making firm but also recently started developing the Build Alpha trading software which has the ability to create, stress test, and produce tradeable code for hundreds of systematic trading strategies. All of this can be achieved with NO programming.  However, I recently added a Python development environment to allow sophisticated users a bit more flexibility. I can be reached at David@buildalpha.com or on twitter @dburgh.

-- Dave Bergstrom from Build Alpha

## Alpha Compass!

### The complete, step-by-step formula to build winning strategies with Build Alpha without coding.

I've created an excellent on-demand video course on how to best use Build Alpha. The course is called Alpha Compass, and it's where I show you how to use it and my best tips on building strategies with Build Alpha.

The course is closed right now. But get notified when it becomes available. You need to be on my mailing list to get access to join Alpha Compass.

Alpha Compass Waiting List!

The Alpha Compass course is closed. Get on the waiting list to be notified when a becomes available.

By signing up you agree to our terms

David Bergstrom

##### About the author

My name is David Bergstrom, and I am the guy behind the Build Alpha software. I have spent many years researching, building, testing, and implementing market making and trading strategies for a high frequency trading firm, a handful of CTAs, individual clients, registered money managers, and even aspiring retail traders. I am a self taught programmer who uses C++, C#, Python, Perl, Java and even TradeStation’s EasyLanguage. Most of my experience has led me to a series of repeatable processes to find, create, test, and implement trading ideas. Build Alpha is the culmination of this process from start to finish.

## Unlock the Power of the Money Flow Indicator

• Simon Lee says:

Dave, where can I find the TwoSigma in the current BuildAlpha?

• Hey Simon,

The complete python code is in the private user forum so you can copy and paste it into Build Alpha. It is not a pre-built signal (yet) although I can simply add in next update or so.

Thanks,
Dave

• Nick says:

Hello there,

I imported the ELD in MultiCharts 10 but I get very different results. I also did this in excel and results are also different. Any ideas?

• Hey Nick,

I’m not sure as I cannot see what you’re doing. I am able to replicate in both, however. You can send me an email and I will send you a full excel sheet (with formulas).

Some things off the top of my head that could be your issue
-data differences (not sure your provider in MC)
-make sure using natural log
-Jeff and I both used \$5 commission and \$30 slippage
-make sure you use sample standard deviation and not population standard deviation as that could change some fringe signals. (in excel that is stdev.s())

Thanks,
Dave

• Nick says:

Hello Dave, could you please post here yearly returns of this system?

• Sure, Nick. I want to note this is a simple foundational edge and should not be considered a full fledged trading “system”. Also, these returns shouldn’t drive any decisions you make – speak to a financial advisor, please.

But these are the returns copy and pasted from the TradeStation strategy report from the ELD file. Please note these are for 1 contract.

1/1/2017 \$412.50 1.17%
1/1/2016 \$4,725.00 15.50%
1/1/2015 (\$1,487.50) -4.65%
1/1/2014 \$662.50 2.12%
1/1/2013 (\$25.00) -0.08%
1/1/2012 \$637.50 2.08%
1/1/2011 \$2,375.00 8.38%
1/1/2010 (\$300.00) -1.05%
1/1/2009 \$487.50 1.73%
1/1/2008 \$4,312.50 18.10%
1/1/2007 (\$175.00) -0.73%
1/1/2006 (\$400.00) -1.64%
1/1/2005 \$1,250.00 5.40%
1/1/2004 \$900.00 4.04%
1/1/2003 (\$275.00) -1.22%
1/1/2002 \$2,725.00 13.76%
1/1/2001 (\$300.00) -1.49%
1/1/2000 \$100.00 0.50%

• Nick says:

It is obvious to even a beginner in this business that this is an optimized system to catch downtrends in prices. All gains come from either bear markets or corrections and interim returns are random. The optimization was done for the rolling period and as it happens 20 is or is near the optimum value that gives the nest curve fit to historical data. A Runs Test with the annual returns above produces a p-value equal to 0.13524 for R = 1 indicating no evidence against randomness in results. The take is that these optimized strategies are no good examples of what can be achieved by technical trading and maybe offer the wrong impression especially to those who are not familiar with statistical analysis. For a statistician like me it is easy to see immediately that these results are random without even looking at the code of the system. This is no matter of a foundational edge because there is no edge of any kind in this system but what you see is a result of curve fitting.

As far as this site goes I have seen a few systems in the past that I took the time to analyze and they were actually good in statistical sense.

• Nick says:

Correction: “optimum value that gives the best curve fit to historical data. A Runs Test with the annual returns above produces a p-value equal to 0.13524 for R = 11 indicating”

• Nick, the e-ratio shows that there is more favorable movement following the signal than there is adverse movement. That is the most rudimentary definition of edge. Point blank.

My intentions were not to give away a great short strategy (which are nearly impossible on recent S&P data). Those are kept in-house and certainly not given away for free! Furthermore, I was looking for an example that would lend itself to an easy to understand snippet of python code and that would also be easily reproduced in TradeStation’s Easy Language.

20 days was not optimized but chosen because that is a roughly a typical month in terms of trading days. It is also a nice round number – simple as that.

Matter of fact, a lookback of 20 was the sixth best value optimizing +/- 20% from the value of 20 (16 to 24). If you know anything about me then you know that I really don’t encourage optimization of parameters either.

This signal actually works great as a filter for intraday short strategies, but I cannot give away all my goodies!! I did hint at this in the article, however.

All of your comments have been negative and for no reason. If you don’t like the article then I’m sorry. I’m also sorry you had trouble replicating the code (even though given in two languages).

I immediately offered to help and even created an excel spreadsheet reproducing the exact results, but you never took me up on the offer.

That being said, I don’t wish to continue this conversation with you as it serves neither of us any good. I wish you the best and appreciate the read.

Dave

• Nick says:

I am stunned by the response. This is supposed for be a place for people to exchange ideas and learn. I do not think my critic of the results was in any way an ad hominen attack. Maybe you have not tried to publish a paper in a peer-reviewed journal to then get a flavor of anonymous criticism. Here at least you get a chance to reply. If you are not interested in criticism about a system and claims you have made in public, maybe some other people are.

By the way the z-score is old and appeared in the trading literature in 90s if I recall correctly. Maybe you can see why this is a fluke if you try a highly correlated contract like Nasdaq futures. You will find out that it is a failure there as I recall.

Your e-ratio does not measure the edge but the efficiency of the optimization process to get the optimal results. Over fitted systems just like this one either via parameter optimization or by suitable market selection (applies in this case too) behave robustly with respect to variations in key parameters and metrics because they are optimized. When any measure of robustness is used to rank in-sample performance it then becomes integral part of the optimization process.

“… but you never took me up on the offer.”

I have no idea of what offer you are talking about. Maybe someone with the same name?

I suppose you can come up with a better system we can try to evaluate here? There have been some good ones in this site in the past by other authors and Jeff in particular as I remember.

• The offer I was referring to is when you were unable to reproduce results. I offered to email you an excel sheet replicating the results with exact formulas. An offer that still stands.

I already mentioned this is not optimized but you continuously harp on that. As mentioned in my last response the parameter setting in the article ranked 6th of 9 in terms of max p&l when testing plus or minus 20% from the setting used in the article – clearly not the optimal choice.

Regarding trying on another highly correlated instrument as suggested… it actually shows profit on NQ, YM, SPY, TF, SB, AD, TY, FV.

I am not against peer review or honest back-and-forth, but all of your comments from the go seemed aggressive.

Again, you keep referring to it as a “system” even though I specifically mentioned multiple times not to consider it as a full-fledged system. You continue to evaluate it as such and that is probably the disconnect.

I’m actually trying to end this cordially and you’re still on the offensive.

• Nick says:

“The offer I was referring to is when you were unable to reproduce results.”

Unable? I just wanted to check your results because your presentation was seriously incomplete. I am not supposed to produce any results neither I want to. You have assumed the task of doing that. But I can analyze results and it seems you either do not know how to do that or you do not want or you even do not like it. It seems you want people to take your results on face value. That is bad, undemocratic and defensive.

S&P 500 futures started back in 1982. Why don’t you show the results starting in 1982 since data is available?

What you presented is an optimized system but appears you don’t understand fully what optimized means. It is optimized because

1. You selected an instrument it worked best

2. You selected a parameter that generates top performance

3. You selected a backtest period where this system worked

Obviously you are trying to get traffic to a site of yours but why couldn’t you produce something better and of value to the audience here? Borrowing an idea that was analysed in trading magazines 20 years ago and presenting it as something that has potential value when in reality it is over-fitted to two bear markets is not a sensible way to gain respect. Can you produce something that is genuinely interesting and has merit or are you just interesting in getting traffic to your site in a hurry without even offering some performance statistics? If you can produce something interesting I would be the first to concede to that. But I highly doubt it because I sense some serious holes in your understanding of trading system development.

Of course I am also inclined to stop any interaction with you since you are not willing to accept criticism unfortunately.

• Again with an attack. You just stated “The presentation was seriously incomplete” and “that I don’t know how to analyze results”.

S&P500 e-mini futures started in 1997 not 1982; this was the contract I used in the article.

To combat your same claims for the 100th time…

1. You selected an instrument it worked best
False, performance actually was better on two of the other instruments I listed

2. You selected a parameter that generates top performance
False, as mentioned twice before, the parameter setting was 6th best of 9. Not even in top half.

3. You selected a backtest period where this system worked
You mean the life of the contract? then yes.

I tried to present an edge that could be helpful and something for people to explore. I think what you want is an out of the box trading system and I’m sorry I did not provide an entire strategy for you in this article.

You keep pressing about performance results when I specifically mentioned this is not a full fledged system which should not warrant that type of analysis as this is just something to build on.

• Dee says:

I think this is a great time, now at the start of 2023, to note that the system’s edge proved to be robust over the five *out of sample* years since your comment. Your comment didn’t age at all well.

• ari says:

isisiiisn’t this indicator, a clone of the conventional universal channel index. wawait for cci to hit +200 then short. use 20 as length for input. ??

• Hey Ari,

If you’re referring to commodity channel index (CCI) then the answer is no.

CCI is similar in the fact that it subtracts a mean, but it is actually the most recent mean and not a rolling mean. It also multiplies the denominator by a seemingly arbitrary 0.015 which z score does not. It also uses average deviation instead of standard deviation. Finally, the CCI’s initial calculation is on average of high, low and close whereas sigma score uses the natural log of first differences.

If anything, CCI is a transformation of sigma score. Sigma score is a well known statistical property that far out dates CCI and technical analysis.

Thanks,
Dave

• Shawn says:

Great stuff, Dave. Looking forward to the next BA update!

• {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}