Skip to main content

Utility to create a monthly returns heatmap from Pandas series

Project description

Python version Travis-CI build status PyPi version PyPi status Star this repo Follow me on twitter

monthly-returns-heatmap is a simple Python library for creating Monthly Returns Heatmap from Pandas series with ease.

Changelog »


Quick Start

Let’s create a returns heatmap for SPY (S&P 500 Spider ETF).

First, let’s download SPY’s daily close prices from Google finance.

from pandas_datareader import data
prices = data.get_data_google("SPY")['Close']

Next, we’ll import returns_heatmap and plot the monthly return heatmap:

import monthly_returns_heatmap as mrh

prices.plot_returns_heatmap()
# mrh.plot(prices) # <== or using direct call
demo

Getting data only (no plotting

returns = prices.get_returns_heatmap()
# returns = mrh.get(prices) # <== or using direct call

print(returns)

# prints:

Month       Jan        Feb        Mar        Apr  ...        Dec
Year
2010   0.000000   0.031195   0.056529   0.015470  ...   0.061271
2011   0.023300   0.034737  -0.004807   0.030413  ...   0.003117
2012   0.045498   0.043137   0.028129  -0.006751  ...   0.001759
2013   0.051190   0.012759   0.033375   0.019212  ...   0.020387
2014  -0.035248   0.045516   0.003865   0.006951  ...  -0.008012
2015  -0.029629   0.056205  -0.020080   0.009834  ...  -0.023096
2016  -0.049787  -0.001910   0.062943   0.003941  ...   0.014293
2017   0.017895   0.039292  -0.003087   0.009926  ...   0.000000

Plot Parameters (optional)

  • title - Heatmap title (defaults to "Monthly Returns (%)")

  • title_color - Heatmap title color (defaults to "black")

  • title_size - Heatmap title font size (defaults to 12)

  • annot_size - Returns boxes font size (defaults to 10)

  • figsize - Heatmap figure size (defaults to None)

  • cmap - Color map (defaults to "RdYlGn")

  • cbar - Show color bar? (defaults to True)

  • square - Force squere returns boxes? (defaults to False)

Installation

Install returns_heatmap using pip:

$ pip install returns_heatmap --upgrade --no-cache-dir

Requirements

P.S.

Please drop me an note with any feedback you have.

Ran Aroussi

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

monthly-returns-heatmap-0.0.1.tar.gz (7.3 kB view details)

Uploaded Source

File details

Details for the file monthly-returns-heatmap-0.0.1.tar.gz.

File metadata

File hashes

Hashes for monthly-returns-heatmap-0.0.1.tar.gz
Algorithm Hash digest
SHA256 78507e7166a213ba4f9ac3fa421878fc924d7476c02d42939490063b5f216608
MD5 482af5c2f8eed43cde37a61fc16f8c9d
BLAKE2b-256 d5be582b389874aef1087395c4d0d2e82af095866621cb3092ef68b9b6e7cecb

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