Skip to main content

Finance plotting

Project description

Finance Plot

Plotting financial data in Python for the most part sucks. mpl_finance is horribly slow -- and plotly too -- when displaying 100k candlesticks or more.

Meet Finance Plotter, or finplot! It utilizes pyqtgraph underneath, which to my surprise was an excellent library. Finance Plot is built to immitate matplotlib's api, but with better default looks and much better performance.

Also included is some zooming+scaling logic, so you won't get that "panning all over the place" feeling as one normally finds in most non-finance plot libraries. Plus manual line drawing, where each line segment shows % and time change.

The left mouse button pans, the mouse wheel zooms, and holding Ctrl allows you to draw lines.

Easy installation

$ pip install finplot

Example

sample

This 25-liner pulls some BitCoin data off of Bittrex and shows the above:

import finplot as fplt
import numpy as np
import pandas as pd
import requests

# pull some data
symbol = 'USDT-BTC'
url = 'https://bittrex.com/Api/v2.0/pub/market/GetTicks?marketName=%s&tickInterval=fiveMin' % symbol
data = requests.get(url).json()

# format it in pandas
df = pd.DataFrame(data['result'])
df = df.rename(columns={'T':'time', 'O':'open', 'C':'close', 'H':'high', 'L':'low', 'V':'volume'})
df = df.astype({'time':'datetime64[ns]'})

# create three plots
ax,ax2,ax3 = fplt.create_plot(symbol, rows=3)

# plot candle sticks
candles = df[['time','open','close','high','low']]
fplt.candlestick_ochl(candles, ax=ax)

# put an MA in there
fplt.plot(df['time'], df['close'].rolling(25).mean(), ax=ax, color='#00f', legend='ma-25')

# place some dumb markers
hi_wicks = df['high'] - df[['open','close']].T.max()
df.loc[(hi_wicks>hi_wicks.quantile(0.99)), 'marker'] = df['high']
fplt.plot(df['time'], df['marker'], ax=ax, color='#000', style='v', legend='dumb mark')

# draw some random crap on our second plot
fplt.plot(df['time'], np.random.normal(size=len(df)), ax=ax2, color='#927', legend='stuff')
fplt.set_y_range(-1.4, +3.7, ax=ax2) # hard-code y-axis range limitation

# finally a volume bar chart in our third plot
volumes = df[['time','open','close','volume']]
fplt.volume_ocv(volumes, ax=ax3)

# we're done
fplt.show()

Realtime updating with realistic indicator

Included in this repo are a 40-liner Bitfinex example and a slightly longer BitMEX websocket example, which both update in realtime with Bitcoin/Dollar pulled from the exchange. They also shows realistic and useful indicators (TD Sequential for BFX and Bollinger Bands for BitMEX).

Enjoy!

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

finplot-0.7.0.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

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

finplot-0.7.0-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

Details for the file finplot-0.7.0.tar.gz.

File metadata

  • Download URL: finplot-0.7.0.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.6

File hashes

Hashes for finplot-0.7.0.tar.gz
Algorithm Hash digest
SHA256 5654afcf17f2122f652f33b7da5c823b6b7851622d51d1a654bb7103ff13acbd
MD5 7b3848a6c19fdad14d81f39dc333ff9c
BLAKE2b-256 4c3333303f68e72178841e5da92455a177b75a79d2cb14406f575837a7b84224

See more details on using hashes here.

File details

Details for the file finplot-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: finplot-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 35.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.6

File hashes

Hashes for finplot-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb5fa02c11f75ea0c5bafde8b982d9366d50828de00d0bd58eb7834b2324f778
MD5 772b842c8b6953d547371a6118ac9109
BLAKE2b-256 851a08adb5b5570ef79377ebdaa49a74a130235ef357f3317d30a90dd9a91e81

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