Backend/Database/GAnalysis.cpp
/*!
 * @brief calculates OBV
 * @details OBV calculation
 * @param input the closing stock prices in a vector
 * @param volume the corresponding volumes in a vector
 */
@brief calculates OBV
@details OBV calculation
@param input the closing stock prices in a vector
@param volume the corresponding volumes in a vector
@brief calculates OBV @details OBV calculation @param input the closing stock prices in a vector @param volume the corresponding volumes in a vector
std::vector<float> GAnalysis::OBV(const std::vector<float>& close, const std::vector<float>& volume)
{
	unsigned int len = close.size();
	float prev_price = 0.0f;
	std::vector<float> obvs;
	for (unsigned int i = 0; i < len; ++i)
	{
		if (i == 0)
			obvs.push_back(abs(volume[i]));
		else if (close[i] < prev_price)
			obvs.push_back(obvs[i - 1] - volume[i]);
		else if (close[i] > prev_price)
			obvs.push_back(obvs[i - 1] + volume[i]);
		else
			obvs.push_back(obvs[i - 1]);
		prev_price = close[i];
	}
	return obvs;
}
std :: vector < float > GAnalysis :: OBV ( const std :: vector < float > & close , const std :: vector < float > & volume ) { unsigned int len = close . size ( ) ; float prev_price = 0.0f ; std :: vector < float > obvs ; for ( unsigned int i = 0 ; i < len ; ++ i ) { if ( i == 0 ) obvs . push_back ( abs ( volume [ i ] ) ) ; else if ( close [ i ] < prev_price ) obvs . push_back ( obvs [ i - 1 ] - volume [ i ] ) ; else if ( close [ i ] > prev_price ) obvs . push_back ( obvs [ i - 1 ] + volume [ i ] ) ; else obvs . push_back ( obvs [ i - 1 ] ) ; prev_price = close [ i ] ; } return obvs ; }
@brief calculates OBV
 @details OBV calculation
 @param input the closing stock prices in a vector
 @param volume the corresponding volumes in a vector
@brief calculates OBV @details OBV calculation @param input the closing stock prices in a vector @param volume the corresponding volumes in a vector
// float prev_vol = 0.0f;
 // prev_vol = volume[i];
