Skip to main content

Capital Market in Python

Project description

capon

Capital Market in Python

Author Version Demo
Gialdetti PyPI Binder

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

$ pip install capon

Install latest development version

$ pip install git+https://github.com/gialdetti/capon.git

or

$ 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.

import capon

amd = capon.stock('AMD', range='ytd')

The historical data is given as a standard pandas dataframe. This allows a fast and powerful data analysis, manipulation and visualization. For instance,

amd.plot(x='timestamp', y='adjclose')

Alt text

My portfolio example

Track your personal stock portfolio with real-time data.

a) Define my holdings

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

b) Sync with real-time stock data to find current status

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

c) Plot it

from capon.visualization import plot_status
plot_status(status)

Alt text

d) Plot historical data

import plotly.express as px

performance = my_portfolio.performance()
px.line(performance, x='timestamp', y='gain_pct', color='symbol', template='capon')

Alt text

The full example in a live notebook is provided below.

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
My Stock Portfolio Performance Binder Open In Colab
Stock Market Crash and Rebound Amid Coronavirus Binder Open In Colab
Analyzing the Sector-level Crash and Rebound Binder Open In Colab

Testing

After cloning and installing the development version, you can launch the test suite:

$ pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

capon-0.0.8.tar.gz (2.2 MB view details)

Uploaded Source

Built Distribution

capon-0.0.8-py3-none-any.whl (2.2 MB view details)

Uploaded Python 3

File details

Details for the file capon-0.0.8.tar.gz.

File metadata

  • Download URL: capon-0.0.8.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for capon-0.0.8.tar.gz
Algorithm Hash digest
SHA256 3ac44ba709c0935e69ba2df143a5710a35060cc8ea0e03f84f459881bc758d3a
MD5 c78da698c82bbbb70d64c03b18464457
BLAKE2b-256 513bd2aea2bb9c31d1e3d9b8e332bc7ad144413c68fa84527c98d45fd55f7167

See more details on using hashes here.

Provenance

File details

Details for the file capon-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: capon-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for capon-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 cc4cd4d1bfa1c70bce7ebe716320cda27404fb1603eb4f7bfa298847a48f754c
MD5 870e11395cd333f1e616c806d39e48b7
BLAKE2b-256 fbd5ce149cc44295dc2721fc45618d6881998c3abaa55f9ca6a5abf1707770f8

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page