Skip to content

Commit

Permalink
Merge pull request #11 from Techtonique/plot-mts
Browse files Browse the repository at this point in the history
Plot mts
  • Loading branch information
thierrymoudiki authored Feb 26, 2024
2 parents 0251eab + 1524d99 commit 9bdadd6
Show file tree
Hide file tree
Showing 87 changed files with 1,474 additions and 11,529 deletions.
Binary file modified .DS_Store
Binary file not shown.
37 changes: 37 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish Python 🐍 distribution 📦 to PyPI

on:
workflow_dispatch:
push:
branches:
- master # Replace with your branch name

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x' # Replace with your Python version

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel setuptools twine
- name: Build distribution
run: python setup.py sdist bdist_wheel

- name: Run examples
run: pip install .&&find examples -maxdepth 2 -name "*.py" -exec python3 {} \;

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_AHEAD }}
repository-url: https://upload.pypi.org/legacy/
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# version 0.10.0

- Naming series in input data frame
- Plot method for all the objects
- More about the code: begin refactoring and DRYing --> Base class

# version 0.9.0

- Align with R version
Expand Down
45 changes: 21 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

.PHONY: clean clean-test clean-pyc clean-build docs help
.DEFAULT_GOAL := help

define BROWSER_PYSCRIPT
import os, webbrowser, sys
import os, webbrowser, sys, mkdocs

from urllib.request import pathname2url

Expand Down Expand Up @@ -31,55 +32,51 @@ clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and
clean-build: ## remove build artifacts
rm -fr build/
rm -fr dist/
rm -fr .eggs/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -rf {} +
find . -name '*.egg' -exec rm -fr {} +

clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +

clean-test: ## remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
clean-test: ## remove test and coverage artifacts
rm -fr htmlcov

lint: ## check style with flake8
flake8 ahead tests

test: ## run tests quickly with the default Python
python -m unittest

test-all: ## run tests on every Python version with tox
tox

coverage: ## check code coverage quickly with the default Python
coverage run --source ahead setup.py test
coverage report -m
coverage html
$(BROWSER) htmlcov/index.html

docs: ## generate mkdocs
rm -rf docs/sources
make install
python3 docs/autogen.py
docs: ## generate docs
pip install black pdoc
black ahead/* --line-length=80
pdoc -t docs ahead/* --output-dir ahead-docs
find . -name '__pycache__' -exec rm -fr {} +

servedocs: docs ## compile the docs watching for changes
cd docs&&mkdocs serve
cd ..
servedocs: ## compile the docs watching for change
pip install black pdoc
black ahead/* --line-length=80
pdoc -t docs ahead/*
find . -name '__pycache__' -exec rm -fr {} +

release: dist ## package and upload a release
twine upload dist/*
pip install twine --ignore-installed
python3 -m twine upload --repository pypi dist/* --verbose

dist: clean ## builds source and wheel package
python3 setup.py bdist_wheel
python3 setup.py sdist
python3 setup.py bdist_wheel
ls -l dist

install: clean ## install the package to the active Python's site-packages
python3 -m pip install .
python3 -m pip install . --verbose

build-site: docs ## put docs website in a directory
cd docs&&mkdocs build
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ The Python implementation contains only the [automatic version](https://thierrym
- From Pypi, stable version:

```bash
pip install ahead
pip install ahead --verbose
```

- From Github, for the development version:

```bash
pip install git+https://github.com/Techtonique/ahead_python.git
pip install git+https://github.com/Techtonique/ahead_python.git --verbose
```

## Quickstart
Expand Down
77 changes: 29 additions & 48 deletions ahead/ARMAGARCH/ArmaGarch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from ..utils import univariate as uv
from ..utils import unimultivariate as umv


class ArmaGarch(object):
""" ARMA(1, 1)-GARCH(1, 1) forecasting (with simulation)
"""ARMA(1, 1)-GARCH(1, 1) forecasting (with simulation)
Parameters:
Expand All @@ -25,7 +26,7 @@ class ArmaGarch(object):
distribution of innovations ("student" or "gaussian")
seed: an integer;
reproducibility seed
reproducibility seed
date_formatting: a string;
Currently:
Expand All @@ -45,15 +46,15 @@ class ArmaGarch(object):
output_dates_: a list;
a list of output dates (associated to forecast)
mean_: a numpy array
contains series mean forecast as a numpy array
contains series mean forecast as a numpy array
lower_: a numpy array
contains series lower bound forecast as a numpy array
lower_: a numpy array
contains series lower bound forecast as a numpy array
upper_: a numpy array
contains series upper bound forecast as a numpy array
upper_: a numpy array
contains series upper bound forecast as a numpy array
result_df_: a data frame;
contains 3 columns, mean forecast, lower + upper
Expand All @@ -68,24 +69,19 @@ def __init__(
self,
h=5,
level=95,
B = 250,
cl = 1,
dist = "student",
seed = 123,
B=250,
cl=1,
dist="student",
seed=123,
date_formatting="original",
):
if not config.R_IS_INSTALLED:
raise ImportError("R is not installed! \n" + config.USAGE_MESSAGE)

if not config.RPY2_IS_INSTALLED:
raise ImportError(config.RPY2_ERROR_MESSAGE + config.USAGE_MESSAGE)

):

self.h = h
self.level = level
self.B = B
self.cl = cl
self.dist = dist
self.seed = seed
self.seed = seed
self.date_formatting = date_formatting
self.input_df = None

Expand All @@ -94,10 +90,10 @@ def __init__(
self.ranges_ = None
self.output_dates_ = []
self.mean_ = []
self.lower_= []
self.upper_= []
self.lower_ = []
self.upper_ = []
self.result_df_ = None
self.sims_ = None
self.sims_ = None

def forecast(self, df):
"""Forecasting method from `ArmaGarch` class
Expand All @@ -109,47 +105,32 @@ def forecast(self, df):
"""

self.input_df = df
# get input dates, output dates, number of series, series names, etc.
self.init_forecasting_params(df)

# obtain dates 'forecast' -----

output_dates, frequency = umv.compute_output_dates(
self.input_df, self.h
)
# obtain time series object -----
self.format_input()

# obtain time series forecast -----

y = uv.compute_y_ts(df=self.input_df, df_frequency=frequency)

self.fcast_ = config.AHEAD_PACKAGE.armagarchf(
y=y,
h=self.h,
level=self.level,
B=self.B,
cl=self.cl,
dist=self.dist,
seed=self.seed
)
self.get_forecast("armagarch")

# result -----

(
self.averages_,
self.ranges_,
self.output_dates_,
) = uv.format_univariate_forecast(
date_formatting=self.date_formatting,
output_dates=output_dates,
output_dates=self.output_dates_,
horizon=self.h,
fcast=self.fcast_,
)

self.mean_ = np.asarray(self.fcast_.rx2['mean'])
self.lower_= np.asarray(self.fcast_.rx2['lower'])
self.upper_= np.asarray(self.fcast_.rx2['upper'])
self.mean_ = np.asarray(self.fcast_.rx2["mean"])
self.lower_ = np.asarray(self.fcast_.rx2["lower"])
self.upper_ = np.asarray(self.fcast_.rx2["upper"])

self.result_df_ = umv.compute_result_df(self.averages_, self.ranges_)

self.sims_ = np.asarray(self.fcast_.rx2['sims'])
self.sims_ = np.asarray(self.fcast_.rx2["sims"])

return self
Loading

0 comments on commit 9bdadd6

Please sign in to comment.