Skip to main content

Ingest portfolio and other data from multiple brokerages, and analyze it

Project description

bankroll CircleCI

Ingest portfolio and other data from multiple brokerages, and analyze it.

Table of contents:

  1. Installation
  2. Connecting to brokers
    1. Interactive Brokers
    2. Charles Schwab
    3. Fidelity
    4. Vanguard
  3. Extending bankroll

Installation

To install bankroll as a Python package, simply run pip (or pip3, as it may be named on your system) from the repository root:

pip install .

This will also make the command-line tool available directly:

bankroll --help

The Interactive Brokers API must also be installed prior to using bankroll. This repository includes a helpful script to ease this process:

script/install_twsapi

If you do not want to install ibapi globally, you may wish to set up a Python virtual environment instead.

Connecting to brokers

After being set up, bankroll can be used from the command line to bring together data from multiple brokerages.

For example, to show all positions held in both Interactive Brokers and Charles Schwab:

python -m bankroll \
  --twsport 7496 \
  --schwabpositions ~/Positions-2019-01-01.CSV \
  --schwabtransactions ~/Transactions_20190101.CSV \
  positions

Run with --help to see all options:

python -m bankroll --help

Interactive Brokers

Interactive Brokers (sometimes abbreviated as IB or IBKR) offers a well-supported API, which—along with ib_insync—makes it possible to load up-to-date portfolio data and request real-time information about particular securities.

Because this integration is so useful, some generic functionality in bankroll will require an IB account.

Unfortunately, one of IB's trading applications—Trader Workstation or IB Gateway—must be running and logged-in to accept API connections. You may wish to use IBC to automate the startup and login of these applications.

Once Trader Workstation or IB Gateway is running, and API connections are enabled, provide the local port number to bankroll like so:

python -m bankroll \
  --twsport 7496 \
  [command]

Querying trade history

IB's Trader Workstation API does not support retrieving information about an account's historical trades, so bankroll must use their Flex Web Service.

To set this up, log in to Account Management, then browse to SettingsAccount Settings in the sidebar:

Account Settings

In the Reporting section of this page, click the gear to configure Flex Web Service:

Flex Web Service

Once configured, copy the Current Token for use on the command line.

Then, you must save a query for bankroll to use. Back in the sidebar, browse to ReportsFlex Queries:

Flex Queries

Click the gear to configure Custom Flex Queries:

Custom Flex Queries

Create a new Trade Confirmation Flex Query Template:

Trade Confirmation Flex Query Templates

Pick a name of your choosing, then make sure the Date Period reflects the historical period you care about (e.g., Last 365 Calendar Days):

Trade Confirmation Flex Query Details

Under Sections, click Trade Confirmations and enable everything in the dialog which appears:

Trade Confirmation button Trade Confirmation options

After saving your query, expand it in the list to view and copy the Query ID for use on the command line.

With the token and the query ID from your account, historical trades can be downloaded:

python -m bankroll \
  --flextoken [token] \
  --flexquery-trades [query ID] \
  activity

Querying dividend history

This workflow will be simplified in the future.

To incorporate the history of dividend payments in your portfolio, follow the same steps for the Trade Confirmation Flex Query, but create an Activity Flex Query instead.

The only section which needs to be enabled is Change in Dividend Accruals:

Activity query options

Pass your existing token, and the new query's ID, on the command line:

python -m bankroll \
  --flextoken [token] \
  --flexquery-activity [query ID] \
  activity

Charles Schwab

Charles Schwab does not offer an API, but it does provide CSV files for export, which bankroll can then import.

Browse to the "Positions" and/or "Transactions" screen:

Positions and Transactions

Click the "Export" link in the top-right:

Export

Then provide the paths of either or both these downloaded files to bankroll:

python -m bankroll \
  --schwabpositions ~/path/to/Positions.CSV \
  --schwabtransactions ~/path/to/Transactions.CSV \
  [command]

Fidelity

Fidelity is supported through a similar facility as Schwab. More detailed instructions have yet to be written—contributions welcome!

Vanguard

Vanguard is a work in progress, and may not be as fully-featured as the other brokerages listed here. Contributions welcome!

Extending bankroll

Although the command-line interface exposes a basic set of functionality, it will never be able to capture the full set of possible use cases. For much greater flexibility, you can write Python code to use bankroll directly, and build on top of its APIs for your own purposes.

For some examples, see the included notebooks.

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

bankroll-0.1.0.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

bankroll-0.1.0-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

Details for the file bankroll-0.1.0.tar.gz.

File metadata

  • Download URL: bankroll-0.1.0.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for bankroll-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d5977cb5850d84f2b567a8564bc44f86bec619bce9f8e675684ac47eb722f6c1
MD5 11dbdb67a793a75a318beaf5762f0c45
BLAKE2b-256 e26b04287c1f56e81a4e7d87b166e08b27baf72dc9ebc7d1e9a13d6f92a04585

See more details on using hashes here.

File details

Details for the file bankroll-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bankroll-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for bankroll-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d05169472a8794c318290ca7bb6a2af4f7e63f1624ba1549144d1893eb7ec31
MD5 07447e5a111fd09b77851fe36aa434e6
BLAKE2b-256 36cb144b28826a6727b712548d2b0b8d6c33f329e4a033a8eb044914f98e79d0

See more details on using hashes here.

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