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

[amibroker] Regression Moving Forecast - Plot



PureBytes Links

Trading Reference Links


Would some kind soul convert this c++ to .afl with plot vs. close
..a regression moving forecast vs. closing price ...

Thanks in advance!

mv


//--Begin ---Regression Moving Forecast -------------- //

BOOL rmf (
          vector<double>& ivec,     // input  vector
          vector<double>& ovec,     // output vector
          unsigned long   span)     // time period or span of embedding
{
    ULONG   x       = 0;
    ULONG   y       = 0;
    double  sx      = 0;
    double  sxs     = 0;
    double  sy      = 0;
    double  sxy     = 0;
    double  intercept1   = 0;
    double  slope   = 0;
    double  p       = span;
    ULONG   e       = ivec.size();
    double  se      = 2.0 / (p / 3.0 + 1.0); // short exponent
    double  le      = 1.0 - se;              // long exponent

    if ( span == 0 || span >= e )
        return false;

    ovec.resize(ivec.size());

    // calculate the sum and the sum of squares
    // of the time series x-axis
    for ( x = 1; x <= span; x++ )
    {
        sx  += x;
        sxs += sqr(x);
    }

    ovec[0] = ivec[0];

    for ( y = 0; y < e; y++ )
    {
        slope  = 0;
        intercept1  = 0;

        if ( y >= span - 1 )
        {
            sy  = 0;
            sxy = 0;

            for ( x = 0; x < span; x++ )
            {
                sy  += ivec[y-x];
                sxy += ivec[y-x] * (span - x);
            }

            slope   = (sxy - ((sx * sy) / p)) / (sxs - (sqr(sx) / p));
            intercept1   = (sy - (slope * sx)) / p;
            ovec[y] = intercept1 + p * slope;
            ovec[y] = (ovec[y] * se) + ivec[y-1] * le;
        }
        else
        {
            if ( y > 0 )
            {
                ovec[y] = ivec[y] * se + ovec[y-1] * le;
            }
        }
    }

    return true;
}

//-- End ---Regression Moving Forecast -------------- //






------------------------ Yahoo! Groups Sponsor --------------------~--> 
In low income neighborhoods, 84% do not own computers.
At Network for Good, help bridge the Digital Divide!
http://us.click.yahoo.com/EpW3eD/3MnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.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/