Traders' Consortium: explorer coding to find out r-squared period - Traders' Consortium

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

explorer coding to find out r-squared period please help

#1 User is offline   singashari Icon

  • New Contributor
  • Pip
  • Group: Member
  • Posts: 15
  • Joined: 28-January 10
  • Real Name:ade

Posted 28 January 2010 - 05:52 PM

Dear friend,
I tried to understand r-squared indicator which it can measure strenghtness of stock movement. The r-squared with correlate with confidence level, we can see on metastock help. I like to know how to explore period of security which is weak (r-squared=0.0001) or strong (r-squared=0.80).
Please help me.

Regards,
Ade
0

#2 User is offline   JohnathanStein Icon

  • Lively Contributor
  • PipPipPipPip
  • Group: Premium Member
  • Posts: 177
  • Joined: 25-April 07
  • Real Name:Johnathan Stein

Posted 28 January 2010 - 06:04 PM

Ade -- You'll need to know basic Statistics and Correlation before using this; there is some background at http://en.wikipedia.org/wiki/R_squared. The same function exists in Excel (and, I assume, in Open Office) if you really want to "dig in" and understand it.

Good luck,


--Johnathan
0

#3 User is offline   singashari Icon

  • New Contributor
  • Pip
  • Group: Member
  • Posts: 15
  • Joined: 28-January 10
  • Real Name:ade

Posted 29 January 2010 - 12:09 PM

View PostJohnathanStein, on 29 January 2010 - 07:04 AM, said:

Ade -- You'll need to know basic Statistics and Correlation before using this; there is some background at http://en.wikipedia.org/wiki/R_squared. The same function exists in Excel (and, I assume, in Open Office) if you really want to "dig in" and understand it.

Good luck,


--Johnathan


Johnathan,
Do you mean we cannot use R-squared as one of trading tools? Please kindly explain to me.

Thank you

Ade
0

#4 User is offline   Siligard Icon

  • Lively Contributor
  • PipPipPipPip
  • Group: Member
  • Posts: 172
  • Joined: 23-July 07
  • Real Name:Giorgos E. Siligardos

Posted 29 January 2010 - 05:56 PM

Ade,
in the most general case the r-squared (r^2) measures how well a model fits to reality. r^2=0 means no fitness at all and r^2=1 means perfect fitness.
Metastock help is a bit misleading when it comes to r^2 so I 'll try to explain it in simple terms. The r^2 of Metastock measures how well the closing price movement in a chart (the reality) resembles a straight line (the model). If you calculate the r^2 of say the last 20 bars of a stock in Metastock and you find that r^2 is 1 then this just means that the last 20 closing prices are moving in a perfect straight line (more precisely, they are moving in a perfect oblique line, not horizontal) and nothing more. As such, the r^2 does not offer an indication of trend strength in and of itself since the slope of the oblique line could be very small in absolute value.

Giorgos
0

#5 User is offline   singashari Icon

  • New Contributor
  • Pip
  • Group: Member
  • Posts: 15
  • Joined: 28-January 10
  • Real Name:ade

Posted 30 January 2010 - 12:12 PM

View PostSiligard, on 30 January 2010 - 06:56 AM, said:

Ade,
in the most general case the r-squared (r^2) measures how well a model fits to reality. r^2=0 means no fitness at all and r^2=1 means perfect fitness.
Metastock help is a bit misleading when it comes to r^2 so I 'll try to explain it in simple terms. The r^2 of Metastock measures how well the closing price movement in a chart (the reality) resembles a straight line (the model). If you calculate the r^2 of say the last 20 bars of a stock in Metastock and you find that r^2 is 1 then this just means that the last 20 closing prices are moving in a perfect straight line (more precisely, they are moving in a perfect oblique line, not horizontal) and nothing more. As such, the r^2 does not offer an indication of trend strength in and of itself since the slope of the oblique line could be very small in absolute value.

Giorgos


Dear Giorgos,
Its very simple & clear explanation, thank you.
From your explanation, can i say in different way that if r^2<1 meanings the straight line trend strength is just weakening (or model starts to change the direction) and r^2=1 means the model is not random. Is it correct?

Regards,
Ade
0

#6 User is offline   JohnathanStein Icon

  • Lively Contributor
  • PipPipPipPip
  • Group: Premium Member
  • Posts: 177
  • Joined: 25-April 07
  • Real Name:Johnathan Stein

Posted 30 January 2010 - 01:00 PM

Quote

From your explanation, can i say in different way that if r^2<1 meanings the straight line trend strength is just weakening (or model starts to change the direction) and r^2=1 means the model is not random. Is it correct?

Ade,

An R^2 can be roughly thought of as a % explanatory; also, any significant "R", will also denote whether the relationship is directly or inversely proportional, depending on whether it is positive or negative. In multiple regression forecasting, there will be multiple R's and R^2's. The "R" is used in forecast calculation.

In this case, Metastock is using TIME as the independent variable.

You will never see a real-world R^2 of 1. Also, keep in mind that both R and R^2 are NOT measures of a single data point.


--Johnathan
0

#7 User is offline   Siligard Icon

  • Lively Contributor
  • PipPipPipPip
  • Group: Member
  • Posts: 172
  • Joined: 23-July 07
  • Real Name:Giorgos E. Siligardos

Posted 31 January 2010 - 02:19 AM

View Postsingashari, on 30 January 2010 - 12:12 PM, said:

Dear Giorgos, Its very simple & clear explanation, thank you. From your explanation, can i say in different way that if r^2<1 meanings the straight line trend strength is just weakening (or model starts to change the direction) and r^2=1 means the model is not random. Is it correct? Regards, Ade

When r^2<1 it means that the closing prices do not move in a straight oblique line and as Johnathan said an r^2 equal to 1 is seldom in the real world. An r^2 equal to 1 yes it would mean that the price moves in a perfect straight oblique line and as such it does not have any random components. Theoretically however, you may have a low r^2 accompanied by a progressively stronger directional movement just because the movement does not follow a straight line.
Giorgos
0

#8 User is offline   singashari Icon

  • New Contributor
  • Pip
  • Group: Member
  • Posts: 15
  • Joined: 28-January 10
  • Real Name:ade

Posted 31 January 2010 - 12:19 PM

View PostSiligard, on 31 January 2010 - 03:19 PM, said:

When r^2<1 it means that the closing prices do not move in a straight oblique line and as Johnathan said an r^2 equal to 1 is seldom in the real world. An r^2 equal to 1 yes it would mean that the price moves in a perfect straight oblique line and as such it does not have any random components. Theoretically however, you may have a low r^2 accompanied by a progressively stronger directional movement just because the movement does not follow a straight line.
Giorgos


Giorgos,
I got the point now. I like to know whether you have coding to find out period of any indicator?

Thank you.

Regards,
Ade
0

#9 User is offline   Siligard Icon

  • Lively Contributor
  • PipPipPipPip
  • Group: Member
  • Posts: 172
  • Joined: 23-July 07
  • Real Name:Giorgos E. Siligardos

Posted 01 February 2010 - 05:28 AM

View Postsingashari, on 31 January 2010 - 12:19 PM, said:

I like to know whether you have coding to find out period of any indicator?

Ade, I don't understand what you mean by "have coding to find out period"
Giorgos
0

#10 User is offline   singashari Icon

  • New Contributor
  • Pip
  • Group: Member
  • Posts: 15
  • Joined: 28-January 10
  • Real Name:ade

Posted 02 February 2010 - 03:14 PM

View PostSiligard, on 01 February 2010 - 06:28 PM, said:

Ade, I don't understand what you mean by "have coding to find out period"
Giorgos


Giorgos,
What i mean is suppose i like to find period of securities which r^2>=0.8, do you have this kind of coding?

Regards,
Ade
0

#11 User is offline   Siligard Icon

  • Lively Contributor
  • PipPipPipPip
  • Group: Member
  • Posts: 172
  • Joined: 23-July 07
  • Real Name:Giorgos E. Siligardos

Posted 02 February 2010 - 05:25 PM

View Postsingashari, on 02 February 2010 - 03:14 PM, said:

What i mean is suppose i like to find period of securities which r^2>=0.8, do you have this kind of coding?

still haven't understood what you want Ade...
Do you want to find how many bars have passed since r^2>=8 for every stock?
Do you want to find how many bars back to take into account in the calculation of r^2 so that r^2>=8 if possible for every stock?
What do you mean by "period of securities"?
Perhaps somebody else can help...
Giorgos
0

#12 User is offline   JohnathanStein Icon

  • Lively Contributor
  • PipPipPipPip
  • Group: Premium Member
  • Posts: 177
  • Joined: 25-April 07
  • Real Name:Johnathan Stein

Posted 02 February 2010 - 05:57 PM

Ade -- Why don't you try plotting a few indicators, until you know more precisely what it is you need help with?


--Johnathan
0

#13 User is offline   singashari Icon

  • New Contributor
  • Pip
  • Group: Member
  • Posts: 15
  • Joined: 28-January 10
  • Real Name:ade

Posted 03 February 2010 - 01:29 PM

View PostSiligard, on 03 February 2010 - 06:25 AM, said:

still haven't understood what you want Ade...
Do you want to find how many bars have passed since r^2>=8 for every stock?
Do you want to find how many bars back to take into account in the calculation of r^2 so that r^2>=8 if possible for every stock?
What do you mean by "period of securities"?
Perhaps somebody else can help...
Giorgos


Giorgos,
This is what i read from Metastock help.


r-squared values show the percentage of movement that can be explained by linear regression. For example, if the r-squared value over 20 days is at 70%, this means that 70% of the movement of the security is explained by linear regression. The other 30% is unexplained random noise.

One of the most useful way to use r-squared is as a confirming indicator. Momentum based indicators (e.g., Stochastics, RSI, CCI, etc.) and moving average systems require a confirmation of trend in order to be consistently effective. R-squared provides a means of quantifying the "trendiness" of prices. If r-squared is above its critical value and heading up, you can be 95% confident that a strong trend is present.

When using momentum based indicators, only trade overbought/oversold levels if you have determined that prices are trendless or weakening (i.e., a low or lowering r-squared value). Because in a strong trending market, prices can remain overbought or oversold for extended periods. Therefore, you may want to reconsider trading on strict overbought/oversold levels used by many indicators. An "overbought" market can remain overbought for extended periods in a trending market. However, a signal generated by a moving average crossover system may be worth following, since these systems work best in strong trending markets.

To determine if the trend is statistically significant for a given x-period linear regression line, plot the r-squared indicator and refer to the following table. This table shows the values of r-squared required for a 95% confidence level at various time periods. If the r-squared value is less than the critical values shown, you should assume that prices show no statistically significant trend.


Based on e.g. r^2(20) = 70%, what I mean about the coding I like to know coding to find period of r^2 which equal to 70% and as e.g is 20 days.
The idea is I like to see correlation r^2 with momentum indicators & moving average to make profit. I believe Metastock team build the indicator based on some experiences, so they can explained on Metastock Help.

Thank you

Regards,
Ade
experience
Regards,
0

#14 User is offline   singashari Icon

  • New Contributor
  • Pip
  • Group: Member
  • Posts: 15
  • Joined: 28-January 10
  • Real Name:ade

Posted 03 February 2010 - 01:36 PM

View PostJohnathanStein, on 03 February 2010 - 06:57 AM, said:

Ade -- Why don't you try plotting a few indicators, until you know more precisely what it is you need help with?


--Johnathan


Johnathan,
Why I interested with this indicator, because some indicators is worked un-consistently ( I didn't check all indicators yet). So, I found something interesting on Metastock Help, which is r^2. The idea is I like to confirm my indicator so the indicator performance will improved.
Thank you.

Regards,
Ade
0

#15 User is offline   JohnathanStein Icon

  • Lively Contributor
  • PipPipPipPip
  • Group: Premium Member
  • Posts: 177
  • Joined: 25-April 07
  • Real Name:Johnathan Stein

Posted 03 February 2010 - 01:45 PM

Ade,

If you let us know what you're using, and how, we might be of greater help. Perhaps also upload a screen capture.


--Johnathan
0

#16 User is offline   JohnathanStein Icon

  • Lively Contributor
  • PipPipPipPip
  • Group: Premium Member
  • Posts: 177
  • Joined: 25-April 07
  • Real Name:Johnathan Stein

Posted 03 February 2010 - 02:57 PM

Ade -- Looks like you might need a leg up, so here's an indicator and a screen-shot to play with.

Indicator Name: _R2
Period:=Input("Period",1,120,20);
MinSlope:=Input("Minimum Slope",.01,.5,.05);
CriticalValue:=If(Period>=120,.03,If(Period>=60,.06,If(Period>=50,.08,If(Period>=30,.13,If(Period>=25,.16,If(Period>=20,.20,If(Period>=14,.27,If(Period>=10,.40,If(Period>=5,.77,0)))))))));
Trend:=If(RSquared(C,Period)>CriticalValue,1,0);
Direction:=If(LinRegSlope(C,Period)>=MinSlope,1,If(LinRegSlope(C,Period)<=-MinSlope,-1,0));
If(Trend>0 AND Direction>0,1,If(Trend>0 AND Direction<0,-1,0));


Attached File  R2.png (29.48K)
Number of downloads: 17
--Johnathan
0

#17 User is offline   singashari Icon

  • New Contributor
  • Pip
  • Group: Member
  • Posts: 15
  • Joined: 28-January 10
  • Real Name:ade

Posted 04 February 2010 - 01:18 PM

View PostJohnathanStein, on 04 February 2010 - 03:57 AM, said:

Ade -- Looks like you might need a leg up, so here's an indicator and a screen-shot to play with.

Indicator Name: _R2
Period:=Input("Period",1,120,20);
MinSlope:=Input("Minimum Slope",.01,.5,.05);
CriticalValue:=If(Period>=120,.03,If(Period>=60,.06,If(Period>=50,.08,If(Period>=30,.13,If(Period>=25,.16,If(Period>=20,.20,If(Period>=14,.27,If(Period>=10,.40,If(Period>=5,.77,0)))))))));
Trend:=If(RSquared(C,Period)>CriticalValue,1,0);
Direction:=If(LinRegSlope(C,Period)>=MinSlope,1,If(LinRegSlope(C,Period)<=-MinSlope,-1,0));
If(Trend>0 AND Direction>0,1,If(Trend>0 AND Direction<0,-1,0));


Attachment R2.png
--Johnathan


Johnathan,
Thank you for your coding. Actually I don't apply the method yet & I just start it.
I am wondering, is there possible we modified the coding by iteration. For example, if R^2(C,period)<0.8 then period=period+1 continue until we get R^2 >=0.8. Is it possible?

Regards,
Ade
0

#18 User is offline   JohnathanStein Icon

  • Lively Contributor
  • PipPipPipPip
  • Group: Premium Member
  • Posts: 177
  • Joined: 25-April 07
  • Real Name:Johnathan Stein

Posted 04 February 2010 - 02:32 PM

View Postsingashari, on 04 February 2010 - 02:18 PM, said:

Thank you for your coding. Actually I don't apply the method yet & I just start it.

Ade -- You really, really, really need to use it and learn more about how Metastock works.

Specifically, how to plot indicators on a chart, so you can see what they do, and how to use indicators in an Exploration.

It will also be helpful to you to create/attach an Expert, and to modify Indicators used in Experts.

I worked up the code to give you a "leg up" on these things, but there is no shortcut anyone can give you in learning to do them; it just takes time & experience. You have to know/learn the basics of Metastock's features.

View Postsingashari, on 04 February 2010 - 02:18 PM, said:

I am wondering, is there possible we modified the coding by iteration. For example, if R^2(C,period)<0.8 then period=period+1 continue until we get R^2 >=0.8. Is it possible?

I don't think you quite understand how to use indicators, as your question does not make sense.



--Johnathan
0

#19 User is offline   Siligard Icon

  • Lively Contributor
  • PipPipPipPip
  • Group: Member
  • Posts: 172
  • Joined: 23-July 07
  • Real Name:Giorgos E. Siligardos

Posted 05 February 2010 - 04:03 PM

View Postsingashari, on 04 February 2010 - 01:18 PM, said:

I am wondering, is there possible we modified the coding by iteration. For example, if R^2(C,period)<0.8 then period=period+1 continue until we get R^2 >=0.8. Is it possible? Regards, Ade

Ade, now I think I got what you want.

In Metastock help there is a table which contains 9 periods for r^2 along with their corresponding critical values. If you want to find which period gives an r^2 greater than its critical value you don't need to use iteration (loop). Just calculate the r^2 for these nine periods and check which one is greater than its critical value.

If however you want to use a specific value (say 0.80) for every period and you want to check say 200 different periods (from 10 to 210) to find those which will produce an r^2 of greater value than the specific 0.80 you will surely need iteration which is not possible in Metastock formula language. You will need an external dll function to accomplish this.

Hope this helps.

Giorgos
0

#20 User is offline   singashari Icon

  • New Contributor
  • Pip
  • Group: Member
  • Posts: 15
  • Joined: 28-January 10
  • Real Name:ade

Posted 08 February 2010 - 06:30 PM

View PostJohnathanStein, on 05 February 2010 - 03:32 AM, said:

Ade -- You really, really, really need to use it and learn more about how Metastock works.

Specifically, how to plot indicators on a chart, so you can see what they do, and how to use indicators in an Exploration.

It will also be helpful to you to create/attach an Expert, and to modify Indicators used in Experts.

I worked up the code to give you a "leg up" on these things, but there is no shortcut anyone can give you in learning to do them; it just takes time & experience. You have to know/learn the basics of Metastock's features.


I don't think you quite understand how to use indicators, as your question does not make sense.



--Johnathan


Johnathan,
I think I need more experience since I am new on Metastock. Many thank you, for the explanation.

Regards,
Ade
0

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users