moving_average.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef MOVING_AVERAGE_H_
00013 #define MOVING_AVERAGE_H_
00014
00015 #include "settings_type.h"
00016 #include "core/math_func.hpp"
00017
00025 template<class Tvalue>
00026 class MovingAverage {
00027 protected:
00028 uint length;
00029
00030 public:
00035 FORCEINLINE MovingAverage(uint length) : length(length)
00036 {
00037 assert(this->length > 0);
00038 }
00039
00044 FORCEINLINE uint Length() const
00045 {
00046 return this->length;
00047 }
00048
00059 FORCEINLINE Tvalue Monthly(const Tvalue &value) const
00060 {
00061 return (value * 30) / (this->length);
00062 }
00063
00069 FORCEINLINE Tvalue &Decrease(Tvalue &value) const
00070 {
00071 return value = (value * this->length) / (this->length + 1);
00072 }
00073 };
00074
00075 template<class Titem> void RunAverages();
00076
00077 #endif
00078