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

An error occurred while generating the QuantStats report: Index(...) must be called with a collection of some kind, 'Strategy' was passed #383

Open
tilakpatel22 opened this issue Nov 22, 2024 · 3 comments

Comments

@tilakpatel22
Copy link

tilakpatel22 commented Nov 22, 2024

code - import yfinance as yf
import quantstats as qs
import os

stock_ticker = "AAPL" # Replace with your stock ticker
start_date = "2020-01-01" # Start date for historical data
output_dir = "quantstats_reports"
os.makedirs(output_dir, exist_ok=True)
data = yf.download(stock_ticker, start=start_date, progress=False)

if data.empty:
print(f"No data found for {stock_ticker}. Please check the ticker or date range.")
else:
stock_close = data['Close'].dropna()

stock_close.name = stock_ticker  # Set a name for the Series
stock_close.index = stock_close.index.to_pydatetime()  

report_path = os.path.join(output_dir, f"{stock_ticker}_full_report.html")
try:
    qs.reports.html(
        stock_close,
        title=f"QuantStats Report for {stock_ticker}",
        output=report_path
    )
    print(f"QuantStats report generated successfully: {report_path}")
except Exception as e:
    print(f"An error occurred while generating the QuantStats report: {e}")

CAN SOMEONE HELP SOLVING ME THIS ERROR?

@tchinossa
Copy link

Have you resolved the error?

@tilakpatel22
Copy link
Author

@tchinossa not yet !!

@YoubiDev
Copy link

Make sure the data is stored as a pandas Series and not as a dataframe. You can convertt the Dataframe to a series by using the squeeze method.
stock_close = stock_close['(column_name)'].squeeze()

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

3 participants