Comments (1)
I've run into this sort of error too and it has also been sporadic. After some digging, it seems that if the first year has only one data point then the code in quanstats._plotting.wrappers.yearly_returns:
returns = _utils._prepare_returns(returns).resample('A')
if compounded:
returns = returns.apply(_stats.compsum) <-----
else:
returns = returns.apply(_df.cumsum) <-----
returns = returns.resample('A').last()
returns a Series with values that range from scalars to arrays that don't have the same shape (leap year, trading day, etc. differences) instead of just scalars. The compsum or cumsum seems to group by day. Perhaps the sampler samples along the wrong axis? I wanted to suggest a fix to @ranaroussi but I couldn't figure it out.
This code reproduces the problem:
import pandas as pd
import pandas_datareader.data as pdr
import quantstats as qs
SP500 = pdr.get_data_yahoo("^GSPC", pd.to_datetime('2009-12-31'), pd.to_datetime('2020-01-02'), interval='d')
SP500["mon_ret"] =SP500["Adj Close"].pct_change()
qs.reports.html(SP500["mon_ret"], output='report2.html', title = "Monthly portfolio rebalancing")
A frustrating one because it can crop up anytime when a user-specified date range is just right (one day/month/...) in a year.
from quantstats.
Related Issues (20)
- stats.py: res = abs(total + 1.0) ** (1.0 / years) - 1 <-- ZeroDivisionErrorZeroDivisionError HOT 1
- Deprecated code in stats.py expected_return() HOT 1
- Calculation of 3Y and 5Y annualized return date lag HOT 1
- report.py's cagr function doesn't include the days per year options HOT 1
- Fix kelly_criterion formula for investment scenario HOT 1
- draw visuals in plotly HOT 1
- Jupyter import issue: `magic(...)` is deprecated HOT 1
- Cumulative Performance in reports.html does not calculate correctly HOT 4
- Generate full html_report but save as image
- Datetime issue
- "Strategy" HOT 2
- is _qtd bug ? HOT 1
- utils.make_index : TypeError: unsupported operand type(s) for +: 'float' and 'str' HOT 8
- Quantstats.plot Cannot Generate Plot HOT 1
- Errors in calculating drawdowns? HOT 2
- CAGR calculations HOT 2
- Issue with cagr function in stats HOT 2
- TypeError: pivot() takes 1 positional argument but 4 were given in quantstats.reports.html HOT 1
- monthly returns plot do not shouw the returns num in figure HOT 2
- Suggestion for Improving the CAGR Calculation in Your Package HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quantstats.