Giter VIP home page Giter VIP logo

Comments (1)

christian-storm avatar christian-storm commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.