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

Re: [amibroker] r-squared and regression analysis



PureBytes Links

Trading Reference Links

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.
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:
>      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.
>
>
>
>      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.
>
>
>                    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.


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 http://docs.yahoo.com/info/terms/