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')
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.

latest = my_portfolio.status()
display(latest)

total_cost, total_value = latest.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

import plotly.express as px

px.bar(latest.sort_values('gain_pct', ascending=False), 
       x='symbol', y='gain_pct', color='gain_pct', 
       text='gain_pct', hover_data=['gain'],
       color_continuous_scale=px.colors.diverging.PiYG, color_continuous_midpoint=0,
       title='My Holdings')

Alt text

d). Plot historical data

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

Alt text

Testing

After installation, you can launch the test suite:

$ pytest

Help and Support

Examples

Theme MyBinder Colab
My Stock Portfolio Performance Binder Open In Colab
Market Indexes Binder Open In Colab

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.2.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

capon-0.0.2-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: capon-0.0.2.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for capon-0.0.2.tar.gz
Algorithm Hash digest
SHA256 3e6e8fa1dbfaf5df2ff2f1ebab012c09690344739ba09634f153be7df9902fa4
MD5 f691f61417956e7e730ed9dd429165dc
BLAKE2b-256 86272b7463e2b3e7ce666daae64a04b1d20fb98e917babb255b56928f6449c5e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: capon-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for capon-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 effd6ebc83622ad472a7d4a1e27daa4ac88a52ddc5c0846b709c3671328abd2d
MD5 74903b91d780bba966b9ff80a241fa81
BLAKE2b-256 6bf9c67a077e3012b646c8e70285cc95910ef0459538209bbed3db3dd9be1b7f

See more details on using hashes here.

Supported by

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