pystock0


Namepystock0 JSON
Version 0.3.0 PyPI version JSON
download
home_page
SummaryA library for portfolio optimization
upload_time2023-03-15 10:24:12
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT License Copyright (c) 2023 Harikesh Kushwaha 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 optimization portfolio stock
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pystock

[![PyPI version](https://badge.fury.io/py/pystock0.svg)](https://badge.fury.io/py/pystock0)
[![Downloads](https://static.pepy.tech/personalized-badge/pystock0?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/pystock0)
![example event parameter](https://github.com/hari31416/pystock/actions/workflows/python-package.yml/badge.svg?event=push)

A small python library for stock market analysis. Especially for portfolio optimization.

## Installation

```bash
pip install pystock0
```

> Note: You will need to call `pip install pystock0` to install the library. However, you can import the library as `import pystock`. The library is still in development, so, a lot of changes will be made to the code.

After installation, you can import the library as follows:

```python
import pystock
```

## Usage

The end goal of the library is to provide a simple interface for portfolio optimization. The library is still in development, so the interface is not yet stable. For now, this is how you can use the library to optimize a portfolio of stocks.

```python
from pystock.portfolio import Portfolio
from pystock.models import Model

# Creating the benchmark and stocks
benchmark_dir = "Data/GSPC.csv"
benchmark_name = "S&P"

stock_dirs = ["Data/AAPL.csv", "Data/MSFT.csv", "Data/GOOGL.csv", "Data/TSLA.csv"]
stock_names = ["AAPL", "MSFT", "GOOGL", "TSLA"]

# Setting the frequency to monthly
frequency = "M"

# Creating a Portfolio object
pt = Portfolio(benchmark_dir, benchmark_name, stock_dirs, stock_names)
start_date = "2012-01-01"
end_date = "2022-12-20"

# Loading the data
pt.load_benchmark(
    columns=["Close"],
    start_date=start_date,
    end_date=end_date,
    frequency=frequency,
)
pt.load_all(
    columns=["Close"],
    start_date=start_date,
    end_date=end_date,
    frequency=frequency,
)

# Creating a Model object and adding the portfolio
model = Model(frequency=frequency, risk_free_rate=0.33)
model.add_portfolio(pt, weights="equal")

# Optimizing the portfolio using CAPM
risk = 0.5
model_ = "capm"
res = model.optimize_portfolio(risk=risk, model=model_)
print(res)

```

```output
Optimized successfully.

Expected return: 1.1159%
Risk:            0.5000%
Expected weights:
--------------------
AAPL      :  47.40%
MSFT      :   0.00%
GOOGL     :  35.83%
TSLA      :  16.77%

{'weights': array([0.474 , 0.    , 0.3583, 0.1677]), 'expected_return': 1.115892062822632, 'variance': 0.5000278422222152, 'std': 0.707126468336616}
```

## More Examples

For more examples, please refer to the notebook [Working_With_pystock.ipynb](https://github.com/Hari31416/pystock/blob/main/Working_With_pystock.ipynb). Also have a look at [Downloading_Data.ipynb](https://github.com/Hari31416/pystock/blob/main/Downloading_Data.ipynb). Please also have a look at [Working_With_frontier.ipynb](https://github.com/Hari31416/pystock/blob/main/Working_With_frontier.ipynb) to see how to use the `frontier` module to plot efficient frontiers.

## Documentation

The documentation is available at [https://hari31416.github.io/pystock/](https://hari31416.github.io/pystock/).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pystock0",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "optimization,portfolio,stock",
    "author": "",
    "author_email": "Harikesh Kushwaha <harikeshkumar0926@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/1a/0e/db3dce245a1fc2b596f5572c8c62f8f0cda3ddfe86eaf454002f9757eb07/pystock0-0.3.0.tar.gz",
    "platform": null,
    "description": "# pystock\n\n[![PyPI version](https://badge.fury.io/py/pystock0.svg)](https://badge.fury.io/py/pystock0)\n[![Downloads](https://static.pepy.tech/personalized-badge/pystock0?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/pystock0)\n![example event parameter](https://github.com/hari31416/pystock/actions/workflows/python-package.yml/badge.svg?event=push)\n\nA small python library for stock market analysis. Especially for portfolio optimization.\n\n## Installation\n\n```bash\npip install pystock0\n```\n\n> Note: You will need to call `pip install pystock0` to install the library. However, you can import the library as `import pystock`. The library is still in development, so, a lot of changes will be made to the code.\n\nAfter installation, you can import the library as follows:\n\n```python\nimport pystock\n```\n\n## Usage\n\nThe end goal of the library is to provide a simple interface for portfolio optimization. The library is still in development, so the interface is not yet stable. For now, this is how you can use the library to optimize a portfolio of stocks.\n\n```python\nfrom pystock.portfolio import Portfolio\nfrom pystock.models import Model\n\n# Creating the benchmark and stocks\nbenchmark_dir = \"Data/GSPC.csv\"\nbenchmark_name = \"S&P\"\n\nstock_dirs = [\"Data/AAPL.csv\", \"Data/MSFT.csv\", \"Data/GOOGL.csv\", \"Data/TSLA.csv\"]\nstock_names = [\"AAPL\", \"MSFT\", \"GOOGL\", \"TSLA\"]\n\n# Setting the frequency to monthly\nfrequency = \"M\"\n\n# Creating a Portfolio object\npt = Portfolio(benchmark_dir, benchmark_name, stock_dirs, stock_names)\nstart_date = \"2012-01-01\"\nend_date = \"2022-12-20\"\n\n# Loading the data\npt.load_benchmark(\n    columns=[\"Close\"],\n    start_date=start_date,\n    end_date=end_date,\n    frequency=frequency,\n)\npt.load_all(\n    columns=[\"Close\"],\n    start_date=start_date,\n    end_date=end_date,\n    frequency=frequency,\n)\n\n# Creating a Model object and adding the portfolio\nmodel = Model(frequency=frequency, risk_free_rate=0.33)\nmodel.add_portfolio(pt, weights=\"equal\")\n\n# Optimizing the portfolio using CAPM\nrisk = 0.5\nmodel_ = \"capm\"\nres = model.optimize_portfolio(risk=risk, model=model_)\nprint(res)\n\n```\n\n```output\nOptimized successfully.\n\nExpected return: 1.1159%\nRisk:            0.5000%\nExpected weights:\n--------------------\nAAPL      :  47.40%\nMSFT      :   0.00%\nGOOGL     :  35.83%\nTSLA      :  16.77%\n\n{'weights': array([0.474 , 0.    , 0.3583, 0.1677]), 'expected_return': 1.115892062822632, 'variance': 0.5000278422222152, 'std': 0.707126468336616}\n```\n\n## More Examples\n\nFor more examples, please refer to the notebook [Working_With_pystock.ipynb](https://github.com/Hari31416/pystock/blob/main/Working_With_pystock.ipynb). Also have a look at [Downloading_Data.ipynb](https://github.com/Hari31416/pystock/blob/main/Downloading_Data.ipynb). Please also have a look at [Working_With_frontier.ipynb](https://github.com/Hari31416/pystock/blob/main/Working_With_frontier.ipynb) to see how to use the `frontier` module to plot efficient frontiers.\n\n## Documentation\n\nThe documentation is available at [https://hari31416.github.io/pystock/](https://hari31416.github.io/pystock/).\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Harikesh Kushwaha  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 optimization",
    "version": "0.3.0",
    "split_keywords": [
        "optimization",
        "portfolio",
        "stock"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cf3f8c2e4bc39f32455b69ac1da2d8bb926d5eac1addc300753aed2c49daf4ac",
                "md5": "a5c01b0efb86bc5f410d72c58341041d",
                "sha256": "1c624e296d59722e3d69f6384fa49ca2526408836dc6c15e6623c21271ffaabe"
            },
            "downloads": -1,
            "filename": "pystock0-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a5c01b0efb86bc5f410d72c58341041d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 23546,
            "upload_time": "2023-03-15T10:23:57",
            "upload_time_iso_8601": "2023-03-15T10:23:57.030919Z",
            "url": "https://files.pythonhosted.org/packages/cf/3f/8c2e4bc39f32455b69ac1da2d8bb926d5eac1addc300753aed2c49daf4ac/pystock0-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1a0edb3dce245a1fc2b596f5572c8c62f8f0cda3ddfe86eaf454002f9757eb07",
                "md5": "6d8dcb498b6cb41fb379197f317407f5",
                "sha256": "452c38a721162e4d86a3078762d05954bc397d6d071d36cde3153a51d9b02405"
            },
            "downloads": -1,
            "filename": "pystock0-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6d8dcb498b6cb41fb379197f317407f5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4795654,
            "upload_time": "2023-03-15T10:24:12",
            "upload_time_iso_8601": "2023-03-15T10:24:12.895460Z",
            "url": "https://files.pythonhosted.org/packages/1a/0e/db3dce245a1fc2b596f5572c8c62f8f0cda3ddfe86eaf454002f9757eb07/pystock0-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-15 10:24:12",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "pystock0"
}
        
Elapsed time: 0.05211s