| Author: rgearyiii |
| Subject: GTR1 and Bear Catchers |
| Date: 9/29/2013 |
| Recommendations: 70 |
In http://boards.fool.com/a-simple-sma-tool-for-trading-2721524... I demonstrated how to build Bear Catcher I, a.k.a. the "SMA Slope Change" signal, and include it in backtests using the new GTR1 universe builder and import functions. In this post I demonstrate how to do the same for Bear Catcher III, also referred to by Zeelotes as "Dying Bullish Euphoria" and defined by mungofitch in http://boards.fool.com/getting-away-from-the-bear-27035352.a... . I also re-build the NH/NL signal described in http://boards.fool.com/gtr1-and-market-timing-30354312.aspx using new field functions that simplify its construction. Finally, I build a signal whose value gives the states of all three Bear Catchers at once and show how to apply it to a basic blend. New Signal Functions sgmin, sgmax, sgavg and sgwsum In order to facilitate the computation of more market timing signals such as Bear Catcher III, I`ve added four new signal functions to the latest version of the backtester at gtr1.backtest.org/2012 . All of them perform calculations on signal fields, i.e., fields that are logically guaranteed to have the same value for all investments on each market day in the backtest. As stated in my last post, when backtests are performed within "singleton universes" (universes consisting of the single investment produced by either a Yahoo! Finance ticker symbol or one screen with a holding period of one market day), the uniqueness of the investment guarantees that all fields qualify as signals. Thus these functions can always be used on any field in backtests within singleton universes. The four new functions have the following command line syntax: field field field field The functions sgmin, sgmax, sgavg compute the minimum, maximum and average, respectively, of the values that signal_field_ref had over the interval of consecutive market days consisting of N market days ending lag_days market days prior the current trading date. The function sgwsum computes the weighted sum of the values that signal_field_ref had over the interval of consecutive market days consisting of N market days ending lag_days market days prior the current trading date, where the weights for the N terms of the sum are weight1, weight2, ... weightN, listed in reverse-chronological order. As always with field functions, setting lag_days to zero results in computations that include values from the same market day close at which trades will take place for the current trading day. Also, lag_days is not subject to Field File Lag Adjustment or Price Lag Adjustment. When computation is performed over an interval of market days that begins before the backtest started, zero is assumed for the value of signal_field_ref on all market days prior to the beginning of the backtest. To ensure that the backtest report only covers the period where computations are based on real values, manually set the report`s starting date later than the default by an appropriate amount. Building Bear Catcher III The first step is to create a universe consisting of the S&P 500 as the only investment, which is done by going to gtr1.backtest.org/2012/universe.cgi and simply entering ^GSPC (Yahoo! Finance`s symbol for the S&P 500) in the slot for Screen 0, clicking "Build Universe", and clicking "Build a screen in this universe", which takes you to http://gtr1.backtest.org/2012/?ss4ff4rr4:%7bU:%7b!GSPC%7d%7d... . Next, create a field that detects whether an investment is at a 99-day high (at least as measured by closing prices only). The expression ratio(gprc(0),hgprc(1,98)) is the ratio of current closing g-price to highest closing g-price over the 98 market days before the current trading day. An investment is at a 99-day high if and only if this ratio is greater than 1. Therefore, if(ratio(gprc(0),hgprc(1,98))>1,1,0) equals 1 if the investment is at a 99-day high and 0 otherwise. Since the S&P 500 is the only investment in this universe, the field just defined is a signal, so it qualifies as an argument of sgmax. sgmax(if(ratio(gprc(0),hgprc(1,98))>1,1,0),0,99) equals 1 if and only if the S&P 500 has hit a new 99-day high at some point during the last 99 market days. Finally, in order for this signal to be importable, it must be labeled, so I label it BCIII. And of course BCIII also must be used in at least one step in order for the signal-building screen to run, so I add the step BCIII = 1, which allows the S&P 500 to be purchased if and only if the signal is bullish, with cash held otherwise. I have set the holding period to one market day in order to allow for daily response to the signal in the backtest (the holding period of the signal-building backtest does not affect the holding periods of importing screens). The resulting URL is http://gtr1.backtest.org/2012/?h1::BCIII:et1:BCIII:sgmax%28i... Here are the results of the backtest with the signal applied to holding the S&P 500 compared with a buy-and-hold of the S&P 500 over the same period (I`m fairly certain that BCIII was bearish at the beginning of 1974, so I haven`t bothered with starting the backtest 198 market days into the year): 19740104-20130927 S&P 500 BCIII Buy & Hold CAGR: 10.39 7.43 TR: 4919.94 1610.57 GSD(20): 13.46 17.46 DD(20): 8.47 11.77 MDD: -33.51 -56.78 UI(20): 6.96 15.60 Sharpe(20): 0.45 0.22 Beta(20): 0.64 1.00 TI(20): 8.95 3.47 AT: 0.48 0.00 Bear Catcher III produces a clear advantage by every measurement, at least when applied to the S&P 500 index on which it is based. Bear Catcher II (NH/NL) Revisited In http://boards.fool.com/gtr1-and-market-timing-30354312.aspx I demonstrated how to build Bear Catcher II (NH/NL) signals and used them in backtests of MI screens using the 2011 GTR1 backtester. I got the best results using a smoothed version of the signal that calculated the ratio between a weighted sum of the daily count of highs over the last 9 days and a weighted sum of the daily count of lows over the last 9 days, where both weighted sums used weights of 9, 8, 7, ... 1. For the sake of demonstrating the function sgwsum, I will rebuild that signal using the 2012 GTR1 backtester. I begin with the link (3) in that post and change the "2011" in the URL to "2012": http://gtr1.backtest.org/2012/?NHNLRatio:et-1:WeightedCountO... That works fine with the new backtester and database, but it can be greatly simplified with the function sgwsum, which I have applied here: http://gtr1.backtest.org/2012/?h1::NHNLRatio:gt1:CountOfHigh... Instead of repeatedly importing CountOfHighs and CountOfLows with lags varying from 0 to 8, I have imported both of them once with lag 0, and then applied sgwsum to each with lag 0 and weights 9, 8, 7, ... 1. I have also added the Universe URL for the Yahoo! ticker symbol ^IXIC so that the signal can be meaningfully backtested as it is constructed. Here are the results of the backtest requiring the NH/NL ratio to be greater than 1 for holding the Nasdaq Composite Index compared with a buy-and-hold of the Nasdaq Composite Index over the same period: 19740104-20130927 Nasdaq Composite Index BCII Buy & Hold CAGR: 13.28 9.77 TR: 13882.26 3918.69 GSD(20): 15.24 24.58 DD(20): 8.86 16.77 MDD: -50.67 -77.93 UI(20): 11.05 31.01 Sharpe(20): 0.60 0.31 Beta(20): 0.51 1.18 TI(20): 16.64 5.74 AT: 2.93 0.00 Bear Catchers Combined (BCC) In this next link, I have created a new signal field labeled BCC (for Bear Catchers Combined) that gives the eight possible states of all three Bear Catchers as an integer from 0 to 7: http://gtr1.backtest.org/2012/?h1::BCC:et7:SMADiff:imports%2... The definition of BCC itself is as follows: BCC: linear(1,if(SMADiff>0,1,0),2,if(NHNLRatio>1,1,0),4,BCIII) Bear Catcher I is converted to a binary value (1 = bullish, 0 = bearish) according to whether SMADiff is positive. Bear Catcher II is converted to a binary value according to whether NHNLRatio is greater than 1. Bear Catcher III (Dying Bullish Euphoria) already is a binary value by its construction. BCC is equal to 1 times Bear Catcher I`s state, plus 2 times Bear Catcher II`s state, plus 4 times Bear Catcher III`s state, which produces an integer from 0 to 7, each corresponding to one of the eight possible states that all three Bear Catchers can be in. The following table summarizes the eight states and the value of BCC: BCC BCI BCII BCIII (Bear Catchers Combined) (SMA Slope Change) (NH/NL Ratio) (Dying Bullish Euphoria) 0 Bear Bear Bear 1 Bull Bear Bear 2 Bear Bull Bear 3 Bull Bull Bear 4 Bear Bear Bull 5 Bull Bear Bull 6 Bear Bull Bull 7 Bull Bull Bull At the end of this post is a list of all changes in BCC from 1974 to the present (this information can be easily obtained by selecting "Signal Values" for inclusion in a Detailed Report on the backtest defining the signal). The next table summarizes the values you can set BCC equal to in backtests to require certain Bear Catcher states: BCC Bear Catcher State 1!3!5!7 BCI Bullish 2!3!6!7 BCII Bullish 4!5!6!7 BCIII Bullish > 0 At least one Bullish 3!5!6!7 At least two Bullish 7 All Bullish 0!2!4!6 BCI Bearish 0!1!4!5 BCII Bearish 0!1!2!3 BCIII Bearish < 7 At least one Bearish 0!1!2!4 At least two Bearish 0 All Bearish And here is a link to a backtester form with BCC imported, ready for steps to be added: http://gtr1.backtest.org/2012/?ss5ff5rr1:BCC:imports%280,BCC... Zero lag is used throughout the construction (as I recommend), so all lagging can be controlled in the one lag argument of imports, currently set to 0. If you omit the lag argument (the third one), it will default to 1. Whether omitted or not, its value is subject to Field File Lag Adjustment, which defaults to 0 in backtests and -1 in screening. You can of course tweak this URL to apply different lags to specific Bear Catchers (we saw that Bear Catcher I, SMA Slope Change, did better lagged by one market day) before the import of BCC. As an example, the following table shows results for the WER P/E Bottom 10 screen with various BCC requirements: 19920103 to 20130927 WER P/E Bottom 10 (1) (2) (3) (4) Bullish Req`d: All Any Two NH/NL Only None (20-Cycle Avg) CAGR: 27.66 32.38 34.55 31.23 TR: 19639.76 43236.04 61534.76 38728.31 GSD(20): 20.56 24.19 22.51 30.13 DD(20): 8.76 12.01 9.39 17.51 MDD: -24.23 -30.46 -24.23 -55.22 UI(20): 5.32 7.84 5.33 15.56 Sharpe(20): 1.21 1.25 1.38 1.06 Beta(20): 0.43 0.57 0.52 0.99 TI(20): 54.36 48.67 56.81 28.35 AT: 8.09 9.35 9.77 7.39 As Zeelotes found with other investments, NH/NL is the star of the Bear Catchers. The links for the four tests are as follows: (1) http://gtr1.backtest.org/2012/?h1::BCC:et7:pe.w:gt0:pe.w:bn1... (2) http://gtr1.backtest.org/2012/?h1::BCC:et3!5!6!7:pe.w:gt0:pe... (3) http://gtr1.backtest.org/2012/?h1::BCC:et2!3!6!7:pe.w:gt0:pe... (4) http://gtr1.backtest.org/2012/?pe.w:gt0:pe.w:bn10 Note that in the first three tests (where BCC is used), I have reduced the holding period from 20 market days to one market day in order to allow for daily response to the signal, but I have added holding conditions that keep stocks that have been held for less than 20 market days as long as the signal remains bullish. This does throw away a lot of statistical significance, however, since a lot less of the daily data is used in testing the screen. Also note that I have kept BCC`s lag at 0, since it isn`t all that hard to produce an instantaneous computation of the signal while trading near the market close. Applying Signals to Basic Blends I now demonstrate how to apply market timing signals to a basic GTR1 blend, such as this one: http://gtr1.backtest.org/2012/blend.cgi?%7b1:timely.v:et1:rr... First, run the blend, click "Add blend to new universe", build the universe and click "Build a screen in this universe", which should take you to http://gtr1.backtest.org/2012/?ss4ff4rr4:%7bU:%7b%7b1:timely... . This step has created a new custom universe whose investments consist of all cycles (in this case, 60, which is the least common multiple of the holding periods of all screens in the blend) of the blend. Next, add whatever market timing signals you want to use and the steps that apply them. I`ve added the signal BCC I created above requiring at least one Bear Catcher to be bullish: http://gtr1.backtest.org/2012/?ss5ff5rr1:BCC:gt0:BCC:imports... Next, add "dhp = 0" (translated "[Days into Hold Period] == 0") as the final step. This step ensures that the cycle that is rebalancing is the only cycle that is ever bought; otherwise, all (in this case, 60) cycles would be bought. Finally, set the holding period to one market day and add a holding condition that keeps investments as long as they satisfy your market timing steps, which in this case is just step0: http://gtr1.backtest.org/2012/?h1::BCC:gt0:dhp:et0:htd0:BCC:... Here are the results compared with those of the blend without any market timing: 19740107-20130927 (1) (2) BCC req`d: BCC > 0 None CAGR: 27.54 26.97 TR: 1532566.38 1407674.25 GSD(20): 19.08 22.37 DD(20): 10.78 13.75 MDD: -31.65 -54.52 UI(20): 5.95 9.35 Sharpe(20): 1.20 1.05 Beta(20): 0.73 0.94 TI(20): 28.90 22.47 AT: 7.56 6.08 Note the huge reduction in maximum drawdown. Robbie Geary BCC signal changes 19740107 2 19740109 0 19740227 2 19740329 0 19750116 2 19750127 6 19750422 7 19751203 3 19751208 1 19751216 3 19760105 7 19761119 6 19761122 7 19770209 6 19770210 2 19770314 3 19770331 2 19780424 6 19780607 7 19780627 6 19780717 7 19781024 5 19781206 7 19781214 5 19781215 7 19781218 5 19790102 7 19790201 3 19790306 2 19790313 3 19790327 7 19790517 6 19790713 7 19790723 6 19790806 7 19791015 5 19791116 7 19800306 5 19800328 4 19800411 5 19800418 4 19800429 5 19800507 7 19801215 5 19801219 7 19810422 3 19810708 1 19810714 3 19810724 1 19810728 3 19810729 1 19810730 2 19810812 3 19810819 1 19810827 0 19811014 2 19811015 0 19811103 2 19811119 0 19811127 2 19811208 0 19820408 2 19820520 0 19820825 2 19820831 6 19821008 7 19831025 5 19831117 7 19831215 5 19840103 7 19840130 5 19840210 4 19840301 0 19840803 4 19840808 6 19840820 4 19840821 5 19840822 7 19840910 6 19840920 7 19841002 5 19841011 4 19841018 6 19841029 4 19841106 5 19841107 7 19841115 5 19841221 7 19850912 5 19851018 7 19860716 5 19860819 7 19860909 5 19870108 7 19870416 5 19870501 7 19870521 5 19870601 7 19870918 5 19870929 7 19871009 5 19871028 4 19880115 0 19880225 2 19880317 6 19880512 4 19880603 6 19880810 7 19880812 5 19880906 7 19881108 5 19881227 7 19890706 5 19890710 7 19891017 5 19900103 7 19900115 5 19900301 1 19900319 3 19900322 1 19900518 3 19900523 7 19900625 5 19900703 7 19900719 5 19900814 4 19901204 0 19910118 4 19910128 6 19910206 7 19911127 5 19911202 7 19920409 5 19920414 7 19920605 3 19920617 1 19920707 3 19920729 7 19920825 5 19920904 7 19920924 5 19920925 7 19920928 5 19921020 6 19921102 7 19930730 3 19930818 7 19931124 5 19931201 7 19940330 5 19940413 4 19940429 5 19940516 4 19940524 5 19940601 7 19940617 6 19940621 4 19940627 0 19940816 4 19940818 6 19940825 7 19940929 6 19941006 4 19941012 6 19941108 4 19950109 6 19950117 7 19950120 3 19950126 1 19950203 7 19960627 5 19960701 7 19960710 5 19960808 7 19960814 5 19960819 7 19961031 5 19961107 7 19961218 5 19961219 7 19970318 5 19970508 7 19971114 5 19971120 7 19971215 5 19980102 7 19980113 5 19980121 7 19980521 5 19980720 7 19980722 5 19981104 7 19981211 5 19981228 7 19990210 5 19990426 7 19990805 5 19990823 7 19990922 5 19991104 7 20000322 5 20000323 7 20000403 5 20000713 7 20000725 5 20000815 1 20000828 3 20000831 7 20000920 5 20001010 4 20010112 6 20010125 2 20010223 0 20010420 2 20010620 0 20010626 2 20010813 0 20010815 2 20010816 0 20011106 2 20020114 3 20020118 2 20020208 0 20020211 2 20020222 0 20020228 2 20020530 0 20021105 2 20021113 0 20021118 2 20021219 0 20030103 2 20030128 0 20030324 2 20030506 7 20040507 5 20040527 7 20040706 3 20040709 1 20040826 3 20040929 1 20040930 3 20041018 1 20041019 3 20041020 1 20041022 2 20041104 6 20041108 7 20050126 5 20050127 7 20050315 5 20050523 7 20051010 5 20051012 4 20051031 5 20051103 7 20060517 5 20060602 7 20060608 5 20060706 7 20060710 5 20060823 7 20060824 5 20060830 7 20070305 5 20070322 7 20070518 5 20070522 7 20070627 5 20070628 7 20070723 5 20070906 7 20070910 5 20070920 7 20071018 5 20071128 4 20071205 5 20080115 4 20080303 0 20080815 2 20080819 0 20090413 2 20090601 6 20090709 4 20090716 6 20090804 7 20091102 5 20091109 7 20100521 5 20100618 7 20100623 5 20100708 4 20100715 5 20100727 7 20100812 5 20100831 4 20100909 6 20100914 2 20100915 3 20101005 7 20110316 5 20110323 7 20110524 5 20110531 7 20110607 5 20110627 7 20110729 5 20110817 4 20110920 0 20111028 2 20111102 0 20111207 2 20111209 0 20120105 2 20120110 6 20120203 7 20120411 5 20120417 7 20120514 5 20120618 7 20120725 5 20120807 7 20120822 3 20120906 7 20121024 5 20121107 7 20121108 5 20121129 7 |