[Python] QUANTSTAT library : Error: Truth value of a Series is ambiguous. Use a.empty,...

Discussão em 'Python' iniciado por Stack, Agosto 16, 2025.

  1. Stack

    Stack Membro Participativo

    I was able to generate a html Tearsheet report on the returns of a single stock. But when i try to include a benchmark I get this error.

    Traceback (most recent call last):
    File "d:\Documents\112825123\QuantSTAT\portfolio.py", line 20, in <module>
    qs.reports.html(stock, benchmark="SPY", title='GOLD vs S&P 500', output='reports/gld_vs_spy.html')
    File "D:\Documents\112825123\environments\Quantvenv\Lib\site-packages\quantstats\reports.py", line 264, in html
    mtrx = metrics(
    ^^^^^^^^
    File "D:\Documents\112825123\environments\Quantvenv\Lib\site-packages\quantstats\reports.py", line 1331, in metrics
    _stats.kelly_criterion(df, prepare_returns=False) * pct
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\Documents\112825123\environments\Quantvenv\Lib\site-packages\quantstats\stats.py", line 2395, in kelly_criterion if win_loss_ratio == 0 or _pd.isna(win_loss_ratio):
    ^^^^^^^^^^^^^^^^^^^
    File "D:\Documents\112825123\environments\Quantvenv\Lib\site-packages\pandas\core\generic.py", line 1577, in __nonzero__
    raise ValueError(
    ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().


    import quantstats as qs

    # extend pandas functionality with metrics unto the stock obect
    qs.extend_pandas()

    # using yfinance download the daily returns for GOLD
    stock = qs.utils.download_returns('GLD')


    # generate html Tearsheet Report comparing GOLD commodity with S&P 500 index
    qs.reports.html(stock, benchmark="SPY", title='GOLD vs S&P 500', output='reports/gld_vs_spy.html')

    Continue reading...

Compartilhe esta Página