Registered User Joined: 1/28/2005 Posts: 6,049
|
Has anyone attempted to plot the K-RATIO ?
Its described as:
( b1 coefficient estimate)/ ( standard error b1 )*(square root of the number of observations)
If you take an excel spreadsheet and want to do a 20 period K-RATIO.
cells A1=1,A2=2,A3=3 and so on until...... A20=20 The data would be placed in cells B1 thru B20 The K-RATIO would be:
=SLOPE(B1:B20,A1:A20)*SQRT(DEVSQ(A1:A20))/ STEYX(B1:B20,A1:A20)/SQRT(20)
I think a 20 period K-RATIO would be a good starting point.
A few points:
K-RATIO was designed to test equity curves of trading systems which always start at zero. Some type of normalization will be necessary to normalize it over different stock prices.
Multiplying standard error by the square of the number of observation is used to normalize when looking at different length K-RATIOS it may not be necessary for a fixed equation.
If this cant be done as is Im sure some type of ( Linear reg % slope / Linear reg % error ) could at least mimic the K-RATIO.
Making a custom indicator in Telechart by changing the timeframe, I can view a 20 day ratio--20 week--and 20 month and so on. I also have Telechart Mutual Funds which only allows the use of daily bars.
If possible I would like to also see a version where C=C,C1=C5,C2=C10 so that I could calculate a 20 week version in the mutual fund program using daily bars.
Thanks
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
diceman, Please try the following:
(9.5 * C + 8.5 * C1 + 7.5 * C2 + 6.5 * C3 + 5.5 * C4 + 4.5 * C5 + 3.5 * C6 + 2.5 * C7 + 1.5 * C8 + 0.5 * C9 - 0.5 * C10 - 1.5 * C11 - 2.5 * C12 - 3.5 * C13 - 4.5 * C14 - 5.5 * C15 - 6.5 * C16 - 7.5 * C17 - 8.5 * C18 - 9.5 * C19) / 665 * SQR((C - AVGC20) ^ 2 + (C1 - AVGC20) ^ 2 + (C2 - AVGC20) ^ 2 + (C3 - AVGC20) ^ 2 + (C4 - AVGC20) ^ 2 + (C5 - AVGC20) ^ 2 + (C6 - AVGC20) ^ 2 + (C7 - AVGC20) ^ 2 + (C8 - AVGC20) ^ 2 + (C9 - AVGC20) ^ 2 + (C10 - AVGC20) ^ 2 + (C11 - AVGC20) ^ 2 + (C12 - AVGC20) ^ 2 + (C13 - AVGC20) ^ 2 + (C14 - AVGC20) ^ 2 + (C15 - AVGC20) ^ 2 + (C16 - AVGC20) ^ 2 + (C17 - AVGC20) ^ 2 + (C18 - AVGC20) ^ 2 + (C19 - AVGC20) ^ 2) / SQR(((C ^ 2 + C1 ^ 2 + C2 ^ 2 + C3 ^ 2 + C4 ^ 2 + C5 ^ 2 + C6 ^ 2 + C7 ^ 2 + C8 ^ 2 + C9 ^ 2 + C10 ^ 2 + C11 ^ 2 + C12 ^ 2 + C13 ^ 2 + C14 ^ 2 + C15 ^ 2 + C16 ^ 2 + C17 ^ 2 + C18 ^ 2 + C19 ^ 2) / 20 - AVGC20 ^ 2) - 12 * (((0 * C0 + 1 * C1 + 2 * C2 + 3 * C3 + 4 * C4 + 5 * C5 + 6 * C6 + 7 * C7 + 8 * C8 + 9 * C9 + 10 * C10 + 11 * C11 + 12 * C12 + 13 * C13 + 14 * C14 + 15 * C15 + 16 * C16 + 17 * C17 + 18 * C18 + 19 * C19) / 20 - (20 - 1) * AVGC20 / 2) ^ 2) / (20 ^ 2 - 1)) / SQR(20)
The Standard Error portion of the formula seems close, but is not matching the results of STEYX(B1:B20,A1:A20) exactly (the rest seems to match up with the Excel example). I hadn't tried converting it to weekly since I didn't see the formula as being done (and would not have posted an unfinished formula except for your In case I was not clear. topic).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
This looks great Bruce Thank You.
Two points: #1. I would be interested in a 30 bar version of this.
#2. Because of all the averaging this looks like it would be messy to convert this to a weekly format.
EQ#1 100 * (7 * C + 6 * C1 + 5 * C2 + 4 * C3 + 3 * C4 + 2 * C5 + C6 - C8 - 2 * C9 - 3 * C10 - 4 * C11 - 5 * C12 - 6 * C13 - 7 * C14) / 280 / (AVGC15 - 7 * (7 * C + 6 * C1 + 5 * C2 + 4 * C3 + 3 * C4 + 2 * C5 + C6 - C8 - 2 * C9 - 3 * C10 - 4 * C11 - 5 * C12 - 6 * C13 - 7 * C14) / 280)
EQ#2 SQR(((C0 ^ 2 + C1 ^ 2 + C2 ^ 2 + C3 ^ 2 + C4 ^ 2 + C5 ^ 2 + C6 ^ 2 + C7 ^ 2 + C8 ^ 2 + C9 ^ 2 + C10 ^ 2 + C11 ^ 2 + C12 ^ 2 + C13 ^ 2 + C14 ^ 2) / 15 - AVGC15 ^ 2) - 12 * (((0 * C0 + 1 * C1 + 2 * C2 + 3 * C3 + 4 * C4 + 5 * C5 + 6 * C6 + 7 * C7 + 8 * C8 + 9 * C9 + 10 * C10 + 11 * C11 + 12 * C12 + 13 * C13 + 14 * C14) / 15 - (15 - 1) * AVGC15 / 2) ^ 2) / (15 ^ 2 - 1))
The two equations above are from posts. The first is one you gave as a 15 bar LR % slope. The second came from bustermu in a 12-24-2005 post. He called it LR rms error
Both are 15 bar. Because these are smaller and use less averaging it seems like they would offer a cleaner solution for the weekly converson.
My first thought was:
EQ1 * 100 / EQ2 + 1
I realize this wouldnt be the exact K-RATIO but the sorts would be similar
Feel free to recommend if you know of something better.
I would be interested in a 15 WEEK and a 30 WEEK formula from daily bars.
Thank You
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
When I look at my post this may be the correct way to say it :
( EQ1 * 100 ) / ( EQ2 + 1 )
Thanks
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I haven't rewritten it yet, but I think there will only be one additional Moving Average in the original formula versus your simpler alternative. If this is actually the case, would you you still want to use the simpler version for the Weekly formulas?
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
My guess is the simpler version would be OK.
The only way to really know is a side by side test.
Im more interested in the relative values then the actual numbers for the Fund version.
Thanks
|
|
Registered User Joined: 1/1/2005 Posts: 2,645
|
Bruce,
Your PCF looks like:
LRSlope*LRrms/SQR(Period)
whereas, the K-Ratio is more like:
LRSlope/(LRrms*SQR(Period))
Note: LRrms is the rms error of the LR curve fit which is the Standard Error.
Let's clear this up first and delete this post if I am correct.
Thanks. Jim Murphy
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
bustermu, I'm sure your knowledge of how the K-Ratio is calculated is greater than my own since I had not heard of it until this topic was posted. I am relying entirely on, and attempting to match, diceman's spreadsheet formula:
=SLOPE(B1:B20,A1:A20)*SQRT(DEVSQ(A1:A20))/STEYX(B1:B20,A1:A20)/SQRT(20)
SLOPE() = Returns the slope of the linear regression line through the given data points. This result matches with the appropriate portion of the formula.
DEVSQ() = Returns the sum of squares of deviations of data points from their sample mean. This result matches with the appropriate portion of the formula.
STEYX() = Returns the standard error of the predicted y-value for each x in a regression. The Excel results don't match the PCF results, but seem very close.
I should be able to create either version (although it would be nice to know which is correct since I'm working on a spreadsheet to automatically write both the daily and weekly versions of the formulas now).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
The K-RATIO verbal description and the terms used to describe it (b1 coefficient estimate, standard error) are from an article in Technical Analysis of Stocks and Commodities. (March 1996)
The author Lars Kestner also included the spreadsheet example I supplied.
At one point while discussing equity curves he states:
"I have developed a new method of evaluating performance that is more robust than current popular techniques."
This would lead me to believe he is the developer of the K-RATIO.
In his bio--it says:Lars Kestner is founder of Link Financial, a firm specializing in trading system development and applications.
Thanks
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
Bruce
This is a tradestation version of the K-RATIO supplied by Lars Kestner. I realize you may not be expert at their code but, it may supply some insight.
{K-RATIO}
VAR: OBSERVATION(0), COUNT(0), SUMXY(0), SUMX(0), SUMY(0), SUMXSQR(0); VAR: BETAO(0),BEATA1(0),SUMRESIDSQR(0), SIGMAREGRESS(0), STANDARDERRB1(0); VAR: YPROJECTED(0), KRATIO(0); ARRAY: EQUITY[5000](0);
OBSERVATION= OBSERVATION+1; EQUITY[OBSERVATION]= NETPROFIT +OPENPOSITIONPROFIT;
IF DATE=LASTCALCDATE THEN BEGIN FOR COUNT=1 TO OBSERVATION BEGIN SIMXY=SUMXY+(COUNT*EQUITY[COUNT]); SUMX=SUMX+COUNT; SUMY=SUMY+EQUITY[COUNT]; SUMXSQR=SUMXSQR+(COUNT*COUNT); END; BETA1=(SUMXY-(SUMX*SUMY)/OBSERVATION)/(SUMXSQR-(SUMX*SUMX)/OBSERVATION); BETAO=(SUMY/OBSERVATION)-BETA1*(SUMX/OBSERVATION); FOR COUNT= 1 TO OBSERVATION BEGIN YPROJECTED=BETAO+(BETA1*COUNT); SUMRESIDSQR=SUMRESIDSRQ+SQUARE(EQUITY[COUNT]-YPROJECTED); END;
SIGMAREGRESS=SQUAREROOT(SUMRESIDSQR/(OBSERVATION-2));
STANDARDERRB1=SIGMAREGRESS/SQUAREROOT(SUMXSQR);
KRATIO= BETA1/(STANDARDERRB1*SQUAREROOT(OBSERVATION));
PRINT("K-RATIO =",KRATIO:4:2); END;
The code is in the style of "basic".
Thanks
|
|
Registered User Joined: 1/1/2005 Posts: 2,645
|
Bruce,
I misread your PCF and said it was:
LRSlope*LRrms/SQR(Period)
It is actually:
LRSlope*StdDev*SQR(Period)/(LRrms*SQR(Period))
= LRSlope/SQR(1-R^2)
Anyway, you have put SQRT(DEVSQ(B1:B20)) in the numerator where the initial post has SQRT(DEVSQ(A1:A20)). According to your description of DEVSQ(.:.), we should have:
SQRT(DEVSQ(A1:A20)) = SQR((P^2-1)*P/12)
With this change, your PCF should become:
LRSlope*SQR{(P^2-1)*P/12)/(LRrms*SQR( P )) = LRSlope*SQR((P^2-1)/12)/LRrms
After this correction, assuming I have not made an error, the only question is whether
1) STEYX(B1:B20,A1:A20) = LRrms
You have said it is close. Please see if
2) STEYX(B1:B20,A1:A20) = SQR(P/(P-2))*LRrms
or
3) STEYX(B1:B20,A1:A20) = SQR(P/(P-1))*LRrms
works. I have seen 1) and 2) (and others) used for "Standard Error" in Linear Regression.
I believe the second program supplied by diceman produces:
K-Ratio = LRSlope*SQR((P+1)*P*(2*P+1)/6) /(LRrms*SQR(P/(P-2))*SQR( P ))
which, I believe, will will never match the first program.
Note: Sometime in 2000, Kestner changed the SQR( P ) in the denominator to P. Some use LOG( C ) in place of C, which makes more sense to me. I was unaware of K-Ratio until after you.
It is at present a mystery to me why Kestner did not use LOG( C ) in place of C and then define:
K-Ratio = LRSlope/LRrms
Maybe he did?
Thanks, Jim Murphy
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
In the article Kastner states:
" Those familiar with statistics will recognize the K-RATIO as the t-statistic of b1 with correction factor for the number of observations."
Using the values in the spreadsheet:
COL:A COL:B
1 ---- 0.0 2 ---- -.15 3 ---- .72 4 ---- 1.23 5 ---- 2.50 6 ---- 2.33 7 ---- 2.54 8 ---- 3.63 9 ---- 4.91 10 ---- 6.25 11 ---- 6.32 12 ---- 6.6 13 ---- 6.75 14 ---- 7.92 15 ---- 8.3 16 ---- 9.0 17 ---- 9.22 18 ---- 9.36 19 ---- 9.37 20 ---- 10.17
He states:
"Equity = -.75+.58x" "standard error of b1=.022"
K-RATIO = .58/.022*SQRT(20)= 5.90
Hope that makes things more clear.
Thanks
|
|
Registered User Joined: 1/1/2005 Posts: 2,645
|
diceman,
There is little doubt that the K-Ratio is given by:
K-Ratio = Const*LRSlope/LRrms
where Const depends only on the Period of the LR.
We already know what the Const is for the second program you gave. We will know what the Const is for the first program as soon as we know what the Excel function STEYX(B1:B20,A1:A20) calculates. I am quite sure that:
STEYX(B1:B20,A1:A20) = Const2*LRrms
where Const2 depends only on the period of the LR. There is no way for me to know what Const2 is because I do not have Excel. Hopefully, Bruce will give us the formula for Const2.
Anyway, I'll bet my bottom dollar that the two programs give two different results.
Thanks, Jim Murphy
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
bustermu
By second program I assume you mean:
( EQ1 * 100 ) / ( EQ2 + 1 )
(with K-RATIO being the first program)
My theory/guess is that while they may not give the same answer---they will give the same relative answer.
If you sort a watchlist by 100 day % change.
Then sort it by (100 day % change) * 1.2
You wont be sorting by the same values but, the watchlist will be in the same order.
Im just trying to supply Bruce with enough info so he can feel confident he has the proper version of the K-RATIO.
Thanks
|
|
Registered User Joined: 1/1/2005 Posts: 2,645
|
diceman,
By your first program, I meant the Excel program which starts:
cells A1=1,A2=2,A3=3 and so on until...... A20=20 The data would be placed in cells B1 thru B20 The K-RATIO would be: .....
By your second program, I meant the TradeStation program which starts:
VAR: OBSERVATION(0), COUNT(0), SUMXY(0), SUMX(0), SUMY(0), SUMXSQR(0); VAR: BETAO(0),BEATA1(0),SUMRESIDSQR(0), SIGMAREGRESS(0), STANDARDERRB1(0); VAR: YPROJECTED(0), KRATIO(0); ARRAY: EQUITY[5000](0); .....
The corresponding PCFs will give the same sorts which will not be the same sort as by:
(EQ1*100)/(EQ2+1)
It is not a monotonic function of either of the K-Ratios given by the first two programs. But, I will bet:
LRSlope/LRrms
is proportional to each of the K-Ratios of the first two programs and you already have the PCFs needed for it.
We will know when we find out what the function STEYX is.
Thanks, Jim Murphy
|
|
Registered User Joined: 1/1/2005 Posts: 2,645
|
I have now found evidence that:
STEYX = SQR(P/(P-2))*LRrms.
With this, The K-Ratio is of the form:
K-Ratio = Const*LRSlope/LRrms
for each of the two programs supplied by diceman. The Const depends only on the period of the LR and is different for each of the two programs.
The formula:
(EQ1*100)/(EQ2+1)
suggessted by dicenan is not of the above form.
Thanks, Jim Murphy
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
bustermu,
In the equation:
K-Ratio = Const*LRSlope/LRrms
If you change the value of the Const the sort that the equation creates would remain the same?
For example (Const*1) and (Const*.5) would produce the same sort result. Am I correct in making that assumption?
Over a fixed length (lets say 20 bars) what do you believe would be the practical/realworld error between the two equations:
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
Sorry I hit post by accident.
Over a fixed length (lets say 20 bars) what do you believe would be the practical/realworld error between the two equations:
K-Ratio = Const*LRSlope/LRrms
AND
(EQ1*100)/(EQ2+1)
I would think they would produce similar sorts because they are both essentially SLOPE/ERROR.
Is that a proper assumption to make ??
Thanks
|
|
Registered User Joined: 1/1/2005 Posts: 2,645
|
diceman,
The All Stocks WatchList was sorted by:
1) 100*LRSlope/LRrms
2) EQ1/(EQ2+1)
3) EQ1/EQ2
The period was P = 15. The sort ordering was quite different for the three sorts. I do not know the rationale for the +1 in 2). If it is merely to prevent a divide by zero, it is much too large.
The PCFs used were:
PCF1: 100*((7*C+6*C1+5*C2+4*C3+3*C4+2*C5+C6-C8-2*C9 -3*C10-4*C11-5*C12-6*C13-7*C14)/280) /SQR(((C0^2+C1^2+C2^2+C3^2+C4^2+C5^2+C6^2+C7^2+C8^2+C9^2 +C10^2+C11^2+C12^2+C13^2+C14^2)/15-AVGC15^2) -12*(((0*C0+1*C1+2*C2+3*C3+4*C4+5*C5+6*C6+7*C7+8*C8+9*C9 +10*C10+11*C11+12*C12+13*C13+14*C14)/15 -(15-1)*AVGC15/2)^2)/(15^2-1))
PCF2: 100*(7*C+6*C1+5*C2+4*C3+3*C4+2*C5+C6-C8-2*C9 -3*C10-4*C11-5*C12-6*C13-7*C14)/280 /(AVGC15-7*(7*C+6*C1+5*C2+4*C3+3*C4+2*C5+C6-C8-2*C9 -3*C10-4*C11-5*C12-6*C13-7*C14)/280) /(SQR(((C0^2+C1^2+C2^2+C3^2+C4^2+C5^2+C6^2+C7^2+C8^2+C9^2 +C10^2+C11^2+C12^2+C13^2+C14^2)/15-AVGC15^2) -12*(((0*C0+1*C1+2*C2+3*C3+4*C4+5*C5+6*C6+7*C7+8*C8+9*C9 +10*C10+11*C11+12*C12+13*C13+14*C14)/15 -(15-1)*AVGC15/2)^2)/(15^2-1))+1)
PCF3: 100*(7*C+6*C1+5*C2+4*C3+3*C4+2*C5+C6-C8-2*C9 -3*C10-4*C11-5*C12-6*C13-7*C14)/280 /(AVGC15-7*(7*C+6*C1+5*C2+4*C3+3*C4+2*C5+C6-C8-2*C9 -3*C10-4*C11-5*C12-6*C13-7*C14)/280) /(SQR(((C0^2+C1^2+C2^2+C3^2+C4^2+C5^2+C6^2+C7^2+C8^2+C9^2 +C10^2+C11^2+C12^2+C13^2+C14^2)/15-AVGC15^2) -12*(((0*C0+1*C1+2*C2+3*C3+4*C4+5*C5+6*C6+7*C7+8*C8+9*C9 +10*C10+11*C11+12*C12+13*C13+14*C14)/15 -(15-1)*AVGC15/2)^2)/(15^2-1))+0)
Note: Do not extend the PCF forms above to large Periods. They are subject to intolerable computational errors for large P and their forms must be changed. You have seen Bruce avoid such forms with good reason.
If one were interested in K-Ratios I know of no reason to use 2) or 3). As a matter of fact, I know of no reason that Percent Slope is calculated the way it is in TC2005. I believe it is a mistake which will, hopefully, be corrected.
As previously stated, some are of the opinion that LOG( C ) should be used in place of C in the K-Ratio. In addition, the numerator (reward) should probably be something like be the annual percentage rate compounded daily of the LR and the denominator (risk) adjusted accordingly. Bruce has expressed related ideas in other threads. (Thus, you can take it to the bank.)
Thanks, Jim Murphy
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
Thanks bustermu
I will take a look at it.
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
bustermu,
After Looking at the PCFs I have some observations:
PCFs#1 and #3 while having different values, visually they appear almost identical. PCFs #1 and #3 at times suffer from severe overshoot and undershoot.
PCF#2 appears as a smooth (filtered) version of PCFs #1 and #3.
If you look at the following example:
StockA SLOPE( A ) / ERROR( A )<1 StockB SLOPE( A )*.5 / ERROR( A )*.5
To me the "spirit" of the indicator is to find strong slope stocks and "punish" the stocks that have a strong slope with large error. In this example StockB is rewarded by error correcting its slope. I also believe some over the overshoot and undershoot can be cleaned up by limiting the error side of the equation to 1 or >1. The evidence is the relative smoothness of PCF#2.
Most of the error that I can find in the stock list sorts is related to stock prices and the ability for the error side of the equation to drop below 1.
From this information I can draw a few conclusions. ( I would consider them subjective conclusions.)
1. Some type of input conditioning would probably help the PCFs maybe LOG( C ).
2. Its seems desirable to have the error side of the equation not go below one.
3. If +1 is too large a value to add to the error side the some type of adjustment should be made to the equation (error*const+1) or (slope*const) or both.
4. It appears that (EQ1*100) / (EQ2+1) is an acceptable version of this indicator.
Remember the reason this started was to find something smaller and using less averaging to approximate the K-RATIO. So that it could be used in the Mutual Fund program to create a weekly indicator. The fund program only allows the use of daily data.
Thanks
|
|
Registered User Joined: 1/1/2005 Posts: 2,645
|
diceman,
I suggest that EQ1 never be used for anything. It can blow up because of the denominator, or, worse yet, it can be negative when the LRSlope is positive.
If you wish to deviate from the K-Ratio by moderating the denominator with an added 1, I suggest you consider something like:
LRSlope/(LRrms+1)
You might look at the Chande Trend Index in:
Chande Trend Index (CTI)
It is trying to accomplish the same thing as the K-Ratio.
Thanks, Jim Murphy
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
bustermu
Thanks for the advice. I will be curious to see the Chande Trend Index.
Its funny, the reason I was looking into linear regression as an evaluation method is, I thought it was consistent and not open to debate.
I thought LR was a least square line:
Y = a0+a1X and thats it no debate no discussion.
Now it seems there is a lot of debate as to how to measure it, what error really is and, how to put the equations together.
Thanks
|
|
Guest-1 |