This site is best viewed in a browser that conforms to web standards.



BOOL ivorix_ama (
vector<double>& ivec, // input vector
vector<double>& ovec, // output vector
unsigned long span, // time period or span of embedding
unsigned long fastSmoothingPeriod,
unsigned long slowSmoothingPeriod)
{
double fsc = 2.0 / (double) (fastSmoothingPeriod + 1.0);
double ssc = 2.0 / (double) (slowSmoothingPeriod + 1.0);
double se = 2.0 / (double) (span + 1); // short exponent
double le = 1.0 - se; // long exponent
ULONG e = ivec.size();
ULONG x = 0;
ULONG y = 0;
if ( span == 0 || span >= e )
return false;
ovec.resize(ivec.size());
ovec[0] = ivec[0];
for ( x = 1; x < e; x++ )
{
double direction = 0;
double volatility = 0;
double eratio = 0;
double c = 0;
if ( x >= span )
{
direction = ivec[x] - ivec[x - span];
for ( y = 0; y < span; y++ )
volatility += fabs(ivec[x - y] - ivec[x - y - 1]);
if ( volatility != 0 )
{
eratio = direction / volatility;
c = sqr ( (eratio * ( fsc - ssc )) + ssc );
}
ovec[x] = ovec[x-1] + c * (ivec[x] - ovec[x-1]);
}
else
{
ovec[x] = ivec[x] * se + ovec[x-1] * le;
}
}
return true;
}