This Python script provides a comprehensive financial analysis of a specified stock. It leverages various APIs and libraries to collect, analyze, and summarize stock sentiment and price data. The tool generates detailed financial reports, including sentiment analysis, price analysis, expert insights, and trade signals.
yfinance
matplotlib
crewai-tools
langchain-groq
langchain-openai
langchain-core
python-dotenv
numpy
markdown
pdfkit
streamlit
reportlab
logging
base64
functools
langchain_community.llms
langchain_community.document_loaders
langchain.docstore.document
unstructured.cleaners.core
langchain.chains.summarize
Clone the repository:
git clone <repository-url>
cd <repository-directory>
Install the required Python packages:
pip install -r requirements.txt
Set up environment variables:
.env
file in the root directory.OPENAI_API_KEY=your_openai_api_key
GROQ_API_KEY=your_groq_api_key
SERPER_API_KEY=your_serper_api_key
Run the script:
python production.py
Follow the prompts to choose a language model and enter the stock details:
The script will perform the following tasks:
.txt
and .md
file.The script generates a comprehensive financial report saved in both .txt
and .md
formats. The report includes:
Here is a sample of the generated report structure:
# Financial Report for [Stock] - Week of [Date]
## Collected Data:
## Initial Analysis Output:
[Analysis Output]
## Review Output:
[Review Output]
## Improved Analysis Output:
[Improved Output]
## Price Analysis:
[Price Analysis]
## Expert Analysis:
[Expert Analysis]
## Trade Signal:
[Trade Signal]
## Weekly Numerical Analysis:
A weekly chart has been generated to analyze the price trends of [Stock] over the past year.
![Weekly Chart](./[chart_filename])
## Sources:
[Data Summary]
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.
This project is licensed under the MIT License.
This script provides a graphical user interface (GUI) for the stock analysis tool using Streamlit. It includes the following features:
This script converts markdown files to PDF format. It includes the following functions:
extract_sources(md_content)
: Extracts sources from markdown content.This script contains various functions for stock data analysis and summarization. It includes the following functions:
collect_stock_data(stock, date)
: Collects stock data for a given stock and date.summarize_content(content)
: Summarizes the given content.scrape_and_summarize_link(link)
: Scrapes and summarizes content from a given link.analyze_stock_data(stock, data_summary)
: Analyzes stock data based on the data summary.review_analysis(stock, analysis_output)
: Reviews the analysis output for a given stock.improve_analysis(stock, review_output, analysis_output)
: Improves the analysis based on the review output.expert_analysis(stock, price_analysis, sentiment_analysis)
: Provides expert analysis based on price and sentiment analysis.generate_trade_signal(stock, improved_output, price_analysis)
: Generates trade signals based on the improved output and price analysis.get_weekly_stock_data(ticker, start_date, end_date)
: Retrieves weekly stock data for a given ticker and date range.perform_numerical_analysis(data, stock)
: Performs numerical analysis on the given data and stock.calculate_macd(data)
: Calculates the MACD (Moving Average Convergence Divergence) for the given data.calculate_bollinger_bands(data, window=20)
: Calculates the Bollinger Bands for the given data and window.analyze_price_data(data, stock)
: Analyzes the price data for a given stock.