Name | portfolio-optimizer0 JSON |
Version |
0.3.2
JSON |
| download |
home_page | |
Summary | A library for Portfolio management and optimization |
upload_time | 2023-02-04 05:44:31 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.7 |
license | MIT License Copyright (c) 2023 Shailja Kant Tiwari Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
optimizer
portfolio
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# portfolio_optimizer
[![PyPI version](https://badge.fury.io/py/portfolio-optimizer0.svg)](https://badge.fury.io/py/portfolio-optimizer0)
[![Downloads](https://static.pepy.tech/personalized-badge/portfolio-optimizer0?period=total&units=none&left_color=grey&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/portfolio-optimizer0)
<!-- [![Downloads](https://static.pepy.tech/badge/portfolio-optimizer0)](https://pepy.tech/project/portfolio-optimizer0) -->
A small python library for analysis of historical data of stocks. Especially for portfolio management and optimization.
## Installation
```bash
pip install portfolio-optimizer0
```
> Note: The library is still in development, so the version number is 0. You will need to call `pip install portfolio-optimizer0` to install the library. However, you can import the library as `import portfolio_optimizer`.
After installation, you can import the library as follows:
```python
import portfolio_optimizer as po
```
## Usage
The end goal of the library is to provide a simple interface for portfolio management and optimization. The library is still in development, so the interface is not yet stable. The following example shows how to use the library to optimize a portfolio of stocks.
```python
from po.load_data import LoadData # for loading data
from po.portfolio import Portfolio # for portfolio management
from po.optimizer import Optimizer # for optimization purpose
from po.frontier import EfficientFrontier # for the plot of Efficient Frontier
# loading the data from NSE exchange you can use BSE also
ld = LoadData()
data_dic = ld.load_data(['HDFCBANK', 'RELIANCE', 'INFY', 'BAJAJ-AUTO', 'TATAMOTORS'], 'NSE')
# loading the benchmark separately, Indices are always downloaded from nasdaq
benchmark = ld.load_data(['^NSEI'], 'nasdaq')
# Creating a Portfolio object, with the freq="M" and benchmark as NSEI (Nifty 50)
portfolio = Portfolio(freq="M", benchmark=benchmark)
# Adding the stocks to the portfolio
portfolio.add_stock(data_dic)
# You can view you Portfolio summary also by
portfolio.portfolio_summary()
```
```output
Portfolio Summary
*****************
Stocks in the Portfolio : *************************
{"['HDFCBANK', 'RELIANCE', 'INFY', 'BAJAJ-AUTO', 'TATAMOTORS']"}
Beta :
******
| | HDFCBANK | RELIANCE | INFY | BAJAJ-AUTO | TATAMOTORS |
|------+------------+------------+----------+--------------+--------------|
| beta | 1.00174 | 1.04458 | 0.543611 | 1.01237 | 1.59273 |
Expected Returns :
******************
| | HDFCBANK | RELIANCE | INFY | BAJAJ-AUTO | TATAMOTORS |
|----+------------+------------+----------+--------------+--------------|
| 0 | 1.05617 | 1.09172 | 0.676051 | 1.065 | 1.54654 |
The covariance matrix is as follows
***********************************
| | HDFCBANK | RELIANCE | INFY | BAJAJ-AUTO | TATAMOTORS |
|------------+------------+------------+------------+--------------+--------------|
| HDFCBANK | 0.00565169 | 0.00383894 | 0.00144691 | 0.00458971 | 0.00610401 |
| RELIANCE | 0.00383894 | 0.00795272 | 0.00227559 | 0.00466296 | 0.0060295 |
| INFY | 0.00144691 | 0.00227559 | 0.00679807 | 0.00154204 | 0.00296804 |
| BAJAJ-AUTO | 0.00458971 | 0.00466296 | 0.00154204 | 0.0110113 | 0.00849118 |
| TATAMOTORS | 0.00610401 | 0.0060295 | 0.00296804 | 0.00849118 | 0.0228973 |
Portfolio Returns at equals weights: 1.0870947316063777
Portfolio Risk at equals weights: 0.5528354886819963
```
```python
# Creating a Optimizer object and adding the portfolio
model = Optimizer()
model.add_portfolio(portfolio=portfolio)
# Optimizing the portfolio using CAPM
risk = 1
model_ = "capm"
optimized_res = model.optimize_portfolio(model=model, max_risk=risk)
print(optimized_res)
```
```output
Optimized successfully.
Expected Portfolio's Returns : 1.1792
Risk : 0.8001
Expected weights:
--------------------
['HDFCBANK']: 47.44%
['RELIANCE']: 29.62%
['INFY']: 0.00%
['BAJAJ-AUTO']: 0.00%
['TATAMOTORS']: 22.94%
```
## More Examples
For more detailed go through of the library, please refer to the notebook [Walk through portfolio_optimizer](https://github.com/SKT27182/portfolio_optimizer/blob/main/go_through_portfolio_optimizer.ipynb)
## Documentation
The documentation is available at [Documentation](https://SKT27182.github.io/portfolio_optimizer/)
Raw data
{
"_id": null,
"home_page": "",
"name": "portfolio-optimizer0",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "optimizer,portfolio",
"author": "",
"author_email": "Shailja Kant Tiwari <shailjakant2000@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/9d/ba/7de47eee4b1d8938767baaa833cacf57c86a27d4baa6ce498eb0bea2d354/portfolio_optimizer0-0.3.2.tar.gz",
"platform": null,
"description": "# portfolio_optimizer\n\n[![PyPI version](https://badge.fury.io/py/portfolio-optimizer0.svg)](https://badge.fury.io/py/portfolio-optimizer0)\n[![Downloads](https://static.pepy.tech/personalized-badge/portfolio-optimizer0?period=total&units=none&left_color=grey&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/portfolio-optimizer0)\n<!-- [![Downloads](https://static.pepy.tech/badge/portfolio-optimizer0)](https://pepy.tech/project/portfolio-optimizer0) -->\n\n\n\n\nA small python library for analysis of historical data of stocks. Especially for portfolio management and optimization.\n\n## Installation\n\n```bash\npip install portfolio-optimizer0\n```\n\n> Note: The library is still in development, so the version number is 0. You will need to call `pip install portfolio-optimizer0` to install the library. However, you can import the library as `import portfolio_optimizer`.\n\nAfter installation, you can import the library as follows:\n\n```python\nimport portfolio_optimizer as po\n```\n\n## Usage\n\nThe end goal of the library is to provide a simple interface for portfolio management and optimization. The library is still in development, so the interface is not yet stable. The following example shows how to use the library to optimize a portfolio of stocks.\n\n```python\nfrom po.load_data import LoadData # for loading data\nfrom po.portfolio import Portfolio # for portfolio management\nfrom po.optimizer import Optimizer # for optimization purpose\nfrom po.frontier import EfficientFrontier # for the plot of Efficient Frontier\n\n# loading the data from NSE exchange you can use BSE also\nld = LoadData()\ndata_dic = ld.load_data(['HDFCBANK', 'RELIANCE', 'INFY', 'BAJAJ-AUTO', 'TATAMOTORS'], 'NSE')\n\n# loading the benchmark separately, Indices are always downloaded from nasdaq\nbenchmark = ld.load_data(['^NSEI'], 'nasdaq')\n\n# Creating a Portfolio object, with the freq=\"M\" and benchmark as NSEI (Nifty 50)\nportfolio = Portfolio(freq=\"M\", benchmark=benchmark)\n\n\n# Adding the stocks to the portfolio\nportfolio.add_stock(data_dic)\n\n# You can view you Portfolio summary also by\nportfolio.portfolio_summary()\n```\n \n```output\nPortfolio Summary\n*****************\n\nStocks in the Portfolio : *************************\n{\"['HDFCBANK', 'RELIANCE', 'INFY', 'BAJAJ-AUTO', 'TATAMOTORS']\"}\n\nBeta :\n******\n| | HDFCBANK | RELIANCE | INFY | BAJAJ-AUTO | TATAMOTORS |\n|------+------------+------------+----------+--------------+--------------|\n| beta | 1.00174 | 1.04458 | 0.543611 | 1.01237 | 1.59273 |\n\nExpected Returns :\n******************\n| | HDFCBANK | RELIANCE | INFY | BAJAJ-AUTO | TATAMOTORS |\n|----+------------+------------+----------+--------------+--------------|\n| 0 | 1.05617 | 1.09172 | 0.676051 | 1.065 | 1.54654 |\n\nThe covariance matrix is as follows\n***********************************\n| | HDFCBANK | RELIANCE | INFY | BAJAJ-AUTO | TATAMOTORS |\n|------------+------------+------------+------------+--------------+--------------|\n| HDFCBANK | 0.00565169 | 0.00383894 | 0.00144691 | 0.00458971 | 0.00610401 |\n| RELIANCE | 0.00383894 | 0.00795272 | 0.00227559 | 0.00466296 | 0.0060295 |\n| INFY | 0.00144691 | 0.00227559 | 0.00679807 | 0.00154204 | 0.00296804 |\n| BAJAJ-AUTO | 0.00458971 | 0.00466296 | 0.00154204 | 0.0110113 | 0.00849118 |\n| TATAMOTORS | 0.00610401 | 0.0060295 | 0.00296804 | 0.00849118 | 0.0228973 |\n\nPortfolio Returns at equals weights: 1.0870947316063777\nPortfolio Risk at equals weights: 0.5528354886819963\n```\n\n```python\n# Creating a Optimizer object and adding the portfolio\nmodel = Optimizer()\nmodel.add_portfolio(portfolio=portfolio)\n\n# Optimizing the portfolio using CAPM\nrisk = 1\nmodel_ = \"capm\"\noptimized_res = model.optimize_portfolio(model=model, max_risk=risk)\nprint(optimized_res)\n```\n\n```output\nOptimized successfully.\nExpected Portfolio's Returns : 1.1792\nRisk : 0.8001\nExpected weights:\n--------------------\n['HDFCBANK']: 47.44%\n['RELIANCE']: 29.62%\n['INFY']: 0.00%\n['BAJAJ-AUTO']: 0.00%\n['TATAMOTORS']: 22.94%\n```\n\n## More Examples\n\nFor more detailed go through of the library, please refer to the notebook [Walk through portfolio_optimizer](https://github.com/SKT27182/portfolio_optimizer/blob/main/go_through_portfolio_optimizer.ipynb)\n\n## Documentation\n\nThe documentation is available at [Documentation](https://SKT27182.github.io/portfolio_optimizer/)\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2023 Shailja Kant Tiwari Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "A library for Portfolio management and optimization",
"version": "0.3.2",
"split_keywords": [
"optimizer",
"portfolio"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "df86b838978d39ba649993623058ede52e4efe297e8a9c1df9f2248203dd30c6",
"md5": "e0f12d2321cba4387403652d3baf1f8d",
"sha256": "f18fe21914ff47d5024d6af5944d331110ac34cff5a651f8fc2f0f043962511e"
},
"downloads": -1,
"filename": "portfolio_optimizer0-0.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e0f12d2321cba4387403652d3baf1f8d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 15844,
"upload_time": "2023-02-04T05:44:18",
"upload_time_iso_8601": "2023-02-04T05:44:18.170013Z",
"url": "https://files.pythonhosted.org/packages/df/86/b838978d39ba649993623058ede52e4efe297e8a9c1df9f2248203dd30c6/portfolio_optimizer0-0.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9dba7de47eee4b1d8938767baaa833cacf57c86a27d4baa6ce498eb0bea2d354",
"md5": "c59aa160bd8ad742d4942863fbb86e34",
"sha256": "67e67f2e61858cdbacebf3cb0f9910444e00512979ed85389ba7a5e6de9b1165"
},
"downloads": -1,
"filename": "portfolio_optimizer0-0.3.2.tar.gz",
"has_sig": false,
"md5_digest": "c59aa160bd8ad742d4942863fbb86e34",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 4214099,
"upload_time": "2023-02-04T05:44:31",
"upload_time_iso_8601": "2023-02-04T05:44:31.494191Z",
"url": "https://files.pythonhosted.org/packages/9d/ba/7de47eee4b1d8938767baaa833cacf57c86a27d4baa6ce498eb0bea2d354/portfolio_optimizer0-0.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-04 05:44:31",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "portfolio-optimizer0"
}