diff --git a/.header-template b/.header-template index 78bae3f..c3ce0be 100644 --- a/.header-template +++ b/.header-template @@ -1,5 +1,5 @@ # This file is part of the # Garpar Project (https://github.com/quatrope/garpar). -# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# Copyright (c) 2021, 2022, 2023, 2024, Diego Gimenez, Nadia Luczywo, Juan Cabral and QuatroPe # License: MIT # Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE \ No newline at end of file diff --git a/1 archivos sin guardar b/1 archivos sin guardar deleted file mode 100644 index 3410062..0000000 --- a/1 archivos sin guardar +++ /dev/null @@ -1 +0,0 @@ -c \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index 4c8cf12..a9f814e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,13 +1,14 @@ include LICENSE include README.md +include pyproject.toml recursive-include garpar *.csv exclude tox.ini -exclude pyproject.toml exclude .header-template +exclude requirements.txt recursive-exclude tests * recursive-exclude draft * recursive-exclude tools * - +recursive-exclude res * diff --git a/README.md b/README.md index fc11bf2..7345d6a 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,18 @@ > _Generación y análisis de retornos de portafolios artificiales y reales_ > > Generation and analysis of artificial and real portfolio returns + +------------------------------------------- +## Pasos para correr el proyecto + +`git clone git@github.com:quatrope/garpar.git` + +Luego de clonar el repositorio: + +``` +pip install build + +python -m build + +pip install dist/garpar-0.1-py3-none-any.whl +``` diff --git a/Untitled-1.ipynb b/draft/Untitled-1.ipynb similarity index 100% rename from Untitled-1.ipynb rename to draft/Untitled-1.ipynb diff --git a/Untitled.ipynb b/draft/Untitled.ipynb similarity index 100% rename from Untitled.ipynb rename to draft/Untitled.ipynb diff --git a/Untitled1.ipynb b/draft/Untitled1.ipynb similarity index 100% rename from Untitled1.ipynb rename to draft/Untitled1.ipynb diff --git a/garpar/core/__init__.py b/garpar/core/__init__.py index fb2b0e2..0133e57 100644 --- a/garpar/core/__init__.py +++ b/garpar/core/__init__.py @@ -1 +1,7 @@ -from .portfolio import Portfolio, GARPAR_METADATA_KEY +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE + +from .portfolio import GARPAR_METADATA_KEY, Portfolio diff --git a/garpar/core/_mixins.py b/garpar/core/_mixins.py index 8ac3212..9634d38 100644 --- a/garpar/core/_mixins.py +++ b/garpar/core/_mixins.py @@ -1,3 +1,9 @@ +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE + import numpy as np import pandas as pd diff --git a/garpar/core/covcorr_acc.py b/garpar/core/covcorr_acc.py index b8d943e..d6b8ed2 100644 --- a/garpar/core/covcorr_acc.py +++ b/garpar/core/covcorr_acc.py @@ -1,6 +1,10 @@ -import attr +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE -import numpy as np +import attr from pypfopt import risk_models diff --git a/garpar/core/div_acc.py b/garpar/core/div_acc.py index b3a2c4d..ee1aa76 100644 --- a/garpar/core/div_acc.py +++ b/garpar/core/div_acc.py @@ -1,8 +1,14 @@ +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE + import attr import numpy as np -import scipy.stats +# import scipy.stats from sklearn.decomposition import PCA diff --git a/garpar/core/ereturns_acc.py b/garpar/core/ereturns_acc.py index bd50079..c96a65e 100644 --- a/garpar/core/ereturns_acc.py +++ b/garpar/core/ereturns_acc.py @@ -1,6 +1,12 @@ +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE + import attr -from pypfopt import expected_returns, objective_functions +from pypfopt import expected_returns from ..utils import accabc diff --git a/garpar/core/plot_acc.py b/garpar/core/plot_acc.py index e3bf2b1..6367943 100644 --- a/garpar/core/plot_acc.py +++ b/garpar/core/plot_acc.py @@ -39,7 +39,7 @@ def _ddf(self, returns): def _wdf(self): # proxy to access the dataframe with the weights return self._pf.weights.to_frame(), "Weights" - + def _edf(self): return self._pf.entropy.to_frame(), "Entropy" diff --git a/garpar/core/portfolio.py b/garpar/core/portfolio.py index 1fbc1ed..264f5c4 100644 --- a/garpar/core/portfolio.py +++ b/garpar/core/portfolio.py @@ -17,14 +17,14 @@ from . import ( covcorr_acc, + div_acc, ereturns_acc, plot_acc, prices_acc, risk_acc, utilities_acc, - div_acc, ) -from ..utils import df_temporal_header, Bunch, entropy, scalers +from ..utils import Bunch, df_temporal_header, entropy, scalers # ============================================================================= # CONSTANTS diff --git a/garpar/core/risk_acc.py b/garpar/core/risk_acc.py index 581b9ac..6627d6e 100644 --- a/garpar/core/risk_acc.py +++ b/garpar/core/risk_acc.py @@ -1,13 +1,15 @@ +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE + import attr import numpy as np -import pandas as pd - from pypfopt import expected_returns, objective_functions -import scipy.stats - from . import _mixins from ..utils import accabc diff --git a/garpar/core/utilities_acc.py b/garpar/core/utilities_acc.py index 36e5047..1a8e307 100644 --- a/garpar/core/utilities_acc.py +++ b/garpar/core/utilities_acc.py @@ -1,3 +1,9 @@ +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE + import attr from pypfopt import objective_functions diff --git a/garpar/datasets/__init__.py b/garpar/datasets/__init__.py index 24e086b..d686996 100644 --- a/garpar/datasets/__init__.py +++ b/garpar/datasets/__init__.py @@ -9,15 +9,15 @@ from .base import PortfolioMakerABC, RandomEntropyPortfolioMakerABC from .data import load_MERVAL +from .multisector import MultiSector, make_multisector from .risso import ( RissoLevyStable, RissoNormal, RissoUniform, - make_risso_uniform, - make_risso_normal, make_risso_levy_stable, + make_risso_normal, + make_risso_uniform, ) -from .multisector import MultiSector, make_multisector __all__ = [ "PortfolioMakerABC", diff --git a/garpar/datasets/data/__init__.py b/garpar/datasets/data/__init__.py index 55848a5..3c48688 100644 --- a/garpar/datasets/data/__init__.py +++ b/garpar/datasets/data/__init__.py @@ -1,4 +1,9 @@ -import datetime as dt +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE + import os import pathlib @@ -10,7 +15,9 @@ def load_MERVAL(imputation="ffill", first=None, last=None): - """Argentine stock market prices (MERVAL). Unlisted shares were eliminated.""" + """ + Argentine stock market prices (MERVAL). Unlisted shares were eliminated. + """ df = pd.read_csv(DATA_PATH / "merval.csv", index_col="Days") df.index = pd.to_datetime(df.index) df.sort_index(inplace=True) diff --git a/garpar/datasets/multisector.py b/garpar/datasets/multisector.py index 1bcc9d7..5ae858a 100644 --- a/garpar/datasets/multisector.py +++ b/garpar/datasets/multisector.py @@ -1,11 +1,16 @@ +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE + import numpy as np -import pandas as pd +import pandas as pd from .base import PortfolioMakerABC - from ..core.portfolio import Portfolio -from ..utils import mabc, Bunch, unique_names +from ..utils import Bunch, mabc, unique_names class MultiSector(PortfolioMakerABC): @@ -14,7 +19,7 @@ class MultiSector(PortfolioMakerABC): @makers.validator def _makers_validator(self, attribute, value): if len(value) < 2: - raise ValueError(f"You must provide at least 2 makers") + raise ValueError("You must provide at least 2 makers") for maker_name, maker in value: if not isinstance(maker, PortfolioMakerABC): cls_name = PortfolioMakerABC.__name__ diff --git a/garpar/datasets/risso.py b/garpar/datasets/risso.py index 1c89014..0384622 100644 --- a/garpar/datasets/risso.py +++ b/garpar/datasets/risso.py @@ -180,8 +180,8 @@ def get_value(self, sign, refresher, random): class RissoLevyStable(RissoABC): - alpha = mabc.hparam(default=1.6411, converter=float) - beta = mabc.hparam(default=-0.0126, converter=float) + alpha = mabc.hparam(default=1.6411, converter=float) # shape + beta = mabc.hparam(default=-0.0126, converter=float) # scale mu = mabc.hparam(default=0.0005, converter=float) # loc sigma = mabc.hparam(default=0.005, converter=float) # scale diff --git a/garpar/io.py b/garpar/io.py index 8951092..fa4cb7b 100644 --- a/garpar/io.py +++ b/garpar/io.py @@ -30,7 +30,7 @@ import pandas as pd from . import __version__ as VERSION -from .core import Portfolio, GARPAR_METADATA_KEY +from .core import GARPAR_METADATA_KEY, Portfolio # ============================================================================= # CONSTANTS diff --git a/garpar/utils/entropy.py b/garpar/utils/entropy.py index 21c2644..31c2b68 100644 --- a/garpar/utils/entropy.py +++ b/garpar/utils/entropy.py @@ -1,3 +1,9 @@ +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE + from scipy import stats import warnings diff --git a/garpar/utils/mabc.py b/garpar/utils/mabc.py index d8df543..59363fb 100644 --- a/garpar/utils/mabc.py +++ b/garpar/utils/mabc.py @@ -1,4 +1,8 @@ -"""MABC module.""" +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE import attr diff --git a/garpar/utils/scalers.py b/garpar/utils/scalers.py index e2f4178..6a312b7 100644 --- a/garpar/utils/scalers.py +++ b/garpar/utils/scalers.py @@ -1,3 +1,9 @@ +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE + import numpy as np diff --git a/pyproject.toml b/pyproject.toml index 0c4646d..6f2d489 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [tool.black] -line-length = 79 -target-version = ['py39'] +line-length = 80 +target-version = ['py38', 'py39', 'py310', 'py311'] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 128c089..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -setuptools==69.5.1 -kiwisolver==1.4.5 \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..063299e --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,57 @@ +attrs==23.2.0 +black==24.4.2 +build==1.2.1 +cachetools==5.3.3 +chardet==5.2.0 +clarabel==0.8.1 +click==8.1.7 +colorama==0.4.6 +contourpy==1.2.1 +custom-inherit==2.4.1 +cvxpy==1.5.1 +cycler==0.12.1 +Deprecated==1.2.14 +distlib==0.3.8 +ecos==2.0.13 +filelock==3.14.0 +fonttools==4.52.4 +garpar @ file:///home/divasco/Documents/Tesina/garpar/dist/garpar-0.1-py3-none-any.whl#sha256=9f23544e68e8833ad6f84cb5fa3eb1ea5d538ea1e11a496572bc426ec99d8438 +h5py==3.11.0 +importlib_metadata==7.1.0 +Jinja2==3.1.4 +joblib==1.4.2 +kiwisolver==1.4.5 +MarkupSafe==2.1.5 +matplotlib==3.8.4 +methodtools==0.4.7 +mypy-extensions==1.0.0 +numpy==1.26.4 +osqp==0.6.7 +packaging==24.0 +pandas==2.2.2 +pathspec==0.12.1 +pillow==10.3.0 +platformdirs==4.2.2 +pluggy==1.5.0 +PuLP==2.8.0 +pyparsing==3.1.2 +pyportfolioopt==1.5.5 +pyproject-api==1.6.1 +pyproject_hooks==1.1.0 +python-dateutil==2.9.0.post0 +pytz==2024.1 +qdldl==0.1.7.post2 +scikit-criteria==0.8.7 +scikit-learn==1.3.2 +scipy==1.13.1 +scs==3.2.4.post1 +seaborn==0.13.2 +setuptools==69.5.1 +six==1.16.0 +threadpoolctl==3.5.0 +tox==4.15.0 +tzdata==2024.1 +virtualenv==20.26.2 +wirerope==0.4.7 +wrapt==1.16.0 +zipp==3.19.0 diff --git a/setup.py b/setup.py index 9fcb42b..6143d5d 100644 --- a/setup.py +++ b/setup.py @@ -16,33 +16,66 @@ # CONSTANTS # ============================================================================= +# TODO Separar en dev y release REQUIREMENTS = [ - "attrs", - "custom_inherit", - "cvxpy", - "cycler", - "deprecated", - "distutils", - "h5py", - "joblib", - "kiwisolver", - "matplotlib", - "numpy < 2", - "pandas", - "pulp", - "pyparsing", - "PyPortfolioOpt", - "python-dateutil", - "pytz", - "scikit-criteria", - "scikit-learn", - "scipy", - "seaborn", - "wirerope", - "wrapt", - "zipp", + "attrs==23.2.0", + "build==1.2.1", + "clarabel==0.8.1", + "contourpy==1.2.1", + "custom-inherit==2.4.1", + "cvxpy==1.5.1", + "cycler==0.12.1", + "Deprecated==1.2.14", + "ecos==2.0.13", + "fonttools==4.52.4", + "h5py==3.11.0", + "importlib_metadata==7.1.0", + "Jinja2==3.1.4", + "joblib==1.4.2", + "kiwisolver==1.4.5", + "MarkupSafe==2.1.5", + "matplotlib==3.8.4", + "methodtools==0.4.7", + "numpy==1.26.4", + "osqp==0.6.7", + "packaging==24.0", + "pandas==2.2.2", + "pillow==10.3.0", + "PuLP==2.8.0", + "pyparsing==3.1.2", + "pyportfolioopt==1.5.5", + "pyproject_hooks==1.1.0", + "python-dateutil==2.9.0.post0", + "pytz==2024.1", + "qdldl==0.1.7.post2", + "scikit-criteria==0.8.7", + "scikit-learn==1.3.2", + "scipy==1.13.1", + "scs==3.2.4.post1", + "seaborn==0.13.2", + "setuptools==69.5.1", + "six==1.16.0", + "threadpoolctl==3.5.0", + "tox==4.15.0", + "tzdata==2024.1", + "wirerope==0.4.7", + "wrapt==1.16.0", + "zipp==3.19.0", ] +# TODO ordenar +# REQUIREMENTS = [ +# "numpy", +# "pandas", +# "scipy", +# "seaborn", +# "matplotlib", +# "h5py", +# "joblib", +# "PyPortfolioOpt", +# "scikit-criteria", +# "attrs", +# ] with open("README.md", "r") as fp: LONG_DESCRIPTION = fp.read() diff --git a/tests/core/test_plot_acc.py b/tests/core/test_plot_acc.py new file mode 100644 index 0000000..7151c2a --- /dev/null +++ b/tests/core/test_plot_acc.py @@ -0,0 +1,7 @@ +# This file is part of the +# Garpar Project (https://github.com/quatrope/garpar). +# Copyright (c) 2021, 2022, 2023, 2024, Diego Gimenez, Nadia Luczywo, Juan Cabral and QuatroPe +# License: MIT +# Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE + +# TODO TESTEAR \ No newline at end of file diff --git a/tests/datasets/test_risso.py b/tests/datasets/test_risso.py index 69e3850..63a02f9 100644 --- a/tests/datasets/test_risso.py +++ b/tests/datasets/test_risso.py @@ -115,5 +115,5 @@ def test_make_risso_levy_stable(): weights=[1, 1], ) - pd.testing.assert_frame_equal(result.as_prices(), expected.as_prices()) + pd.testing.assert_frame_equal(result.as_prices(), expected.as_prices(), check_exact=False, atol=.01, rtol=.01) pd.testing.assert_series_equal(result.weights, expected.weights) diff --git a/tox.ini b/tox.ini index 606cb31..b6627ec 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ envlist = py39, py310, py311, - coverage + coverage, # ============================================================================= @@ -22,6 +22,7 @@ usedevelop = False deps = flake8 flake8-import-order flake8-black + #flake8-builtins commands = flake8 setup.py garpar/ tests/ {posargs} @@ -61,6 +62,7 @@ deps = pytest commands = pytest tests/ {posargs} + [testenv:coverage] usedevelop = True deps = @@ -68,7 +70,7 @@ deps = coverage pytest-cov commands = - - coverage erase + - coverage erase # - => Segui en el que sigue pytest -v tests/ --cov garpar --cov-fail-under 80 --cov-report term-missing diff --git a/updateHeaders.py b/updateHeaders.py deleted file mode 100644 index af2ed76..0000000 --- a/updateHeaders.py +++ /dev/null @@ -1,40 +0,0 @@ -import os - -header_template = """ -This file is part of the - Garpar Project (https://github.com/quatrope/garpar). -Copyright (c) 2021, 2022, Nadia Luczywo, Juan Cabral and QuatroPe -License: MIT - Full Text: https://github.com/quatrope/garpar/blob/master/LICENSE -""" - -# Lista de archivos con encabezados incorrectos -files_to_update = [ - 'garpar/utils/mabc.py', - 'garpar/utils/scalers.py', - 'garpar/utils/entropy.py', - 'garpar/core/utilities_acc.py', - 'garpar/core/risk_acc.py', - 'garpar/core/__init__.py', - 'garpar/core/_mixins.py', - 'garpar/core/div_acc.py', - 'garpar/core/covcorr_acc.py', - 'garpar/core/ereturns_acc.py', - 'garpar/datasets/multisector.py', - 'garpar/datasets/data/__init__.py', -] - -for file_path in files_to_update: - with open(file_path, 'r') as file: - content = file.readlines() - - # Remove old header - content = [line for line in content if not line.startswith('"""')] - - # Add new header - new_content = [header_template] + content - - with open(file_path, 'w') as file: - file.writelines(new_content) - -print("Headers updated successfully.") \ No newline at end of file