#include "CalcLibCalc.h"

/// <summary>
/// Class:	SimpleMovingAverage 
/// 
/// A simple moving average is formed by finding the average price 
/// of a security over a set number of periods. Most often, the 
/// closing price is used to compute the moving average. For 
/// example: a 5-day moving average would be calculated by adding 
/// the closing prices for the last 5 days and dividing the total 
/// by 5.
/// example:
/// 10 + 11 + 12 + 13 + 14 = 60
/// 60 / 5 = 12
/// 
/// A moving average moves because as the newest period is added, 
/// the oldest period is dropped. If the next closing price in the 
/// average is 15, then this new period would be added and the 
/// oldest day, which is 10, would be dropped. The new 5-day moving 
/// average would be calculated as follows:
/// 
/// 11 + 12 + 13 + 14 + 15 = 65
/// 65 / 5 = 13
/// 
/// Over the last 2 days, the moving average moved from 12 to 13. 
/// As new days are added, the old days will be subtracted and 
/// the moving average will continue to move over time.


	/// </summary>
class CalcLibSMA : public CalcLibCalc
{
private:
	int m_period;		//Number of values to take
	double getSum(int start, int length);
public:
	inline int getPeriod() { return m_period; }
	CalcLibSMA() { };
	CalcLibSMA(DOUBLEVECTOR values, DATEVECTOR dates, int periods);
	int doCalc();
	CalcLibData getOutputPoint(int index);
};
