Re: [amibroker] Re: code for Clenow book

 

Thanks Larry for the great explanation. I will test the ranking suggestions tomorrow!
 
Best regards
Bruce W.
 
Sent: 25 June, 2016 10:29 PM
Subject: Re: [amibroker] Re: code for Clenow book
 
 

Bruce, my last post was meant to offer several variations on Rule #1 out of many rules yet to come. The Explorations, are not needed in the actual trading system afl.  I included them to illustrate what those bits of code were doing.

 

Original rules suggested trading on Wednesday, but IMHO for backtesting we need to write the code to only include days we can actually trade. Occasionally Wednesday will be a market holiday (Christmas, New year's Day). One of our bright forum users can help us out and come up with a code that trades the Third Trading Day of the week (or alternate week).

 

Next rule,

Rank all stocks based on volatility adjusted momentum.

 

Obviously there are several different ways to quantify "volatility adjusted momentum". Those who have read this excellent book know we will use annualized exponential regression slope, calculated on the past 90 days, and then multiply it with the coefficient of determination (R2).

 

If Tomasz is reading this, I have a pet peeve about the lack of a built in AmiBroker coefficient of determination. Come on and build one into AmiBroker!  See here https://groups.yahoo.com/neo/groups/amibroker/conversations/messages/193495

 

But I am strange that way

 

Back to the model, chapter 7 has an example spreadsheet so I just kept the column headings in the code. You can obviously come up with something more descriptive. 

////////////////////////////////////////////

// the calculation for ranking

////////////////////////////////////////////

 

colD = log(Close ); // the natural log of the close

 

colE = LinRegSlope( colD, 90 ); // this gives the slope of the regression line

// and we've manipulated it from dollars/day to average percentage move/day

 

colF = ( ( exp( colE ) ) ^ 250 ) - 1 ;

// we took the natural log so now reverse that and e raised to power of colE

// lets annualize it to get percentage move per year, so ^ 250 trading days (approx/year)

 

// strangely and unfortunately AmiBroker doesn't have R-Squared built in

colG = ( Correlation( Cum( 1 ), colD, 90 ) ^ 2 ); // 90 day R-Squared of column D, the log(C)

 

AdjustedSlope = colF * colG;

 

// this will ultimately be a Long Only Rotational system

// slope can be negative, and EnableRotational would initiate Short trades

// so a simple little manipulation will preserve rank and eliminate negative scores

 

score = AdjustedSlope + 100;

PositionScore = IIf( Rotate, score, scoreNoRotate ) ;

 

///////////////////

 

I noticed that my code is slightly different than Vandan's code. I use Log() and he uses ln(). The original author uses the Natural Log, and funnily enough in AmiBroker both Log() and ln() are the Natural Log.

 

There are many ways to rank stocks based on momentum. The Tactical Asset Allocation whitepapers and books written by Faber, Antonacci, and the models at http://indexswingtrader.blogspot.ca/ use Rate-Of-Change as the simple measure. Michael J. Carr tests numerous methods of measuring momentum in his book "Smarter Investing in Any Economy" , and if anyone has some time to go ahead and code a few of those variations and let us know how they turn out.

https://www.amazon.com/Smarter-Investing-Any-Economy-Definitive/dp/1934354236/ref=sr_1_1?ie=UTF8&qid=1466857358&sr=8-1&keywords=smarter+investing+in+any+economy

 

More rules to follow, but those who've read the book feel free to show us your interpretation of any of the rules that follow or that we've already posted.

__._,_.___

Posted by: "Bruce Wood" <bruce.wood@bigpond.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (16)

Check out the automatic photo album with 1 photo(s) from this topic.
EverySecondWeek.PNG

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/


.

__,_._,___


EmoticonEmoticon