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

Re: FW: [amibroker] Curvilinear (Parabolic) second order regression



PureBytes Links

Trading Reference Links


> I am hopeful that someone with a better understanding of math 
and/or
> AB will fix the code I've shown to remove these problems.  PLEASE
> re-post your corrections here.






Replace
X       = Cum(1);

with
x = BarIndex() - LastValue( BarIndex() - npnt );





 
> // Regression Fit to a Quadratic Equation */
> // Ed Hoopes
> // April 2005
> // Rev A
> 
> // Number of lookback days;
> NPNT    = Param("Pers", 50, 8, 200);
> 
> X       = Cum(1);        // The x cordinate array (# of Bars);
> Y       = Close;         // The y co-ordinate array (Prices);    
> 
> // Calculate some terms;
> 
> SUMX    = LastValue(Sum(X,NPNT));
> SUMY    = LastValue(Sum(Y,NPNT));
> SUMXY   = LastValue(Sum(X*Y,NPNT));
> SUMSQX  = LastValue(Sum(X*X,NPNT));
> SUMX3   = LastValue(Sum(X*X*X,NPNT));
> SUMX4   = LastValue(Sum(X*X*X*X,NPNT));
> SUMX2Y  = LastValue(Sum(Y*X*X,NPNT));
> 
> // Calculate some more terms;
> XPNT    = NPNT;
> RECIP   = 1 / XPNT;
> SAVEA   = SUMSQX  - ((SUMX * SUMX) / XPNT);
> SAVEC   = SUMXY   - ((SUMX * SUMY) / XPNT);
> 
> XMEAN   = SUMX / XPNT;
> YMEAN   = SUMY / XPNT;
> 
> // Fake a 3x3 matrix with variables - fake a Gauss Elimination;
> 
> COEF21  = SAVEC / SAVEA ;
> 
> TEMP    = (SUMX * SUMSQX) / XPNT ;
> TEMP1   = SUMX3 - TEMP;
> 
> COEF32  = (((SUMX2Y - ((SUMY   * SUMSQX) / XPNT)) / TEMP1) -  
COEF21) / 
> 			(((SUMX4  - ((SUMSQX * SUMSQX) / XPNT)) / 
TEMP1) - (TEMP1 / SAVEA));
> 
> COEF22  = (SAVEC - COEF32 * (SumX3 - TEMP)) / SAVEA;
> 
> COEF12  = YMEAN - (COEF22 * XMEAN) - (COEF32 * (SUMSQX * RECIP));
> 
> ATERM   = COEF12;  
> BTERM   = COEF22;
> CTERM   = COEF32;
> 
> /* Force the x value to be very negative so the graph does not 
appear
> before the lookback period */
> 
> Domain =  IIf ( X > LastValue(X) - NPNT, 1 , -1e10);   
> X = X * Domain;
> 
> // Quadratic Regression Line y = a + bx + cx^2  ;
> 
> Y = ATERM + BTERM * X + CTERM * X * X;
> 
> // Plot a Bar chart; 
> Graph0      = Close;
> Graph0Style = styleBar;
> Graph0Color = colorLightGrey;
> 
> // Plot the Quadratic Fit */
> Graph1      = Y;
> Graph1Style = styleLine;
> Graph1Color = colorYellow;






------------------------ Yahoo! Groups Sponsor --------------------~--> 
Has someone you know been affected by illness or disease?
Network for Good is THE place to support health awareness efforts!
http://us.click.yahoo.com/Rcy2bD/UOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/