# capon
**Cap**ital Market in **P**yth**on**
| Author | Version | Demo |
| :----------: | :--------------------------------------: | :--------------------------------------: |
| Gialdetti | [![PyPI](https://img.shields.io/pypi/v/capon.svg)](https://pypi.org/project/capon/) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/gialdetti/capon/master?filepath=examples%2Fmonitoring%2Fmy_portfolio_performance.ipynb) | |
`capon` is a python package for easily obtaining and analyzing real-time stock data. It provides extended datasets of stock metadata and features.
In addition, it offers simple APIs for tracking your personal stock portfolios and their live status.
## Installation
### Install latest release version via [pip](https://pip.pypa.io/en/stable/quickstart/)
```bash
$ pip install capon
```
### Install latest development version
```bash
$ pip install git+https://github.com/gialdetti/capon.git
```
or
```bash
$ git clone https://github.com/gialdetti/capon.git
$ cd capon
$ python setup.py install
```
## A simple example
Get the historical stock price of AMD, and plot it.
```python
import capon
amd = capon.stock('AMD', range='ytd')
```
![](./examples/images/themes/capon/readme_amd_dataframe.png)
The historical data is given as a standard [pandas](https://pandas.pydata.org/) dataframe.
This allows a fast and powerful data analysis, manipulation and visualization. For instance,
```python
amd.plot(x='timestamp', y='adjclose')
```
![Alt text](./examples/images/themes/capon/readme_amd.png)
## My portfolio example
Track your personal stock portfolio with real-time data.
a) Define my holdings
```python
from capon import Portfolio, Lot
my_portfolio = Portfolio([
Lot('2020-03-20', 'AMZN', 2, 1888.86),
Lot('2020-03-20', 'TSLA', 8, 451.40),
Lot('2020-03-23', 'GOOGL', 3, 1037.89),
Lot('2020-03-23', 'AMC', 1041, 2.88),
Lot('2020-03-27', 'ZM', 20, 150.29),
])
```
![Alt text](./examples/images/themes/capon/readme_my_portfolio.png)
b) Sync with real-time stock data to find current status
```python
status = my_portfolio.status()
display(status)
total_cost, total_value = status.sum()[['cost', 'value']]
print(f'Total cost: {total_cost:,.2f}; Market value: {total_value:,.2f}')
print(f'Total gain: {total_value-total_cost:+,.2f} ({total_value/total_cost-1:+,.2%})')
```
![Alt text](./examples/images/themes/capon/readme_my_portfolio_status.png)
c) Plot it
```python
from capon.visualization import plot_status
plot_status(status)
```
![Alt text](./examples/images/themes/capon/readme_my_portfolio_status_bar.png)
d) Plot historical data
```python
import plotly.express as px
performance = my_portfolio.performance()
px.line(performance, x='timestamp', y='gain_pct', color='symbol', template='capon')
```
![Alt text](./examples/images/themes/capon/readme_my_portfolio_history.png)
The full example in a live notebook is provided [below](#examples).
## Help and Support
### Examples
The tutorials below aim to provide a clear and concise demonstration of some of the most important capabilities of `capon`.
For instance, step-by-step guides for building and real-time monitoring of your portfolio, for fetching and analyzing
stock historical data, or for using stocks metadata.
To make it a bit more interesting (hopefully), each tutorial first poses a meaningful stock-market "research question".
In the context of answering these questions, the tutorials demonstrate the relevant library features.
| Theme | MyBinder | Colab |
| ------------ | :----------: | :---: |
| [Market Performance Visualization](https://nbviewer.jupyter.org/github/gialdetti/capon/blob/master/examples/visualization/visualize-markets.ipynb) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/gialdetti/capon/master?filepath=examples/visualization/visualize-markets.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gialdetti/capon/blob/master/examples/visualization/visualize-markets.ipynb) |
| [My Stock Portfolio Performance](https://nbviewer.jupyter.org/github/gialdetti/capon/blob/master/examples/monitoring/my_portfolio_performance.ipynb) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/gialdetti/capon/master?filepath=examples/monitoring/my_portfolio_performance.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gialdetti/capon/blob/master/examples/monitoring/my_portfolio_performance.ipynb) |
| [Stock Market Crash and Rebound Amid Coronavirus](https://nbviewer.jupyter.org/github/gialdetti/capon/blob/master/examples/market_analysis/stock_indexes.ipynb) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/gialdetti/capon/master?filepath=examples/market_analysis/stock_indexes.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gialdetti/capon/blob/master/examples/market_analysis/stock_indexes.ipynb) |
| [Analyzing the Sector-level Crash and Rebound](https://nbviewer.jupyter.org/github/gialdetti/capon/blob/master/examples/market_analysis/sector_crash_and_rebound.ipynb) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/gialdetti/capon/master?filepath=examples/market_analysis/sector_crash_and_rebound.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gialdetti/capon/blob/master/examples/market_analysis/sector_crash_and_rebound.ipynb) |
## Testing
After cloning and installing the development version, you can launch the test suite:
```bash
$ pytest
```
Raw data
{
"_id": null,
"home_page": "https://github.com/gialdetti/capon/",
"name": "capon",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "capital markets, stocks, stock market, finance, dataset, portfolio, dashboard, yahoo finance",
"author": "Eyal Gal",
"author_email": "eyalgl@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e3/fb/1db20f1660632060c5e951ae593ed12c356ac467c4a5ad98afe293dd115e/capon-0.0.94.tar.gz",
"platform": null,
"description": "# capon\n**Cap**ital Market in **P**yth**on**\n\n| Author | Version | Demo |\n| :----------: | :--------------------------------------: | :--------------------------------------: |\n| Gialdetti | [![PyPI](https://img.shields.io/pypi/v/capon.svg)](https://pypi.org/project/capon/) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/gialdetti/capon/master?filepath=examples%2Fmonitoring%2Fmy_portfolio_performance.ipynb) | |\n\n\n`capon` is a python package for easily obtaining and analyzing real-time stock data. It provides extended datasets of stock metadata and features.\nIn addition, it offers simple APIs for tracking your personal stock portfolios and their live status.\n\n## Installation\n### Install latest release version via [pip](https://pip.pypa.io/en/stable/quickstart/)\n```bash\n$ pip install capon\n```\n\n### Install latest development version\n```bash\n$ pip install git+https://github.com/gialdetti/capon.git\n``` \nor\n```bash\n$ git clone https://github.com/gialdetti/capon.git\n$ cd capon\n$ python setup.py install\n```\n\n## A simple example\nGet the historical stock price of AMD, and plot it.\n```python\nimport capon\n\namd = capon.stock('AMD', range='ytd')\n```\n![](./examples/images/themes/capon/readme_amd_dataframe.png)\n\nThe historical data is given as a standard [pandas](https://pandas.pydata.org/) dataframe. \nThis allows a fast and powerful data analysis, manipulation and visualization. For instance,\n```python\namd.plot(x='timestamp', y='adjclose')\n```\n![Alt text](./examples/images/themes/capon/readme_amd.png)\n\n\n## My portfolio example\nTrack your personal stock portfolio with real-time data.\n\na) Define my holdings\n```python\nfrom capon import Portfolio, Lot\n\nmy_portfolio = Portfolio([\n Lot('2020-03-20', 'AMZN', 2, 1888.86),\n Lot('2020-03-20', 'TSLA', 8, 451.40),\n Lot('2020-03-23', 'GOOGL', 3, 1037.89),\n Lot('2020-03-23', 'AMC', 1041, 2.88),\n Lot('2020-03-27', 'ZM', 20, 150.29),\n])\n```\n![Alt text](./examples/images/themes/capon/readme_my_portfolio.png)\n\n\nb) Sync with real-time stock data to find current status\n```python\nstatus = my_portfolio.status()\ndisplay(status)\n\ntotal_cost, total_value = status.sum()[['cost', 'value']]\nprint(f'Total cost: {total_cost:,.2f}; Market value: {total_value:,.2f}')\nprint(f'Total gain: {total_value-total_cost:+,.2f} ({total_value/total_cost-1:+,.2%})')\n```\n![Alt text](./examples/images/themes/capon/readme_my_portfolio_status.png)\n\nc) Plot it\n```python\nfrom capon.visualization import plot_status\nplot_status(status)\n```\n![Alt text](./examples/images/themes/capon/readme_my_portfolio_status_bar.png)\n\nd) Plot historical data\n```python\nimport plotly.express as px\n\nperformance = my_portfolio.performance()\npx.line(performance, x='timestamp', y='gain_pct', color='symbol', template='capon')\n```\n![Alt text](./examples/images/themes/capon/readme_my_portfolio_history.png)\n\nThe full example in a live notebook is provided [below](#examples).\n\n## Help and Support\n\n### Examples\n\nThe tutorials below aim to provide a clear and concise demonstration of some of the most important capabilities of `capon`.\nFor instance, step-by-step guides for building and real-time monitoring of your portfolio, for fetching and analyzing \nstock historical data, or for using stocks metadata.\n\nTo make it a bit more interesting (hopefully), each tutorial first poses a meaningful stock-market \"research question\".\nIn the context of answering these questions, the tutorials demonstrate the relevant library features. \n\n| Theme | MyBinder | Colab |\n| ------------ | :----------: | :---: |\n| [Market Performance Visualization](https://nbviewer.jupyter.org/github/gialdetti/capon/blob/master/examples/visualization/visualize-markets.ipynb) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/gialdetti/capon/master?filepath=examples/visualization/visualize-markets.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gialdetti/capon/blob/master/examples/visualization/visualize-markets.ipynb) |\n| [My Stock Portfolio Performance](https://nbviewer.jupyter.org/github/gialdetti/capon/blob/master/examples/monitoring/my_portfolio_performance.ipynb) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/gialdetti/capon/master?filepath=examples/monitoring/my_portfolio_performance.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gialdetti/capon/blob/master/examples/monitoring/my_portfolio_performance.ipynb) | \n| [Stock Market Crash and Rebound Amid Coronavirus](https://nbviewer.jupyter.org/github/gialdetti/capon/blob/master/examples/market_analysis/stock_indexes.ipynb) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/gialdetti/capon/master?filepath=examples/market_analysis/stock_indexes.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gialdetti/capon/blob/master/examples/market_analysis/stock_indexes.ipynb) |\n| [Analyzing the Sector-level Crash and Rebound](https://nbviewer.jupyter.org/github/gialdetti/capon/blob/master/examples/market_analysis/sector_crash_and_rebound.ipynb) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/gialdetti/capon/master?filepath=examples/market_analysis/sector_crash_and_rebound.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gialdetti/capon/blob/master/examples/market_analysis/sector_crash_and_rebound.ipynb) |\n\n\n## Testing\nAfter cloning and installing the development version, you can launch the test suite:\n```bash\n$ pytest\n```\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Capital Market in Python",
"version": "0.0.94",
"project_urls": {
"Homepage": "https://github.com/gialdetti/capon/"
},
"split_keywords": [
"capital markets",
" stocks",
" stock market",
" finance",
" dataset",
" portfolio",
" dashboard",
" yahoo finance"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "badd0e4375b7b262e280a49be3c62caa6ea06a2472165d82bd80c531e48df492",
"md5": "d5a79860241df39e9d6281193c557da0",
"sha256": "b7678a82aaf2152893d433eb6e8d078e5b69d5b1287fb552de7442dbcf761056"
},
"downloads": -1,
"filename": "capon-0.0.94-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d5a79860241df39e9d6281193c557da0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 2249481,
"upload_time": "2024-08-29T18:57:20",
"upload_time_iso_8601": "2024-08-29T18:57:20.111084Z",
"url": "https://files.pythonhosted.org/packages/ba/dd/0e4375b7b262e280a49be3c62caa6ea06a2472165d82bd80c531e48df492/capon-0.0.94-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e3fb1db20f1660632060c5e951ae593ed12c356ac467c4a5ad98afe293dd115e",
"md5": "2c10e456ba4cec7f8bb3e9d721a8ceb8",
"sha256": "9e338c699b20c51b82d6b6f70b4301fe10a6cd275f48ace5379552d072722b08"
},
"downloads": -1,
"filename": "capon-0.0.94.tar.gz",
"has_sig": false,
"md5_digest": "2c10e456ba4cec7f8bb3e9d721a8ceb8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 2248165,
"upload_time": "2024-08-29T18:57:23",
"upload_time_iso_8601": "2024-08-29T18:57:23.603305Z",
"url": "https://files.pythonhosted.org/packages/e3/fb/1db20f1660632060c5e951ae593ed12c356ac467c4a5ad98afe293dd115e/capon-0.0.94.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-29 18:57:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gialdetti",
"github_project": "capon",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "capon"
}