Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: pivot() takes 1 positional argument but 4 were given in quantstats.reports.html #357

Open
Orchid420 opened this issue Jun 19, 2024 · 1 comment

Comments

@Orchid420
Copy link

I encountered a TypeError when trying to generate a report using the quantstats.reports.html function. The error message indicates an issue with the pivot method in the quantstats library.

Steps to Reproduce
Set up the environment with the following packages:

Python 3.9.19
pandas 2.2.2
numpy 1.26.4
scipy 1.12.0
matplotlib 3.8.4
seaborn 0.13.2
tabulate 0.9.0
yfinance 0.2.40
plotly 5.20.0
quantstats 0.0.50
Run the following script:

python
Copy code
import pandas as pd
import quantstats as qs
import yfinance as yf

Fetch the daily returns for a stock

stock = qs.utils.download_returns('META')

Ensure datetime index of stock is timezone-naive

stock.index = stock.index.tz_localize(None)

Fetch the benchmark data

benchmark = qs.utils.download_returns('SPY')

Ensure datetime index of benchmark is timezone-naive

benchmark.index = benchmark.index.tz_localize(None)

Ensure the data is aligned by reindexing the benchmark to the stock index

benchmark = benchmark.reindex(stock.index).dropna()

Show sharpe ratio

print(qs.stats.sharpe(stock))

Or using extend_pandas() :)

print(stock.sharpe())

Generate the quantstats report

qs.reports.html(stock, benchmark, output='report.html')


TypeError Traceback (most recent call last)
File ~\anaconda3\envs\myenv\lib\site-packages\quantstats\reports.py:185, in html(returns, benchmark, rf, grayscale, title, output, compounded)
182 tpl = tpl.replace('{{title}}', title)
184 figfile = _utils._file_stream()
185 _plots.monthly_heatmap(returns, grayscale=grayscale,
186 figsize=(8, 4), cbar=False,
187 savefig={'fname': figfile, 'format': 'svg'},
188 show=False, ylabel=False, compounded=compounded)
189 tpl = tpl.replace('{{monthly_heatmap}}', figfile.getvalue().decode())
191 figfile = _utils._file_stream()

File ~\anaconda3\envs\myenv\lib\site-packages\quantstats_plotting\wrappers.py:568, in monthly_heatmap(returns, annot_size, figsize, cbar, square, compounded, eoy, grayscale, fontname, ylabel, savefig, show)
559 def monthly_heatmap(returns, annot_size=10, figsize=(10, 5),
560 cbar=True, square=False,
561 compounded=True, eoy=False,
...
564
565 # colors, ls, alpha = _core._get_colors(grayscale)
566 cmap = 'gray' if grayscale else 'RdYlGn'
568 returns = _stats.monthly_returns(returns, eoy=eoy,
569 compounded=compounded) * 100
571 fig_height = len(returns) / 3
573 if figsize is None:

File ~\anaconda3\envs\myenv\lib\site-packages\quantstats\stats.py:697, in monthly_returns(returns, eoy, compounded)
694 returns['Month'] = returns.index.strftime('%b')
696 # make pivot table
697 returns = returns.pivot('Year', 'Month', 'Returns').fillna(0)
TypeError: pivot() takes 1 positional argument but 4 were given

@grzesir
Copy link

grzesir commented Jul 30, 2024

Check out https://github.com/Lumiwealth/quantstats_lumi, which is being updated regularly. We are a fork of this library that is being maintained by Lumiwealth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants