Stock Data to AI Reports
Pull stock data from Yahoo Finance, run AI analysis, get PDF reports
xlwings Lite: Stock Data to AI Reports
Excel app demonstrating how to pull stock data from Yahoo Finance, create technical analysis using API calls to FastAPI servers, and generate PDF reports by connecting to LLMs.
How xlwings Lite Works: The Python code is embedded directly inside the Excel file itself! Download the Excel file from the link below to get the complete app with all code included.
What This App Does
This xlwings Lite app enables you to pull stock data, perform technical analysis, and generate AI-powered reports:
- Pull stock profile data from Yahoo Finance
- Retrieve historical price data and stock financials
- Compute technical indicators (EMA, RSI, MACD, Bollinger Bands)
- Send data to Gemini for AI-powered technical analysis
- Generate PDF reports with custom styling
- Pull financial statements (P&L, Balance Sheet, Cash Flow)
- Access both annual and quarterly financial data
How to Use
- Download the app and install xlwings Lite from the Add-in button in Excel.
- Get a Gemini API key:
- Go to aistudio.google.com → Get API Key → Create AI Key.
- Free, takes less than a minute (no credit card required).
- Use the built-in functions:
- get_profile - Pull company profile information from Yahoo Finance
- get_prices - Retrieve historical stock price data
- get_profit_loss - Get the profit and loss statement
- get_balance_sheet - Get the company's balance sheet
- get_cash_flow - Get the cash flow statement
- get_quarterly - Retrieve quarterly financial data
- create_technicals - Calculate technical indicators like EMA, RSI, MACD
- get_technical_analysis_from_gemini - Generate AI analysis of the technical indicators
- Enter ticker symbols: Input Yahoo Finance symbols (e.g., AAPL, ^NSEI) to retrieve data.
- Click buttons to trigger actions: Get profiles, prices, financials, and generate reports.
How It Works
This app orchestrates a flow between Excel, FastAPI servers, and AI services:
- Data retrieval:
- When you click buttons like "get_profile" or "get_prices", xlwings Lite makes API calls to a custom FastAPI server.
- The FastAPI server acts as a web layer that uses the yfinance Python package to fetch data from Yahoo Finance.
- This intermediary server handles the API requests from Excel, processes the data using yfinance, and returns it back to Excel.
- This architecture solves CORS issues that would occur if yfinance was called directly from xlwings.
- Technical analysis:
- The "create_technicals" function uses the finta Python package to calculate indicators.
- Calculated indicators are added as new columns to the price data.
- The app then prepares this data for AI analysis.
- AI analysis and reporting:
- Price data and indicators are sent to Gemini for technical analysis.
- The markdown output from Gemini is sent to another custom FastAPI server.
- This second server attaches custom styling to the markdown and sends it to a third-party service (md2pdf.fly.dev).
- The third-party service converts the styled markdown to a PDF document.
- A temporary link to the generated PDF is returned to Excel for viewing.
IMPORTANT: Fine Print YLENS: Yahoo Finance Analyzer is not investment research or advice. It's a working prototype to demonstrate what's possible with xlwings Lite. AI and automation setups in live use cases require iteration, validation, and human judgment.
Source Code & Resources
Source Code Location: All Python source code is embedded inside the Excel file! You can download the Excel file with embedded code from the links above.
- xlwings Lite: Official xlwings Lite website with installation instructions and examples.
- xlwings Documentation: Comprehensive documentation with Excel object reference and API documentation.
- FastAPI - Markdown to PDF: GitHub repository for the FastAPI service that converts markdown to PDF reports.
- FastAPI - Yahoo Finance Pull: GitHub repository for the FastAPI service that connects to Yahoo Finance.
Created by Felix Zumstein, xlwings Lite delivers a powerful and flexible solution for integrating Python with Excel - enabling native Excel support for databases, AI agents, LLMs, advanced analytics, machine learning, APIs, web services, and complete automation workflows.