# Time Series Analysis Techniques
### Simple Moving Average
An SMA simply take the $k$ most recent observations of our variable of interest, sum them, and divides by $k$:
$\frac{1}{k} \sum_{i=1}^k x_i$
For example, a 15 day moving average for the price of Tesla stock would take the the 15 most recent days of Tesla stock and calculate there average price.
### Weighted Moving Average
This is simply the same thing as the simple moving average, only now we are going to place a greater importance on specific values. Frequently, this will be done if we want to prioritize either the *most recent* data points, or *older data* points.
For instance, in our Tesla example, say we are looking at a 4 week weighted average, where we want to place more importance on the most recent weeks. We may determine our weights to be:
$X_t\cdot0.4 + X_{t-1}\cdot0.3 + X_{t-2}\cdot0.2 + X_{t-3}\cdot0.1$
### Exponentially Weighted Moving Averages
See: [andrew ng approach](https://www.youtube.com/watch?v=lAq96T8FkTw) and [my notes](https://www.nathanieldake.com/Deep_Learning/02-Modern_Deep_Learning-03-Momentum-and-Adaptive-Learning-Rates.html#6.1-Exponentially-Smoothed-Averages).
### Auto Regression
This is where you are trying to predict a value based on past values of that same thing. For instance, you are trying to predict quantity of milk sold in June 2019 based on the quantity of milk sold each month for the past 3 years.
Mathematically our model is very straightforward:
$x_t = \beta_0 + \beta_1x_{t-1} + \beta_2x_{t-2} + \dots + \beta_kx_{t-k}$
Where we are simply saying that for some variable $x$, we predict its value at the current time $t$ to be a function of it's values at previous points in time, going back $k$ time steps. IT can be writen more simply as:
$X_t = \sum_{i=1}^k \beta_i X_{t-i} + \epsilon_t$
### Vector Auto Regression
Now are are dealing with two variables, $y_1$ and $y_2$, and we are saying that their current values depend on their own past value and each others past value.
$
{\begin{bmatrix}y_{1,t}\\y_{2,t}\end{bmatrix}}={\begin{bmatrix}c_{1}\\c_{2}\end{bmatrix}}+{\begin{bmatrix}a_{1,1}&a_{1,2}\\a_{2,1}&a_{2,2}\end{bmatrix}}{\begin{bmatrix}y_{1,t-1}\\y_{2,t-1}\end{bmatrix}}+{\begin{bmatrix}e_{1,t}\\e_{2,t}\end{bmatrix}}
$
### ARIMA
---
Date: 20210521
Links to: [Anomaly Detection Contribution-Analysis](Anomaly%20Detection%20Contribution-Analysis.md) [Optimization-Techniques](Optimization-Techniques.md) [Mathematics MOC](Mathematics%20MOC.md) [003-Data-Science-MOC](003-Data-Science-MOC.md)
References:
* [Auto Regression](https://www.youtube.com/watch?v=5-2C4eO4cPQ)
* [Vector Auto Regression](https://www.youtube.com/watch?v=UQQHSbeIaB0)
* [Simple moving average](https://www.youtube.com/watch?v=x4nO5yoarM0)
* [Exponentially weighted moving average](https://www.youtube.com/watch?v=lAq96T8FkTw)