{"id":24496840,"url":"https://github.com/10mohi6/portfolio-backtest-python","last_synced_at":"2025-04-14T04:14:21.051Z","repository":{"id":57454228,"uuid":"357555512","full_name":"10mohi6/portfolio-backtest-python","owner":"10mohi6","description":"portfolio-backtest is a python library for backtest portfolio asset allocation on Python 3.7 and above.","archived":false,"fork":false,"pushed_at":"2021-04-21T02:39:24.000Z","size":1153,"stargazers_count":28,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T04:14:15.241Z","etag":null,"topics":["asset-allocation","backtest","cvar","etf","hrp","minimum","mutual-fund","portfolio","python","stock","tangency","variance"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/10mohi6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-13T13:03:05.000Z","updated_at":"2025-01-31T02:36:51.000Z","dependencies_parsed_at":"2022-09-04T18:22:18.683Z","dependency_job_id":null,"html_url":"https://github.com/10mohi6/portfolio-backtest-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fportfolio-backtest-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fportfolio-backtest-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fportfolio-backtest-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/10mohi6%2Fportfolio-backtest-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/10mohi6","download_url":"https://codeload.github.com/10mohi6/portfolio-backtest-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819408,"owners_count":21166477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asset-allocation","backtest","cvar","etf","hrp","minimum","mutual-fund","portfolio","python","stock","tangency","variance"],"created_at":"2025-01-21T21:19:04.861Z","updated_at":"2025-04-14T04:14:21.029Z","avatar_url":"https://github.com/10mohi6.png","language":"Python","readme":"# portfolio-backtest\n\n[![PyPI](https://img.shields.io/pypi/v/portfolio-backtest)](https://pypi.org/project/portfolio-backtest/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![codecov](https://codecov.io/gh/10mohi6/portfolio-backtest-python/branch/main/graph/badge.svg?token=EYDOX015ZS)](https://codecov.io/gh/10mohi6/portfolio-backtest-python)\n[![Build Status](https://travis-ci.com/10mohi6/portfolio-backtest-python.svg?branch=main)](https://travis-ci.com/10mohi6/portfolio-backtest-python)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/portfolio-backtest)](https://pypi.org/project/portfolio-backtest/)\n[![Downloads](https://pepy.tech/badge/portfolio-backtest)](https://pepy.tech/project/portfolio-backtest)\n\nportfolio-backtest is a python library for backtest portfolio asset allocation on Python 3.7 and above.\n\n## Installation\n\n    $ pip install portfolio-backtest\n    $ pip install PyPortfolioOpt\n\n## Usage\n\n### basic run\n```python\nfrom portfolio_backtest import Backtest\n\nBacktest(tickers=[\"VTI\", \"AGG\", \"GLD\"]).run()\n```\n![tangency-portfolio.png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/tangency-portfolio.png)\n![minimum-variance-portfolio.png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/minimum-variance-portfolio.png)\n![hierarchical-risk-parity-portfolio.png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/hierarchical-risk-parity-portfolio.png)\n![minimum-cvar-portfolio.png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/minimum-cvar-portfolio.png)\n![cumulative-return.png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/cumulative-return.png)\n\n### advanced run\n```python\nfrom portfolio_backtest import Backtest\nimport pprint\n\nbt = Backtest(\n    tickers={\n        \"VTI\": 0.6,\n        \"AGG\": 0.25,\n        \"GLD\": 0.15,\n    },\n    target_return=0.1,\n    target_cvar=0.025,\n    data_dir=\"data\",\n    start=\"2011-04-10\",\n    end=\"2021-04-10\",\n)\npprint.pprint(bt.run(plot=True))\n```\n```python\n[{'Annual volatility': '10.9%',\n  'Conditional Value at Risk': '',\n  'Cumulative Return': '160.9%',\n  'Expected annual return': '9.6%',\n  'Sharpe Ratio': '0.70',\n  'portfolio': 'Your Portfolio',\n  'tickers': {'AGG': 0.25, 'GLD': 0.15, 'VTI': 0.6}},\n {'Annual volatility': '6.3%',\n  'Conditional Value at Risk': '',\n  'Cumulative Return': '102.3%',\n  'Expected annual return': '7.0%',\n  'Sharpe Ratio': '0.79',\n  'portfolio': 'Tangency Portfolio',\n  'tickers': {'AGG': 0.67099, 'GLD': 0.0, 'VTI': 0.32901}},\n {'Annual volatility': '4.3%',\n  'Conditional Value at Risk': '',\n  'Cumulative Return': '53.3%',\n  'Expected annual return': '4.3%',\n  'Sharpe Ratio': '0.53',\n  'portfolio': 'Minimum Variance Portfolio',\n  'tickers': {'AGG': 0.91939, 'GLD': 0.00525, 'VTI': 0.07536}},\n {'Annual volatility': '4.0%',\n  'Conditional Value at Risk': '',\n  'Cumulative Return': '48.7%',\n  'Expected annual return': '4.1%',\n  'Sharpe Ratio': '0.51',\n  'portfolio': 'Hierarchical Risk Parity Portfolio',\n  'tickers': {'AGG': 0.89041, 'GLD': 0.05695, 'VTI': 0.05263}},\n {'Annual volatility': '',\n  'Conditional Value at Risk': '0.5%',\n  'Cumulative Return': '52.1%',\n  'Expected annual return': '4.2%',\n  'Sharpe Ratio': '',\n  'portfolio': 'Minimum CVaR Portfolio',\n  'tickers': {'AGG': 0.93215, 'GLD': 0.0, 'VTI': 0.06785}},\n {'Annual volatility': '7.7%',\n  'Conditional Value at Risk': '',\n  'Cumulative Return': '166.5%',\n  'Expected annual return': '10.0%',\n  'Sharpe Ratio': '1.04',\n  'portfolio': 'Semi Variance Portfolio (target return 10.0%)',\n  'tickers': {'AGG': 0.39504, 'GLD': 0.0, 'VTI': 0.60496}},\n {'Annual volatility': '',\n  'Conditional Value at Risk': '2.5%',\n  'Cumulative Return': '251.3%',\n  'Expected annual return': '13.3%',\n  'Sharpe Ratio': '',\n  'portfolio': 'Return Maximize CVaR Portfolio (target CVaR 2.5%)',\n  'tickers': {'AGG': 0.08851, 'GLD': 0.0, 'VTI': 0.91149}}]\n```\n![advanced-your-portfolio.png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/advanced-your-portfolio.png)\n![advanced-tangency-portfolio.png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/advanced-tangency-portfolio.png)\n![advanced-minimum-variance-portfolio.png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/advanced-minimum-variance-portfolio.png)\n![advanced-hierarchical-risk-parity-portfolio.png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/advanced-hierarchical-risk-parity-portfolio.png)\n![advanced-minimum-cvar-portfolio.png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/advanced-minimum-cvar-portfolio.png)\n![advanced-return-maximize-cvar-portfolio-(target-cvar-2.5%).png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/advanced-return-maximize-cvar-portfolio-(target-cvar-2.5%25).png)\n![advanced-semi-variance-portfolio-(target-return-10.0%).png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/advanced-semi-variance-portfolio-(target-return-10.0%25).png)\n![advanced-cumulative-return.png](https://raw.githubusercontent.com/10mohi6/portfolio-backtest-python/main/tests/advanced-cumulative-return.png)\n\n### Provides a method (discrete_allocation) that can be converted into an actual allocation available for purchase by entering the latest price and desired portfolio size ($ 10,000 in this example)\n```python\nfrom portfolio_backtest import Backtest\n\nbt = Backtest(\n    tickers={\n        \"VTI\": 0.6,\n        \"AGG\": 0.25,\n        \"GLD\": 0.15,\n    }\n)\nprint(bt.discrete_allocation(total_portfolio_value=10000))\n```\n```python\n{'Discrete allocation': {'VTI': 28, 'AGG': 21, 'GLD': 9}, 'Funds remaining': '$109.45'}\n```\n\n## Supported Portfolio\n- Your Portfolio\n- Hierarchical Risk Parity Portfolio\n- Tangency Portfolio\n- Minimum Variance Portfolio\n- Minimum CVaR Portfolio\n- Semi Variance Portfolio\n- Return Maximize CVaR Portfolio\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10mohi6%2Fportfolio-backtest-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F10mohi6%2Fportfolio-backtest-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F10mohi6%2Fportfolio-backtest-python/lists"}