Home Login  |   Contact  |   About Us       Wednesday, April 17, 2024   

j0185201- Back to Home
   Skip Navigation LinksHOME ›  AREAS OF EXPERTISE  #2 ›   Curve Fitting  ›  ~ Simple Moving Avg



Skip Navigation Links.



"Curve Fitting Solutions"
Simple Moving Average Method
SMA =


DATA ARRAY

{ , , , , , , , , ,
, , , , , , , , , }



[ Initial Data Array(top): { 45.375, 45.500, 45.000, 43.625, 43.375, 43.125, 43.125, 44.250, 43.500, 44.375 } ]
[ Initial Data Array(bot): { 45.875, 46.750, 47.625, 48.000, 49.125, 48.750, 46.125, 46.750, 46.625, 46.000 } ]

Time Frame:

                                       

IMPLEMENTATION
Curve Fitting Simple Moving Average

Moving averages is often used in analyzing time series data. It is widely applied in finance, particularly in technical analysis. It can also be used as a generic smoothing operation, in which case the data need not be a time series.

A moving average series can be calculated for any time series. In finance it is most often applied to stock prices, returns, or trading volumes. Moving averages are used to smooth out short-term fluctuations, thus highlighting longer-term trends or cycles.

A moving average smooths data by replacing each data point with the average of the neighboring data points defined within the time span.

A simple moving average (SMA) is the mean value of the previous n data points. For example, a 5-day simple moving average of an opening price is the mean of the previous 5 days' opening prices. If those prices are p0, p-1, p-2, p-3, p-4 then the moving average is described by,

SMA = p0 + p-1 + p-2 + p-3 + p-4 / 5

In general, for n-day moving average,

SMA = (p0 + p-1 + p-2 + p-3 + p-4 / n) = 1/n ∑i=0 pi

When calculating successive values, a new value comes into the sum and an old value drops out, meaning a full summation each time is unnecessary.

Technical analysis uses various popular values for n, like 10 days, 40 days, or 100 days. The period selected depends on the kind of movement one is concentrating on, such as short, intermediate or long term.


Testing the Simple Average Moving Method

In order to test the Simple Average Moving Method as defined above, a new SimpleAverageMovingMethod() static method has been added and executed. Supporting code and methods are not shown.

           static void SimpleAverageMovingMethod();
              {
                 ListBox1.Items.Clear();
                 double[] xarray = new double[] {t1, t2, t3, t4, t5, t6, t7, t8,
                 t9, t10, t11, t12, t13, t14, t15, t16,
                 t17, t18, t19, t20};
                 VectorR sma = CurveFitting.SimpleMovingAverage(data, 5);
                 ListBox1.Items.Add(" " + sma.ToString());
              }

As a sample we provide the input data points using one double array using data of a stock for 20 days (Data Array), and use to calculate a 5-day time frame n simple moving average.

The user can manipulate all values and try variations on the arrays themselves by specifying new estimate values.



Other Implementations...


Object-Oriented Implementation
Graphics and Animation
Sample Applications
Ore Extraction Optimization
Vectors and Matrices
Complex Numbers and Functions
Ordinary Differential Equations - Euler Method
Ordinary Differential Equations 2nd-Order Runge-Kutta
Ordinary Differential Equations 4th-Order Runge-Kutta
Higher Order Differential Equations
Nonlinear Systems
Numerical Integration
Numerical Differentiation
Function Evaluation


   Quotes

Consulting Services - Back to Home


Home

Home Math, Analysis,
  expertise..."

EIGENVALUE
SOLUTIONS...


> Rayleigh-Quotient Method

> Cubic Spline Method

 

Applied Mathematical Algorithms

Home

ComplexFunctions

Home

NonLinear
Home

Differentiation
Home

Integration
About Us


KMP Software Engineering is an independent multidisciplinary engineering consulting company specializing in mathematical algorithms.

      (About Us) →
Areas of
Expertise


SpecialFunctions
VectorsMatrices
OptimizationMethods
ComplexNumbers
Interpolation
CurveFitting
NonLinearSystems
LinearEquations
DistributionFunctions
NumericalDifferentiation
NumericalIntegration
DifferentialEquations
Smalltalk
FiniteBoundary
Eigenvalue
Graphics
Understanding
Mining


MiningMastery
MineralNews
MineralCommodities
MineralForum
Crystallography
Services


NumericalModeling
WebServices
MainframeServices
OutsourceServices

LINKED IN
MINE REVIEW(by G.Pacheco)
Brand





Home

Login

Contact
Since 2006 All Rights Reserved  © KMP Software Engineering LINKS | PRIVACY POLICY | LEGAL NOTICE