Converting Alpha from MetaStock?
Author: wphill
Creation Date: 4/4/2009 6:36 PM
profile picture

wphill

#1
Alpha from Metastock:

( Sum( ROC( CLOSE ,1 ,% ) ,21 ) - ( Fml( "Beta" ) * Sum( ROC( INDICATOR,1,%) ,21 ) ) ) / 21


Beta:( ( 21 * Sum( ROC( CLOSE ,1 ,% ) * ROC( INDICATOR ,1 ,% ) ,21 ) ) -
( Sum( ROC( CLOSE ,1 ,% ) ,21) * Sum( ROC( INDICATOR ,1 ,% ) ,21 ) ) ) /
( (21 * Sum( Pwr( ROC( INDICATOR ,1 ,% ) ,2 ) ,21 )) - Pwr( Sum( ROC( INDICATOR ,1 ,% ) ,21 ) ,2 ))

Note: The above is a 21 day period alpha. I think of this as rate of change adjusted for volatility. I'm doing my best to keep it simple for intermediate trading. Alpha...as conceptualized here...but written elsewhre as proprietary in a canned program ...now discontinued...was quite helpful as one of a few parameters to rank order relative strength.

I'd like to see it loaded as an indicator on a chart and then I'd like to use it to rank order ETFs with CLOSE as CLOSE/BENCHMARK INDEX.

Sure would be great to have both the script for creating a custom indicator and code to generate a matrix table of ETFS X (Alpha 21, Alpha 50, Alpha 90). I'm not a programmer.

I'm a little leary of momentum trading in this environment....when to enter and when to exit are the hardest elements for me...meanwhile, having a tool to rank is an important frame of reference. Later, I'm glad to share the rules of the entire strategy that I'm developing.... meant to quantify a safer way to do momentum intermediate trading. Simple, though....hardly as sophisticated as what I see here. Humbling. FWIW "roc adjusted" showed up in a search....impressive. Glad to get any assistance I can get to use W.Lab's incredible potential and put into action with the discipline that any system needs.
profile picture

ss161

#2
i took a shot at it. i had a few questions, so made some assumptions. I assumed that Indicator in the formula referred to the Benchmark Index. I hard coded that in the main program to be SPY. that of course can be changed.

i wasnt sure what you meant by:
QUOTE:
I'd like to see it loaded as an indicator on a chart and then I'd like to use it to rank order ETFs with CLOSE as CLOSE/BENCHMARK INDEX.


but i did plot alpha and beta on the chart.

also, there is enough complexity (and parentheses) in the formula that you should carefully compare what i coded to the formulas you included above.

here is the program that can be copy and pasted in wealthlab:
CODE:
Please log in to see this code.


and the picture that comes out when it is run:


profile picture

wphill

#3
Steve,

Wow...I've used this alpha parameter for a few years and never saw it charted on a price graph by the package that I was limited to, every tool has its limitations. And, this is neat to "see." Thank You! As you might know...and I'm only going by
the mechanics passed onto me....whenever alpha goes below zero, then the underlying equity is a poor risk...and my assumption
is that negative momentum will continue. The 21 day period did well in spotting this, as well as its recent recovery. (This Alpha on the charts, I assume as I go over my thoughts, is Alpha for IYM, alone....rather than IYM "relative" to SPY.)

In the past, I spent much time using Alpha (relative to a benchmark) as a single ranking parameter in order to predict future superior leadership and comparing it as a parameter to other parameters. Per the program used....and what's under-the-hood is a big assumption....alpha did far better in back testing with data back to 1990 than ROC with a single period, or ROC with multiple periods. The program allowed for optimization of a range of single periods (1-250..and higher) for the period used in Alpha and ROC. If one wanted to use multiple periods in ROC one could designate four periods and designate how they were weighted...but if one decided to use this multiple parameter then it could not be optimized. Anyway, I was left with the impression that Alpha is a powerful way to rank order. Another variation that showed excellent promise...and was more conservative...was Alpha/SD. Momentum investing takes a lot of criticism, but if one stayed disciplined and stayed out when there was no momentum...they escaped a lot of carnage. And, as I mention below...I'm really saying Alpha of an ETF relative to Alpha of a benchmark.

So, my goal is to try to replicate the core of what was helpful in past years and to integrate it with features not available to be before.

The core is having a table that ranks etfs by alpha ( relative to a benchmark). And, when i said
QUOTE:
rank order ETFs with CLOSE as CLOSE/BENCHMARK INDEX
I am beginning to question my own self.
The intent is that alpha as used for every ETF in such a table...or depicted on a price chart would represent "relative strength" to a benchmark...and SPY(.spx) is the benchmark that most folks use.

My dilemma is that I'm not sure how to quantitatively have a benchmark embedded into the formula of Alpha...and, I'm new to reading code with Wealth Lab...my question is does Alpha as charted above...does it represent in the example given...IYM's Alpha (momentum) relative to Alpha of SPY? My sense is that what is coded above is Alpha separately for each IYM and SPY.

Going back to metastock's forumula would "CLOSE" be represented by "IYM/SPY" ??? That is, is price data converted to a ratio of IYM to SPY...or, does this lead to some kind of distortion that prevents comparing apples to apples? I'm thinking that it does. I've gotten accustomed to using a ratio at Stockcharts.com to look at relative strength...and, I think that I had a leap of assumptions in how to measure Alpha relative to a benchamark

For a valid measure a table of ranked ETFs should have Alpha at 0.00% for the benchmark.

A limitation of Alpha measured relative to a benchmark is that theoretically it could have a positive % outcome even though the underlying ETF is in a downtrend. Before choosing an ETF, or whatever, that was top ranked, one must examine a price chart to estimate issues of risk.

I hope that you will hang in there with me.

Thanks,Bill


profile picture

brucev

#4
Hi Bill,

"My dilemma is that I'm not sure how to quantitatively have a benchmark embedded into the formula of Alpha..." and "or depicted on a price chart would represent "relative strength" to a benchmark...and SPY(.spx) is the benchmark that most folks use."

Quantitatively speaking, there is no need to embed the benchmark into the formula. If you are using the same benchmark for every stock/ETF, then dividing everything by the same benchmark will not change the ranking order.

I would help you with this, except I don't have WL5... sorry. I'll put it on my list of things to do in WL4.

Good luck,
Bruce
profile picture

wphill

#5
Bruce,

Here's my perspective and...if I understand you correctly.... I do recognize that if I have a list of etfs and if .spx is the benchmark, then all etfs with alpha's above .spx's alpha.... then those etfs are considered to be superior...but....Relative strength can reveal leadership or a slowing momentum not otherwise seen. For example, GLD broke out earlier last year. And, if looking at absolute prices on a chart, one would think that it's too volatile. However, if looking at gld relative to .spx the volatitlity is not there...at least, that's what I saw from August of 2008.
http://stockcharts.com/h-sc/ui?s=GLD:$SPX&p=W&yr=3&mn=0&dy=0&id=p77136387688
This means that gld was reliably contrarian even if gld by itself was not yet on a solid uptrend...and certainly worth watching for an entry.
I would say the same thing about regional banks if looking at it relative to a more narrow benchmark....bkx....
http://stockcharts.com/h-sc/ui?s=KRE:$bkx&p=W&yr=3&mn=0&dy=0&id=p77136387688
which shows the merit of not only having one large group relative to .spx but also smaller groups relative to its total sector/domain benchmark.

To get this into the formula....is it as simple (sort of) as coding it as Alpha(each etf) divided by Alpha(benchmark)?

...Bill
profile picture

ss161

#6
Hi Bill, i've been doing a little more work on this, but have been running into a bunch of issues with some of the numerical calculations -- either my code has issues (always does to a degree) or there are some weird rounding / truncation issues that are happening, as this link suggests http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance.

a few comments:

QUOTE:
My dilemma is that I'm not sure how to quantitatively have a benchmark embedded into the formula of Alpha...and, I'm new to reading code with Wealth Lab...my question is does Alpha as charted above...does it represent in the example given...IYM's Alpha (momentum) relative to Alpha of SPY? My sense is that what is coded above is Alpha separately for each IYM and SPY.

alpha and beta as defined by the market (and I believe as expressed in the formulas you provided), reflect the degree to which an asset moves with the benchmark (beta) and the degree to which it has out/under performed the benchmark (alpha). the formula for calculating beta, which i think the formula you provided reduces to, is Beta = Covariance(Symbol, Benchmark) / Variance(Benchmark). it is a relative measure of how much an asset moves with the benchmark security.
Alpha = Return(Symbol) - Beta * Return(Market), that is, Alpha already reflects the outperformance of the security to the market. Finally, given that formula, Alpha(Benchmark) always will equal 0.

QUOTE:
A limitation of Alpha measured relative to a benchmark is that theoretically it could have a positive % outcome even though the underlying ETF is in a downtrend. Before choosing an ETF, or whatever, that was top ranked, one must examine a price chart to estimate issues of risk.

if we find some expected alpha, i have no problem buying the alpha security and shorting the benchmark, that's what i do. the tricky part of course is finding the reliable signal or alpha.

if / as i work out some of the numerical issues, i'll post some more.
profile picture

brucev

#7
Hi Bill,

I am suggesting you use the alpha measure as your ranking (ordering) mechanism. If you do that, it doesn't matter whether you include the benchmark into your formula or not. Imagine 50 securities are ranked according to alpha order. Then dividing each ones alpha value by the benchmark, and re-ordering them will have no effect. The alpha value will be very different, but the order will be the same.

Sorry if I have misunderstood your intentions... if you are plannning to use a different benchmark for each security, then you should proceed as you are... Finally, it should be clear that although the beta has its uses, this isn't one of them. If the alpha is deterministic and persistent enough for trading, and uniques to your selection, then the beta will only serve to confuse the issue (although pure financial theorists would endlessly debate this). From what I can tell of your intentions in your first few posts, it is unclear what you would actually do with the beta... perhaps you could explain that further?

Cheers,
Bruce
profile picture

wphill

#8


Bruce,

QUOTE:
I am suggesting you use the alpha measure as your ranking (ordering) mechanism


Perhaps, I'm asking too much from WLP. I don't know. But, I do think that alpha relative to a benchmark is what many of the professional investors do. At the same time, you've given me something to think about....what is the added value as long as the index is within the list of etfs being rank ordered? When I think of an etf charted relative to a benchmark in the form of a ratio as in the examples I gave above at stockcharts.com, I think there is quite a bit value added. My dilemma is that I'm not sure that when calculating "Alpha" as it is used in the metastock forumla to rank order that there is the same value added that I see in the ratio when it is used to chart. The use of these comparisons are apples and oranges. I think so, anyway.

I went back to text material in the prior software package that crunched the numbers of Alpha so that it could rank order etfs relative to a designated benchmark.

This is the description provided:

The Alpha statistic is used to measure the risk adjusted return of a fund relative to the Benchmark. Alpha is calculated by
using a “least-squares regression” of the fund’s return against that of a Benchmark. For example, let us assume that the
return of the S&P 500 is 12% and the fund’s Beta equals 1. Beta would predict the return of this fund to also equal 12%. An
alpha of +2.0 indicates the fund has performed 2% better than its Beta would predict. Thus, its return would be 14%. In
contrast, an Alpha of

-2.0 indicates the fund has performed 2% below its expected return, or a return of 10%. An Alpha of 0 indicates performance
in line with its Beta, a 12% return.


In a table of ranked etfs relative to a benchmark, there is an orderly sense of seeing the benchmark with a value of 0% and all etfs ABOVE the benchmark having a positive benchmark. More important is that I use my posting here to better understand what I used for a number of years that worked well to predict leadership among a group.

QUOTE:
From what I can tell of your intentions in your first few posts, it is unclear what you would actually do with the beta... perhaps you could explain that further?


Well sticking to the metastock text, this is what they describe as beta:

Beta is a measure of volatility of one security against another. This is typically used to measure the volatility of a stock against an index like the S&P 500. A value greater than one indicates the stock is more volatile than the index.

My best shot is that Beta helps to adjust absolute roc for volatility.

Now to really go out on a ledge and to make a fool of myself, when it comes to using the metastock formula,
I venture to say that when calculating Alpha or Beta the "indicator" would be the benchmark price data and the "Close" is the etf price data.

Thanks...I hope that I'm making some sense. Getting the right method for rank ordering is the cornerstone for what I want to do, and to ultimately keep it simple.

Bill





profile picture

wphill

#9
Steve,
Great to see you back!!!

When you write:
QUOTE:
alpha and beta as defined by the market (and I believe as expressed in the formulas you provided), reflect the degree to which an asset moves with the benchmark (beta) and the degree to which it has out/under performed the benchmark (alpha). the formula for calculating beta, which i think the formula you provided reduces to, is Beta = Covariance(Symbol, Benchmark) / Variance(Benchmark). it is a relative measure of how much an asset moves with the benchmark security.
Alpha = Return(Symbol) - Beta * Return(Market), that is, Alpha already reflects the outperformance of the security to the market. Finally, given that formula, Alpha(Benchmark) always will equal 0.


This sounds and looks exactly what I'm trying to say!

I'm confused, though, about why whether or not metastock's formula suffices to give a relative alpha and that as you say if it was done for the benchmark alone, alpha would come out as zero percent....or is it alpha of a single asset over the alpha of the benchmark that yields the alpha percentage data?

QUOTE:
the tricky part of course is finding the reliable signal or alpha.

If I undertand you right, then I would say that you are referring to the alpha period? I've done a lot of back testing with optimization that focuses directly on alpha period,
and it's surprising that there can be quite a range...short, medium, and longer time periods....a range between 21 and 145.

As for when to actually make an entry I've grown fond of Pring's KST's. Safest "looks like" when weekly and daily kst's have signals that are in a agreement and not over extended. That's another discussion. For now, it looks like some work to get a rank ordering against a benchmark.

I hope you guys hang in there. I sure do need the help. Kind of lonesome as a non programmer, and a little short on mathematical skills, not to mention the details of a concept. Forced to explain one self can reveal need for clarity.

Thanks again, Bill
profile picture

Roland

#10
Bill,

What you want to do is relatively simple.

As, Bruce and others have mentioned, a benchmark has zero alpha, meaning that it
can not over/under perform itself. However, when you compare relative performance
of a stock to a benchmark, alpha can express the over/under performance. And there,
it is sufficient to subtract both rate of change over your specified period to have
your alpha measure relative to your specific benchmark (hopefully related to the
stocks under consideration). And then the ordering by alpha for the group of stocks
can be a snap.

See my paper for a more elaborate view.

Happy trading.

profile picture

wphill

#11
Roland,
I like relatively simple.

I do think I grasp the concept as you have described it.
My anx is having a coded strategy that I can generate a report with
a spread sheet style look and then move on to working on a buy-sell mechanical strategy, back testing, optimizing etc.

What do you think of metastock's formula for Alpha?

Do you agree that their use of the element "Indicator"
is the selected benchmark?

Fwiw...I'm only going to consider etfs. There will be one large group, as well as more focused groups like
Financial, Materials, Western developed countries, Regional, etc ....some groups are more narrow than others.
The benchmark for the largest group will be .spx. More focused groups could have .spx....

or, do you have an opinion
that a more narrow group should have an index that represents this group more directly...e.g. Financials would have .bkx?

In the past years, when using a packaged software I kept it more simple by only using one large/total group, one domestic group, and one international group...all with .spx as the benchmark.
profile picture

Roland

#12

Bill,

In trying to determine relative alphas, I prefer to use the slope of the regression line over the period of interest. It tends to be less volatile than the rate of change. You can extract “alpha“ by simply comparing the slopes of two or more price series to whatever you might consider as a base of reference or benchmark. Compare a financial stock to a financial index or any other financial stock. Comparing a bank to a solar company to extract an alpha measure can also have its merits. But there again, I prefer to compare the rate of change of the slope of the regression line.

Numerous papers and studies have been done on alpha ranking as a way to improve portfolio performance, but if I recall, none that I have seen showed outstanding “alphas”: they where more in the order of 3 to 5% over the benchmark when they could show some. And then again, it was not that sure if the added alpha was due to the alpha ranking itself or the selection methodology used. However, most of these studies did show some form of alpha persistency.

The alpha ranking is not a predictive method, it only shows what is - in the sense that you can order all stocks at anytime by performance. And without position sizing methods, one’s portfolio performance might be limited by the efficient frontier.

Consider comparing your indexes to a benchmark index like the Wilshire 5000 and sort them by alpha. This should give you the outperforming groups. Then compare your ETFs to their respective indexes. This should give you which ETFs are outperforming their sector which is outperforming the benchmark. Then select from the best performing ETFs those with a rising rate of change of their regression line. Note that all this will only give you what is; however, due to some alpha persistency this procedure will tend to outperform the benchmark.

profile picture

wphill

#13
QUOTE:
I prefer to compare the rate of change of the slope of the regression line.


Roland,

That's quite interesting.....and a huge hint of another way that might be a better bet.
Indeed, there are a lot of variables to choose from to see which offers the best predictive method.


Ahhh..how good it would be to have a table that ranks orders a universe of etfs in two columns of
relative alphas, one derived from roc of price and a second alpha derived from roc of slope of the regression line.
Then back test and see if there is a trend of higher performance within similar rules of asset rotation.

Re...studies of rank ordering....you guys are the pros....but I have read a few...Mebane Faber has done some
interesting recent studies on tactical asset allocation...which is basically what I am doing...and his
study goes back at least as far back as the early 1900's. Rules for rotation, though, may be limited to a cross over of the
the 200dma. This then does not strike me as rotation based on relative strength...would it not be better to rotate when
leadership relative to the group fails rather than only a measure of the asset, itself?

One consistent finding that I have found, is that it is better to rotate into only one asset class, and not try to distribute risk with multiple assets of the same group with the same timing strategy....such as being invested in the top three assets...substituting them whenever there is a cut off violation of their rank order. ..or when there is violation of a trailing loss. Counter intuitive to choose only one asset to be invested in, but there appears to be less trading, less draw down of the the account, and more profit if only being invested in one assset at at time.

My thought is to look for diversification through separate strategies derived across multiple periods of roc, as well as different selection criteria. For example, use a range period of 90 to 150 to optimize with a given alpha and selection/rotation strategy, and then repeat with other ranges. And, do the same, by optimizing on selection criteria that is more value oriented....assets closer to the bottom of the list.

Then again, it's you guys that have the ability to write code, manipulate variables, and have a methodology in real time.

Trying to keep it simple, Bill


profile picture

wphill

#14
Roland,
QUOTE:
slope of the regression line over the period of interest.

Quite curious, I went to charts in WLP and dropped in the indicator---slope of the regression line....
and that dropped onto it/not the price... a ROC. Is this what you meant?
What period would you suggest for each?

I think that I can resonate with your view that slope of a regression line....points the way....more than roc which is, as
you say tells you what is....makes some sense in the abstract if I'm following you...but,
the slope for a higher price etf may be much greater than the slope for a small price etf, even though the roc of change is the same for the same period of interest. Yes???

This is getting a little slippery without a firm handle on knowing what "relative Alpha" says and what it doesn't,
and without comparative findings with other ranking parameters.


thx/wphill
profile picture

wphill

#15
QUESTION........PLEASe WEIGH IN.....

Is it correct to say that if i ranked ordered a universe of etfs and its benchmark using the parameter "Alpha" ,
the order would be exactly the same
when compared to rank ordering on the parameter of a "relative Alpha" (same period of interest) with the only difference being that the benchmark would have zero percent and all etf's would be in parentage terms relative to the benchmark?
Can I be confident on this distinction, or do I need to re digest it all?
If this is correct, I'm not sure what is gained by using a "relative Alpha" as long as the benchmark is included in the list.

Sorry guys....I do feel out of my league but hope some may find this discussion worthwhile.

For what it's worth, just by looking at comparative performance charts, and by selecting the higher performing etfs on varied roc periods,
and then fine tuning by examining ratio charts (etf divided by benchmark(.rua))
...in early March....I screened out what are looking like outperformers: narrow focused:EWY and KRE; broad focused: EPP,ILF,IWP. The harderest part was pulling the trigger the second week into the rally. The next hardest part will be sticking to sell criteria.
Ergo, I want a weekly coded program that keeps it "simple" between the ears.
profile picture

ss161

#16
Eight Ways to Calculate Beta (and Alpha)

After posting the initial code above I tried to get a better understanding of what was behind the calculation of Beta. The two methods I know to calculate beta are: 1) Beta = Cov( Rs, Rm) / Var(Rm) (where Rs = Return of Security s, Rm = Return of Market m), and 2) Beta (and Alpha) automatically fall out of the following regression: Rs = Alpha + Beta * Rm + error. When I compared both of these methods to the code above, the results did not match at all. After fixing the order of how I called the regression routine, the cov/var and regression methods matched exactly, but the MetaStock formula's did not match at all. Finally, I coded another version of the MetaStock formula exactly as before except with the Symbol and the Index parameter reversed everywhere in the formula. The results while not exactly the same as the cov/var and regession methods are a lot closer.

Note: the regression routine is adapted from Dr. Koch's LinRegFit wl4 function to operate on an entire dataseries given an input lookback period over which to calculate the regression.

On the image below, see on the 2nd ChartPane from the bottom, the 4 different methods of calculating Beta plotted. The blue (appears purlish) and red histogram bars are the cov/var and regression methods. They are identical. The Yellow line is the initial metastock formula. The brown line is the MetaStock formula with the symbol and the index reversed throughout the formula. These are the first four ways.

The second four ways are identical to the first four except that instead of calculating Beta using a 1 day ROC (or return), I calculate it using Log Returns. Log Returns are virtually identical to Returns for most price movements, but are supposed to be provide more statistically valid results (I believe studies of distributions of stock returns are found Not to be normally distributed, but instead closer to log normally distributed, since a stock's price is truncated at 0). Anyway, the bottom pane repeats the above four calculations but on the log returns of the symbols, not the 1 day ROC's You can see, the results are almost identical.

My own conclusion, I will use regressions on log price returns to calculate alpha and beta -- it provides identical results to the cov/var method and also provides some additional variables to test whether our results are significantly different from 0 (t-tests of alpha and beta, and standard errors of alpha and beta, and chi2 stat).




Here is the code calculate Alpha and Beta (8 different ways) along with some fairly useful classes / functions.

CODE:
Please log in to see this code.
profile picture

ss161

#17
Ranking Alpha

Here's a first version of a Script that will do two things:
in SingleSymbolBacktest mode (clicking on a symbol), it calculates Alpha and Beta and graphs the results.
in MultiSymbolBacktest mode (clicking on the entire DataSet), it loops through each name, calculates alpha and beta, stores the last calculated Alpha / Beta into a list, sorts the list, and prints the "ranked" alpha list onto the Debug window so it can be copied and pasted into excel.

Here is the output in SSB:


Here is the output in MSB:


Here is the code:
CODE:
Please log in to see this code.



profile picture

wphill

#18
Steve,
Wow!!!!!!!!!!!!!!!!!!!!
What a gift.
A lot to digest and to interact with.

My first impressions:

Slope of linear regression was the underlying parameter of choice for Alpha per Roland's suggestion.

Today I did a look back with simple performance charts on some broad based etfs...If one goes back 21 days, pure roc is dominated by IWN...or small cap value....a financially loaded sector. In contrast the top ranked alpha etf was small cap (close enough) but I was surprised to see PPH/pharm hlders ranked third but with a finding similar to the first ranked small cap....perhaps some digits were hidden.

My very low tech look on the world of etfs:(I sub'd PPH in for GLD)
http://stockcharts.com/charts/performance/perf.html?VUG,VTV,IWN,IWO,EPP,IEV,EWJ,EEM,IGE,pph

Conceptually, does this mean that the alpha of the slope is adjusted for volatility/beta? Is beta incorporated into the alpha?

Given this rank ordering, from the standpoint of short term predictive bias, it may better to place one's bed on broad core sectors rather than narrow sectors, and growth rather than value.

Curious, does this kind of tactical allocation style of investing interest you?... thank YOU for whatever the reason.
Thanks again, Bill
profile picture

ss161

#19
part of the list was truncated. here's the full list of the etf's i look at. yes, i'm very interested in this and hopefully will incorporate some findings into my current systems (all focused on ETFs right now).


CODE:
Please log in to see this code.

profile picture

wphill

#20
Steve,

Are you short term trading or intermediate trading?

Personally, I'm intermediate..., though if need be re allocate short term.I have a universe of about 132 etfs divided by narrow and broad groupings, all trade over 100k shares daily, i'm wanting to put together a system that both mirrors a prior trading package that went defunct...and add to it more risk managing mechanical signals on both the buy and sell sides. To do this I like Martin Pring's KST's which can be optimized.


I don't want to follow anything blindly.....and I find myself asking many questions more of a newbie

Any chance that we could work off this board, or... stay here...I just have so many questions...?

Thanks,Bill
profile picture

ss161

#21