portfolio-backtest is a python library for backtest portfolio asset allocation on Python 3.7 and above.
Project description
portfolio-backtest
portfolio-backtest is a python library for backtest portfolio asset allocation on Python 3.7 and above.
Installation
$ pip install portfolio-backtest
$ pip install PyPortfolioOpt
Usage
basic run
from portfolio_backtest import Backtest
Backtest(tickers=["VTI", "AGG", "GLD"]).run()
advanced run
from portfolio_backtest import Backtest
import pprint
bt = Backtest(
tickers={
"VTI": 0.6,
"AGG": 0.25,
"GLD": 0.15,
},
target_return=0.1,
target_cvar=0.025,
data_dir="data",
start="2011-04-10",
end="2021-04-10",
)
pprint.pprint(bt.run(plot=True))
[{'Annual volatility': '10.9%',
'Conditional Value at Risk': '',
'Cumulative Return': '160.9%',
'Expected annual return': '9.6%',
'Sharpe Ratio': '0.70',
'portfolio': 'Your Portfolio',
'tickers': {'AGG': 0.25, 'GLD': 0.15, 'VTI': 0.6}},
{'Annual volatility': '6.3%',
'Conditional Value at Risk': '',
'Cumulative Return': '102.3%',
'Expected annual return': '7.0%',
'Sharpe Ratio': '0.79',
'portfolio': 'Tangency Portfolio',
'tickers': {'AGG': 0.67099, 'GLD': 0.0, 'VTI': 0.32901}},
{'Annual volatility': '4.3%',
'Conditional Value at Risk': '',
'Cumulative Return': '53.3%',
'Expected annual return': '4.3%',
'Sharpe Ratio': '0.53',
'portfolio': 'Minimum Variance Portfolio',
'tickers': {'AGG': 0.91939, 'GLD': 0.00525, 'VTI': 0.07536}},
{'Annual volatility': '4.0%',
'Conditional Value at Risk': '',
'Cumulative Return': '48.7%',
'Expected annual return': '4.1%',
'Sharpe Ratio': '0.51',
'portfolio': 'Hierarchical Risk Parity Portfolio',
'tickers': {'AGG': 0.89041, 'GLD': 0.05695, 'VTI': 0.05263}},
{'Annual volatility': '',
'Conditional Value at Risk': '0.5%',
'Cumulative Return': '52.1%',
'Expected annual return': '4.2%',
'Sharpe Ratio': '',
'portfolio': 'Minimum CVaR Portfolio',
'tickers': {'AGG': 0.93215, 'GLD': 0.0, 'VTI': 0.06785}},
{'Annual volatility': '7.7%',
'Conditional Value at Risk': '',
'Cumulative Return': '166.5%',
'Expected annual return': '10.0%',
'Sharpe Ratio': '1.04',
'portfolio': 'Semi Variance Portfolio (target return 10.0%)',
'tickers': {'AGG': 0.39504, 'GLD': 0.0, 'VTI': 0.60496}},
{'Annual volatility': '',
'Conditional Value at Risk': '2.5%',
'Cumulative Return': '251.3%',
'Expected annual return': '13.3%',
'Sharpe Ratio': '',
'portfolio': 'Return Maximize CVaR Portfolio (target CVaR 2.5%)',
'tickers': {'AGG': 0.08851, 'GLD': 0.0, 'VTI': 0.91149}}]
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)
from portfolio_backtest import Backtest
bt = Backtest(
tickers={
"VTI": 0.6,
"AGG": 0.25,
"GLD": 0.15,
}
)
print(bt.discrete_allocation(total_portfolio_value=10000))
{'Discrete allocation': {'VTI': 28, 'AGG': 21, 'GLD': 9}, 'Funds remaining': '$109.45'}
Supported Portfolio
- Your Portfolio
- Hierarchical Risk Parity Portfolio
- Tangency Portfolio
- Minimum Variance Portfolio
- Minimum CVaR Portfolio
- Semi Variance Portfolio
- Return Maximize CVaR Portfolio
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file portfolio-backtest-0.3.0.tar.gz
.
File metadata
- Download URL: portfolio-backtest-0.3.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa68ea5afdae5ee1db0167b31733e21608978d25c8142412001433003f78a57a |
|
MD5 | 1d9e71084e50c62644fa7e919966ae2e |
|
BLAKE2b-256 | 9562b7d21af2f05bd5a31d4702c497d485950c9edd62f13fa0a98169d9e6e1ab |
File details
Details for the file portfolio_backtest-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: portfolio_backtest-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f326fc7364d0aba475a481f417e9d68692d1c0ea80bb2c2963bc8a3fbe17a301 |
|
MD5 | 138c64f89c1ae27e285b129383732eba |
|
BLAKE2b-256 | a5e28ba876c7438572647808434a290c6eda48acebe39428689da257d28633ca |