Skip to content
!pip install QuantStats
# https://github.com/ranaroussi/quantstats
%matplotlib inline
import quantstats as qs

# extend pandas functionality with metrics, etc.
qs.extend_pandas()

# fetch the daily returns for a stock
stock = qs.utils.download_returns('AMZN')

# show sharpe ratio
qs.stats.sharpe(stock)

# or using extend_pandas() :)
stock.sharpe()

# qs.plots.snapshot(stock, title='Amazon Performance', show=True)

# can also be called via:
# stock.plot_snapshot(title='Facebook Performance', show=True)
# benchmark can be a pandas Series or ticker
# Ensure the index of the stock DataFrame is a DateTimeIndex
if not isinstance(stock.index, pd.DatetimeIndex):
    stock.index = pd.to_datetime(stock.index)

# Ensure the index of the benchmark is also a DateTimeIndex
if not isinstance(benchmark.index, pd.DatetimeIndex):
    benchmark.index = pd.to_datetime(benchmark.index)

qs.reports.html(stock, "SPY")
Run cancelled
# qs.reports.metrics(stock,"SPY") # - shows basic/full metrics
# qs.reports.plots(stock, "SPY") #- shows basic/full plots
qs.reports.basic(stock,"SPY") # - shows basic metrics and plots
# qs.reports.full(stock, 'SPY"') # - shows full metrics and plots
# qs.reports.html(...) # - generates a complete report as html
# Let' create an html tearsheet