[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] r-squared and regression analysis



PureBytes Links

Trading Reference Links




Thanks, Anthony. I knew what r-squared was; I was just confused by the AFL 
code that correlated C with ref(C,-5). You answered my question perfectly. The 
latter compares only 2 data points (I don't know why anyone would want to do 
that; the correlation of 2 points will always be perfect!), whereas you have to 
use cum(1) to look at the strength of a trend over a number of bars. Thanks 
again.
 
AV
<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  Anthony Faragasso 
  
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">amibroker@xxxxxxxxxxxxxxx 
  Sent: Friday, February 14, 2003 10:20 
  PM
  Subject: Re: [amibroker] r-squared and 
  regression analysis
  Al,The R2 indicator measures how closely prices 
  follow a linear regressiontrendline.  This indicates the strength of 
  the trend...the more closelyprices move in a linear relationship with the 
  passing of time, thestronger the trend.It is helpful to consider 
  the R2 in relation to linear regression slope.While linear regression 
  slope gives you the general direction of thetrend ( whether positive or 
  negative ) , R2 gives you the strength ofthe trend. A high R2 value can be 
  associated with a high positive ornegative linear regression 
  slope.Although it is useful to know the R2 value, ideally, you should 
  use R2in tandem with linear regression slope.  High R2 values 
  accompanied by alarge linear regression slope value are of most interest 
  to traders.There is more.....if you 
  want*********************************************************Answering 
  your questions:1. Yes. to the first part....2nd part you are 
  correlating the close tothe close nPeriods ago.( only 2 data points 
  )example, load into indicator builder:R_Squared= 
  Correlation(Cum(1),C,5)^2;R2=Correlation(C,Ref(C,-5),5)^2;Plot(r_squared,"r_squared",colorRed,styleLine);Plot(r2,"r2",colorYellow,styleLine);2. 
  Yes , I am correlating the closing price of the NDX to the closingprice of 
  "whatever ticker", over  n Periods.     Which 
  will tell me how closely the " whatever ticker" is followingthe price 
  movement of the NDX. therefore, this      might 
  be one way to locate stocks to trade...the higher the R2value the more 
  closely the ticker is following the NDX     and the 
  lower the R2 value the more the ticker is moving in theopposite direction 
  ...example...select QQQ's as your ticker....and load the following 
  intoindicator builder...since the QQQ's track the NDX there will be a 
  highR2 value..../***Base Market************/Mkt="^ndx";//Must 
  be enclosed in 
  "....."Quotations.P=Foreign(Mkt,"C",1);/**************************/Periods=14;//Set 
  the period of 
  Observation/***R-Squared*****************/R2=Correlation(P,C,Periods)^2;/*****************************/AnthonyAvcinci 
  wrote:> Anthony, What I was doing was simply citing what the help 
  file gave as> an example of using the correlation function to establish 
  a trend of> closing prices over a period of time. Your explanation 
  probably> reflects my poor understanding of the cum(1) function. When 
  you write> R2 = Correlation(cum(1),C,14)^2, does this mean you are 
  correlating> all the closing prices over the last 14 days (in other 
  words, closing> price as a function of time)? If so, how does this 
  statement differ> from R2 = Correlation(C,ref(C,-pds),pds)^2? In your 
  next R2 statement,> you wrote R2 = (P, C, periods)^2, where P had been 
  assigned to the> closing price of the NDX index. So, it looks like you 
  are correlating> the price of the index with the closing price of 
  something else. I> don't know what all the other stuff about alpha and 
  beta have to do> with that. I guess I'm having difficulty understanding 
  your second R2> statement. Can you enlighten me a bit? Thanks a lot. 
  AV>>      ----- Original Message 
  ----->      From: Anthony 
  Faragasso>      To: 
  amibroker@xxxxxxxxxxxxxxx>      Sent: Friday, 
  February 14, 2003 8:49 PM>      Subject: Re: 
  [amibroker] r-squared and regression 
  analysis>       
  Al,>>      Here is 
  Metastocks:>>      The following is the 
  formula for Metastocks r-squared:>      
  r_squared 
  =Pwr(Corr(Cum(1),C,14,0),2)>>      AFL 
  Translation:>>      
  R_squared=correlation(cum(1),C,14)^2;>>      
  ********************************************>>      
  The formula I posted is from my Alpha and Beta 
  indicators>      located in 
  the>      
  library.>      <A 
  href="">http://www.amibroker.com/library/formula.php?id=157>>      
  //Alpha AND Beta Indicators>      //Ver.1.00, 
  2/10/02>      //coded by Anthony 
  Faragasso>      //e-mail: 
  ajf1111@xxxxxxxx>>      //Insert your 
  Stock_index,Composite_index, 
  S&P,etc.>      //as the **Base 
  Market**.>>      
  MaxGraph=5;>>      /***Base 
  Market************/>      Mkt="^ndx";//Must be 
  enclosed in "....."Quotations.>      
  P=Foreign(Mkt,"C",1);>      
  /**************************/>>      
  Periods=14;//Set the period of 
  Observation>>      
  //****Beta***********************/>>      
  Beta=(( Periods * Sum(ROC( C,1) * ROC(P,1),Periods )) 
  ->      (Sum(ROC(C,1),Periods) * Sum(ROC( 
  P,1),Periods))) />      ((Periods 
  *>      Sum((ROC(P,1)^2 ),Periods)) - 
  (Sum(ROC(P,1 ),Periods)^2 ));>      
  /******************************************/>>      
  //*****Alpha*********************/>>      
  Alpha=(Sum(ROC( C,1) ,Periods) - ( Beta ) * Sum( ROC( 
  P,1)>      ,Periods ) 
  )>      / 
  Periods;>      
  /******************************************/>>      
  /***R-Squared*****************/>      
  R2=Correlation(P,C,Periods)^2;>      
  /************************************/>      
  Graph0=Beta;>      
  Graph0Style=1;>      
  Graph1=Alpha;>>      
  /Graph1=(LastValue(Highest(Graph0))/LastValue(Highest(Graph1)))>      
  *>      
  Graph1;>      
  Graph1Style=1;>>      /**R_squared 
  graphing*****/>      
  Graph2=r2;>      
  Graph2Style=1;>      
  Graph2Color=7;>      
  /*************************/>      
  Title=Name()+"  "+"ALPHA>>      
  +EncodeColor(colorBlue)+"("+WriteVal(Alpha,format=1.2)+")"+">>      
  "+EncodeColor(colorBlack)+"  BETA>      
  "+EncodeColor(colorRed)+"("+WriteVal(Beta,format=1.2)+")"+">      
  "+EncodeColor(colorBlack)+" R_SQUARED>      
  "+EncodeColor(colorYellow)+"("+WriteVal(r2,format=1.2)+")";>>      
  /**Notes***/>      //You've got to start with 
  r-squared, which is an>      //indicator of 
  the validity of the beta AND alpha>      
  //measures. Because the r-squared measures just 
  how>      //closely the Stock OR fund tracks 
  the>      //index with which it is being 
  compared.>>      //An r-squared of 1.0 
  indicates>      //A perfect match. AND, in 
  that case, you can>      //trust that the beta 
  AND alpha measures are>      //valid, too. 
  But, the lower the r-squared, the less>      
  //reliable beta AND alpha measures 
  are.>>      //"[Betas and alphas on] a 
  Stock or  fund with an r-squared>      
  that's below>      //0.50 are completely 
  meaningless.>>      //Assuming the 
  r-squared is, say, 0.75 OR higher, you 
  can>      move on to 
  the>      
  //beta.>>>>      Avcinci 
  wrote:>>      > Anthony, Shouldn't 
  it be: R2 = Correlation(P,>      > 
  ref(P,-periods),periods)^2; ? Al V.>      
  >>      >      
  ----- Original Message ----->      
  >      From: Anthony 
  Faragasso>      
  >      To: 
  amibroker@xxxxxxxxxxxxxxx>      
  >      Sent: Friday, February 14, 2003 8:10 
  PM>      >      
  Subject: Re: [amibroker] r-squared and 
  regression>      
  analysis>      
  >       /***Base 
  Market************/>      
  >      Mkt="^ndx";//Must be enclosed in 
  "....."Quotations.>      
  >      P=Foreign(Mkt,"C",1);//Base 
  market>      
  >>      >      
  Periods=14;//Set the period of 
  Observation>      
  >>      >      
  /***R-Squared*****************/>      
  >      
  R2=Correlation(P,C,Periods)^2;>      
  >>      
  >>      
  >>      >      
  "sidleysh " wrote:>      
  >>      >      
  >  Does anyone know how to construct r-squared in 
  AB?>      
  There>      >      
  is an r->      
  >      > squared function in MetaStock, and I 
  desperately>      need 
  it>      >      to 
  construct>      
  >      > and adaptive MA based on the AT3 from 
  T&A>      
  >      >>      
  >      >>      
  >      
  >                    
  Yahoo! Groups Sponsor>      
  >                              
  ADVERTISEMENT>      
  >>      
  >>      >      
  >>      >      
  > Post AmiQuote-related messages ONLY 
  to:>      >      
  amiquote@xxxxxxxxxxxxxxx>      
  >      > (Web 
  page:>      >      
  <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)>      
  >      >>      
  >      > Check group FAQ 
  at:>      >      
  >>      
  >>      <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html>      
  >      >>      
  >      > Your use of Yahoo! Groups is subject 
  to the Yahoo!>      
  Terms>      >      
  of Service.>      
  >>      
  >>      
  >>      >      
  Post AmiQuote-related messages ONLY to:>      
  >      
  amiquote@xxxxxxxxxxxxxxx>      
  >      (Web 
  page:>      <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)>      
  >>      >      
  Check group FAQ at:>      
  >>      <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html>      
  >>      >      
  Your use of Yahoo! Groups is subject to the 
  Yahoo!>      Terms 
  of>      >      
  Service.>      
  >>      
  >>      
  >                    
  Yahoo! Groups 
  Sponsor>                              
  ADVERTISEMENT>>>      
  >>      > Post AmiQuote-related messages 
  ONLY to:>      
  amiquote@xxxxxxxxxxxxxxx>      > (Web 
  page:>      <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)>      
  >>      > Check group FAQ 
  at:>      
  >>      <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html>      
  >>      > Your use of Yahoo! Groups is 
  subject to the Yahoo! Terms>      of 
  Service.>>>>      Post 
  AmiQuote-related messages ONLY to:>      
  amiquote@xxxxxxxxxxxxxxx>      (Web page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)>>      
  Check group FAQ at:>      <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html>>      
  Your use of Yahoo! Groups is subject to the Yahoo! Terms 
  of>      
  Service.>>>                    
  Yahoo! Groups 
  Sponsor                        
  ADVERTISEMENT>> Post AmiQuote-related messages ONLY to: 
  amiquote@xxxxxxxxxxxxxxx> (Web page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)>> 
  Check group FAQ at:> <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html>> 
  Your use of Yahoo! Groups is subject to the Yahoo! Terms of 
  Service.Post 
  AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)Check 
  group FAQ at: <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
  Your use of Yahoo! Groups is subject to the <A 
  href="">Yahoo! Terms of Service. 







Yahoo! Groups Sponsor


  ADVERTISEMENT









Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.