Backend/Database/GAnalysis.cpp
/*!
 * @brief calculates exponential moving average
 * @details exponential moving average calculation
 * @param input the stock prices in a vector
 * @param period the length of a period
 */
@brief calculates exponential moving average
@details exponential moving average calculation
@param input the stock prices in a vector
@param period the length of a period
@brief calculates exponential moving average @details exponential moving average calculation @param input the stock prices in a vector @param period the length of a period
std::vector<float> GAnalysis::ExpMovingAverage(const std::vector<float>& input, unsigned int period)
{
	std::vector<float> exp_avg, sma;
	float smooth;
	unsigned int counter = 0;
	sma = SimpleMovingAverage(input, period);
	smooth = 2.0 / (period + 1);
	unsigned int len = input.size();
	for (unsigned int i = period - 1; i <= len - 1; ++i)
	{
		if (counter == 0)
		{
			exp_avg.push_back(sma[counter]);
		}
		else
		{
			exp_avg.push_back(smooth * (input[period - 1 + counter] - exp_avg[counter - 1]) +
							  exp_avg[counter - 1]);
		}
		++counter;
	}
	return exp_avg;
}
std :: vector < float > GAnalysis :: ExpMovingAverage ( const std :: vector < float > & input , unsigned int period ) { std :: vector < float > exp_avg , sma ; float smooth ; unsigned int counter = 0 ; sma = SimpleMovingAverage ( input , period ) ; smooth = 2.0 / ( period + 1 ) ; unsigned int len = input . size ( ) ; for ( unsigned int i = period - 1 ; i <= len - 1 ; ++ i ) { if ( counter == 0 ) { exp_avg . push_back ( sma [ counter ] ) ; } else { exp_avg . push_back ( smooth * ( input [ period - 1 + counter ] - exp_avg [ counter - 1 ] ) + exp_avg [ counter - 1 ] ) ; } ++ counter ; } return exp_avg ; }
@brief calculates exponential moving average
 @details exponential moving average calculation
 @param input the stock prices in a vector
 @param period the length of a period
@brief calculates exponential moving average @details exponential moving average calculation @param input the stock prices in a vector @param period the length of a period