Backend/Database/GAnalysis.cpp
/*!
 * @brief calculates SMA
 * @details Simple Moving Average calculation
 * @param input the stock prices in a vector
 * @param period the length of a period
 */
@brief calculates SMA
@details Simple Moving Average calculation
@param input the stock prices in a vector
@param period the length of a period
@brief calculates SMA @details Simple Moving Average calculation @param input the stock prices in a vector @param period the length of a period
std::vector<float> GAnalysis::SimpleMovingAverage(const std::vector<float>& input,
												  unsigned int period)
{
	std::vector<float> avg;
	float sum = 0;
	unsigned int len = input.size();
	for (unsigned int i = 0; i <= len - period; ++i)
	{
		for (unsigned int j = i; j < i + period; ++j)
		{
			sum = sum + input[j];
		}
		avg.push_back(sum / period);
		sum = 0;
	}
	return avg;
}
std :: vector < float > GAnalysis :: SimpleMovingAverage ( const std :: vector < float > & input , unsigned int period ) { std :: vector < float > avg ; float sum = 0 ; unsigned int len = input . size ( ) ; for ( unsigned int i = 0 ; i <= len - period ; ++ i ) { for ( unsigned int j = i ; j < i + period ; ++ j ) { sum = sum + input [ j ] ; } avg . push_back ( sum / period ) ; sum = 0 ; } return avg ; }
@brief calculates SMA
 @details Simple Moving Average calculation
 @param input the stock prices in a vector
 @param period the length of a period
@brief calculates SMA @details Simple Moving Average calculation @param input the stock prices in a vector @param period the length of a period