Skip to content

Commit

Permalink
Time Series WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
s2t2 committed Sep 20, 2024
1 parent 784565a commit e27f745
Show file tree
Hide file tree
Showing 25 changed files with 351 additions and 29 deletions.
34 changes: 29 additions & 5 deletions docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,33 @@ website:
href: notes/predictive-modeling/regression/ols.qmd
text: "Linear Regression w/ statsmodels"
- section:
href: notes/predictive-modeling/regression/time-series-forecasting.qmd
text: "Time Series Forecasting"
href: notes/predictive-modeling/regression/multiple-features.qmd
text: "Regression with Multiple Features"

- section:
href: notes/predictive-modeling/time-series-forecasting/index.qmd
text: "Regression for Time-series Forecasting"
contents:
- section:
href: notes/predictive-modeling/regression/seasonality.qmd
href: notes/predictive-modeling/time-series-forecasting/polynomial.qmd
text: "Polynomial Features"
- section:
href: notes/predictive-modeling/time-series-forecasting/seasonality.qmd
text: "Seasonality Analysis"

- section:
href: notes/predictive-modeling/regression/autoregressive-models.qmd
text: "Autoregressive Models"
href: notes/predictive-modeling/autoregressive-models/index.qmd
text: "Autoregressive Models for Time-series Forecasting"
contents:
- section:
href: notes/predictive-modeling/autoregressive-models/stationarity.qmd
text: "Stationarity"
- section:
href: notes/predictive-modeling/autoregressive-models/autocorrelation.qmd
text: "Autocorrelation"
- section:
href: notes/predictive-modeling/autoregressive-models/arima.qmd
text: "Autoregressive Models w/ statsmodels"

- section:
href: notes/predictive-modeling/classification/index.qmd
Expand Down Expand Up @@ -356,6 +374,12 @@ website:
- section:
text: "Financial Data Sources"
contents:
- section:
href: notes/financial-data-sources/yfinance.qmd
text: "Y-Finance"
- section:
href: notes/financial-data-sources/yahooquery.qmd
text: "Yahoo Query"
- section:
href: notes/financial-data-sources/pandas-datareader.qmd
text: "Pandas Datareader"
Expand Down
Binary file added docs/data/baseball_data.xlsx
Binary file not shown.
1 change: 1 addition & 0 deletions docs/images/quadratic-equation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/regression-formula.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/stationary-data-variance.webp
Binary file not shown.
Binary file added docs/images/stationary-data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/notes/financial-data-sources/yahooquery.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# The `yahooquery` Package
11 changes: 11 additions & 0 deletions docs/notes/financial-data-sources/yfinance.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# The `yfinance` Pacakge

Fetching data from Yahoo Finance:

```{python}
import yfinance as yf
ticker = "NVDA"
df = yf.download(ticker, start="2014-01-01", end="2024-01-01")
df
```
27 changes: 27 additions & 0 deletions docs/notes/predictive-modeling/autoregressive-models/arima.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Autocorrelation and Auto-Regressive Models

Learning Objectives:

+ Compute autocorrelation in Python using the statsmodels package
+ Use autocorrelation to identify how many periods to use when training an ARMA model
+ Train ARMA model in Python using the statsmodels package, to predict future values given past values.
+ Understand the ARMA model assumption of stationary data.
+ Remember that when making predictions using a trained ARMA model, the dates to predict have to match the format of the training dates. so if the model is trained on monthly data starting at the beginning of the month, we have to predict for dates at the beginning of future months. if the data is trained on quarterly data at the end of the quarter, we have to predict for dates at the end of future quarters.

## Stationary Data

what it means for data to be stationary - the mean does not move over time.


for example:

stock prices would probably not be stationary, however stock returns could be.

gdp might not be stationary, however gdp growth could be.


## Autocorrelation



## Auto-Regressive Moving Average (ARMA)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Autocorrelation

**Autocorrelation** is a statistical concept that measures the relationship between a variable's current value and its past values over successive time intervals.

In time series analysis, autocorrelation helps identify patterns and dependencies in data, particularly when dealing with sequences of observations over time, such as stock prices, temperature data, or sales figures. Autocorrelation analysis is helpful for detecting trends, periodicities, and other temporal patterns in the data, as well as for developing predictive models.

## Interpreting Autocorrelation

Similar to correlation, autocorrelation will range in values from -1 to 1. A positive autocorrelation indicates that a value tends to be similar to preceding values, while a negative autocorrelation suggests that a value is likely to differ from previous observations.

+ **Strong Positive Autocorrelation**: A high positive autocorrelation at a particular lag (close to +1) indicates that past values strongly influence future values at that lag. This could mean that the series has a strong trend or persistent behavior, where high values are followed by high values and low values by low ones.

+ **Strong Negative Autocorrelation**: A strong negative autocorrelation (close to -1) suggests an oscillatory pattern, where high values tend to be followed by low values and vice versa.

+ **Weak Autocorrelation**: If the ACF value is close to zero for a particular lag, it suggests that the time series does not exhibit a strong linear relationship with its past values at that lag. This can indicate that the observations at that lag are not predictive of future values.

## Uses for Predictive Modeling

In predictive modeling, especially for time series forecasting, autocorrelation is essential for selecting the number of lagged observations (or lags) to use in autoregressive models. By calculating the autocorrelation for different lag intervals, it is possible to determine how much influence past values have on future ones. This process helps us choose the optimal lag length, which in turn can improve the accuracy of forecasts.

## Calculating Autocorrelation in Python

In Python, we can calculate autocorrelation using the [`acf` function](https://www.statsmodels.org/stable/generated/statsmodels.tsa.stattools.acf.html) from `statsmodels. The autocorrelation function (ACF) calculates the correlation of a time series with its lagged values, providing a guide to the structure of dependencies within the data.

## Examples of Autocorrelation

### Autocorrelation of Random Data

### Autocorrelation of Baseball Team Performance
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Autoregressive Models
Loading

0 comments on commit e27f745

Please sign in to comment.