Skip to content

Commit 9bdadd6

Browse files
Merge pull request #11 from Techtonique/plot-mts
Plot mts
2 parents 0251eab + 1524d99 commit 9bdadd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1474
-11529
lines changed

.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish Python 🐍 distribution 📦 to PyPI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master # Replace with your branch name
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: '3.x' # Replace with your Python version
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install wheel setuptools twine
26+
27+
- name: Build distribution
28+
run: python setup.py sdist bdist_wheel
29+
30+
- name: Run examples
31+
run: pip install .&&find examples -maxdepth 2 -name "*.py" -exec python3 {} \;
32+
33+
- name: Publish to PyPI
34+
uses: pypa/gh-action-pypi-publish@release/v1
35+
with:
36+
password: ${{ secrets.PYPI_AHEAD }}
37+
repository-url: https://upload.pypi.org/legacy/

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# version 0.10.0
2+
3+
- Naming series in input data frame
4+
- Plot method for all the objects
5+
- More about the code: begin refactoring and DRYing --> Base class
6+
17
# version 0.9.0
28

39
- Align with R version

Makefile

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
12
.PHONY: clean clean-test clean-pyc clean-build docs help
23
.DEFAULT_GOAL := help
34

45
define BROWSER_PYSCRIPT
5-
import os, webbrowser, sys
6+
import os, webbrowser, sys, mkdocs
67

78
from urllib.request import pathname2url
89

@@ -31,55 +32,51 @@ clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and
3132
clean-build: ## remove build artifacts
3233
rm -fr build/
3334
rm -fr dist/
34-
rm -fr .eggs/
35+
rm -fr .eggs/
3536
find . -name '*.egg-info' -exec rm -fr {} +
36-
find . -name '*.egg' -exec rm -rf {} +
37+
find . -name '*.egg' -exec rm -fr {} +
3738

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

44-
clean-test: ## remove test and coverage artifacts
45-
rm -fr .tox/
46-
rm -f .coverage
47-
rm -fr htmlcov/
48-
rm -fr .pytest_cache
45+
clean-test: ## remove test and coverage artifacts
46+
rm -fr htmlcov
4947

5048
lint: ## check style with flake8
5149
flake8 ahead tests
5250

53-
test: ## run tests quickly with the default Python
54-
python -m unittest
55-
56-
test-all: ## run tests on every Python version with tox
57-
tox
58-
5951
coverage: ## check code coverage quickly with the default Python
6052
coverage run --source ahead setup.py test
6153
coverage report -m
6254
coverage html
6355
$(BROWSER) htmlcov/index.html
6456

65-
docs: ## generate mkdocs
66-
rm -rf docs/sources
67-
make install
68-
python3 docs/autogen.py
57+
docs: ## generate docs
58+
pip install black pdoc
59+
black ahead/* --line-length=80
60+
pdoc -t docs ahead/* --output-dir ahead-docs
61+
find . -name '__pycache__' -exec rm -fr {} +
6962

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

7469
release: dist ## package and upload a release
75-
twine upload dist/*
70+
pip install twine --ignore-installed
71+
python3 -m twine upload --repository pypi dist/* --verbose
7672

7773
dist: clean ## builds source and wheel package
78-
python3 setup.py bdist_wheel
74+
python3 setup.py sdist
75+
python3 setup.py bdist_wheel
7976
ls -l dist
8077

8178
install: clean ## install the package to the active Python's site-packages
82-
python3 -m pip install .
79+
python3 -m pip install . --verbose
8380

8481
build-site: docs ## put docs website in a directory
8582
cd docs&&mkdocs build

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ The Python implementation contains only the [automatic version](https://thierrym
2727
- From Pypi, stable version:
2828

2929
```bash
30-
pip install ahead
30+
pip install ahead --verbose
3131
```
3232

3333
- From Github, for the development version:
3434

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

3939
## Quickstart

ahead/ARMAGARCH/ArmaGarch.py

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from ..utils import univariate as uv
55
from ..utils import unimultivariate as umv
66

7+
78
class ArmaGarch(object):
8-
""" ARMA(1, 1)-GARCH(1, 1) forecasting (with simulation)
9+
"""ARMA(1, 1)-GARCH(1, 1) forecasting (with simulation)
910
1011
Parameters:
1112
@@ -25,7 +26,7 @@ class ArmaGarch(object):
2526
distribution of innovations ("student" or "gaussian")
2627
2728
seed: an integer;
28-
reproducibility seed
29+
reproducibility seed
2930
3031
date_formatting: a string;
3132
Currently:
@@ -45,15 +46,15 @@ class ArmaGarch(object):
4546
4647
output_dates_: a list;
4748
a list of output dates (associated to forecast)
48-
49+
4950
mean_: a numpy array
50-
contains series mean forecast as a numpy array
51+
contains series mean forecast as a numpy array
5152
52-
lower_: a numpy array
53-
contains series lower bound forecast as a numpy array
53+
lower_: a numpy array
54+
contains series lower bound forecast as a numpy array
5455
55-
upper_: a numpy array
56-
contains series upper bound forecast as a numpy array
56+
upper_: a numpy array
57+
contains series upper bound forecast as a numpy array
5758
5859
result_df_: a data frame;
5960
contains 3 columns, mean forecast, lower + upper
@@ -68,24 +69,19 @@ def __init__(
6869
self,
6970
h=5,
7071
level=95,
71-
B = 250,
72-
cl = 1,
73-
dist = "student",
74-
seed = 123,
72+
B=250,
73+
cl=1,
74+
dist="student",
75+
seed=123,
7576
date_formatting="original",
76-
):
77-
if not config.R_IS_INSTALLED:
78-
raise ImportError("R is not installed! \n" + config.USAGE_MESSAGE)
79-
80-
if not config.RPY2_IS_INSTALLED:
81-
raise ImportError(config.RPY2_ERROR_MESSAGE + config.USAGE_MESSAGE)
82-
77+
):
78+
8379
self.h = h
8480
self.level = level
8581
self.B = B
8682
self.cl = cl
8783
self.dist = dist
88-
self.seed = seed
84+
self.seed = seed
8985
self.date_formatting = date_formatting
9086
self.input_df = None
9187

@@ -94,10 +90,10 @@ def __init__(
9490
self.ranges_ = None
9591
self.output_dates_ = []
9692
self.mean_ = []
97-
self.lower_= []
98-
self.upper_= []
93+
self.lower_ = []
94+
self.upper_ = []
9995
self.result_df_ = None
100-
self.sims_ = None
96+
self.sims_ = None
10197

10298
def forecast(self, df):
10399
"""Forecasting method from `ArmaGarch` class
@@ -109,47 +105,32 @@ def forecast(self, df):
109105
110106
"""
111107

112-
self.input_df = df
108+
# get input dates, output dates, number of series, series names, etc.
109+
self.init_forecasting_params(df)
113110

114-
# obtain dates 'forecast' -----
115-
116-
output_dates, frequency = umv.compute_output_dates(
117-
self.input_df, self.h
118-
)
111+
# obtain time series object -----
112+
self.format_input()
119113

120-
# obtain time series forecast -----
121-
122-
y = uv.compute_y_ts(df=self.input_df, df_frequency=frequency)
123-
124-
self.fcast_ = config.AHEAD_PACKAGE.armagarchf(
125-
y=y,
126-
h=self.h,
127-
level=self.level,
128-
B=self.B,
129-
cl=self.cl,
130-
dist=self.dist,
131-
seed=self.seed
132-
)
114+
self.get_forecast("armagarch")
133115

134116
# result -----
135-
136117
(
137118
self.averages_,
138119
self.ranges_,
139120
self.output_dates_,
140121
) = uv.format_univariate_forecast(
141122
date_formatting=self.date_formatting,
142-
output_dates=output_dates,
123+
output_dates=self.output_dates_,
143124
horizon=self.h,
144125
fcast=self.fcast_,
145126
)
146127

147-
self.mean_ = np.asarray(self.fcast_.rx2['mean'])
148-
self.lower_= np.asarray(self.fcast_.rx2['lower'])
149-
self.upper_= np.asarray(self.fcast_.rx2['upper'])
128+
self.mean_ = np.asarray(self.fcast_.rx2["mean"])
129+
self.lower_ = np.asarray(self.fcast_.rx2["lower"])
130+
self.upper_ = np.asarray(self.fcast_.rx2["upper"])
150131

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

153-
self.sims_ = np.asarray(self.fcast_.rx2['sims'])
134+
self.sims_ = np.asarray(self.fcast_.rx2["sims"])
154135

155136
return self

0 commit comments

Comments
 (0)