15 for (
int i = 0; i < iCount; ++i) {
16 dSum += listValues[i];
18 return dSum /
static_cast<double>(iCount);
24 int iMinCount = bIsSample ? 2 : 1;
25 if (iCount < iMinCount)
throw ArgumentException(
"Insufficient values to compute variance.");
26 double dMean =
Mean(listValues);
27 double dSumSquares = 0.0;
28 for (
int i = 0; i < iCount; ++i) {
29 double dDiff = listValues[i] - dMean;
30 dSumSquares += dDiff * dDiff;
32 int iDivisor = bIsSample ? (iCount - 1) : iCount;
33 return dSumSquares /
static_cast<double>(iDivisor);
38 return std::sqrt(
Variance(listValues, bIsSample));
50 if (iCount < iPeriod)
throw ArgumentException(
"Not enough data points for moving average window.");
52 int iStart = iCount - iPeriod;
53 for (
int i = iStart; i < iCount; ++i) {
54 dSum += listValues[i];
56 return dSum /
static_cast<double>(iPeriod);
65 if (iCount < iPeriod)
return listResult;
66 double dCurrentSum = 0.0;
67 for (
int i = 0; i < iPeriod; ++i) {
68 dCurrentSum += listValues[i];
70 listResult.
Add(dCurrentSum /
static_cast<double>(iPeriod));
71 for (
int i = iPeriod; i < iCount; ++i) {
72 dCurrentSum += listValues[i] - listValues[i - iPeriod];
73 listResult.
Add(dCurrentSum /
static_cast<double>(iPeriod));
81 for (
int i = 0; i < iPeriod; ++i) {
82 dSum += listValues[i];
84 return dSum /
static_cast<double>(iPeriod);
93 double dMultiplier = dSmoothing / (
static_cast<double>(iPeriod) + 1.0);
95 for (
int i = iPeriod; i < iCount; ++i) {
96 dEma = (listValues[i] - dEma) * dMultiplier + dEma;
107 if (iCount < iPeriod)
return listResult;
108 double dMultiplier = dSmoothing / (
static_cast<double>(iPeriod) + 1.0);
110 listResult.
Add(dEma);
111 for (
int i = iPeriod; i < iCount; ++i) {
112 dEma = (listValues[i] - dEma) * dMultiplier + dEma;
113 listResult.
Add(dEma);
Defines the exception thrown when an invalid argument is provided to a method.
Defines the exception thrown when an argument value is outside the acceptable range of values.
Provides constants and static methods for trigonometric, logarithmic, and other common mathematical f...
ArgumentException(const String &sMessage)
Initializes a new instance of the ArgumentException class with a specified error message.
ArgumentOutOfRangeException(const String &sMessage)
Initializes a new instance of the ArgumentOutOfRangeException class with a specified error message.
Represents a strongly typed list of objects accessible by index.
void Add(const T &item) override
Adds an object to the end of the List.
int GetCount() const override
Gets the number of elements contained in the List.
static double Mean(const Collections::Generic::List< double > &listValues)
Computes the arithmetic mean of a sequence of double values.
static Collections::Generic::List< double > ExponentialMovingAverageSeries(const Collections::Generic::List< double > &listValues, int iPeriod, double dSmoothing=2.0)
Computes the rolling exponential moving average (EMA) series across the sequence.
static double Variance(const Collections::Generic::List< double > &listValues, bool bIsSample=false)
Computes the variance of a sequence of double values.
static double StandardDeviation(const Collections::Generic::List< double > &listValues, bool bIsSample=false)
Computes the standard deviation of a sequence of double values.
static double StdDev(const Collections::Generic::List< double > &listValues, bool bIsSample=false)
Computes the standard deviation of a sequence of double values (abbreviated alias).
static double MovingAverage(const Collections::Generic::List< double > &listValues, int iPeriod)
Computes the simple moving average (SMA) over the final window of length iPeriod.
static Collections::Generic::List< double > MovingAverageSeries(const Collections::Generic::List< double > &listValues, int iPeriod)
Computes the rolling simple moving average (SMA) series across all values.
static double ExponentialMovingAverage(const Collections::Generic::List< double > &listValues, int iPeriod, double dSmoothing=2.0)
Computes the exponential moving average (EMA) value for the sequence.
static double ComputeInitialSma(const Collections::Generic::List< double > &listValues, int iPeriod)