This Jupyter notebook contains two classes, StockAnalysis
and CorrelationVisualizer
, designed to help with the analysis of stock data and visualization of correlations between stock prices and economic indicators.
The StockAnalysis
class fetches historical stock data from Yahoo Finance, calculates Bollinger Bands, identifies bullish and bearish signals, and creates visualizations using Plotly.
- Python 3.x
- pandas
- yfinance
- plotly
- prophet
- Open the
stock_correlation_economic_indicators.ipynb
notebook. - Make sure you have the required libraries installed (you can install them using
!pip install pandas yfinance plotly prophet
). - In the
StockAnalysis
class, initialize the object with your desired list of stock tickers and the date range for historical data. - Run the cells to perform the analysis and visualize the results.
The CorrelationVisualizer
class fetches economic indicator data from FRED API and stock price data from Yahoo Finance for the specified tickers. It then calculates the correlation matrix and visualizes it using Seaborn.
- Python 3.x
- pandas
- yfinance
- seaborn
- matplotlib
- fredapi
- Open the
stock_correlation_economic_indicators.ipynb
notebook. - Make sure you have the required libraries installed (you can install them using
!pip install pandas yfinance seaborn matplotlib fredapi
). - In the
CorrelationVisualizer
class, initialize the object with your desired list of stock tickers, economic indicators, and the date range for data. - Obtain your FRED API key from https://fred.stlouisfed.org/docs/api/api_key.html.
- Replace
'YOUR_FRED_API_KEY'
in the notebook with your actual API key. - Run the cells to fetch data and visualize the correlation matrix for each ticker and the economic indicators.
In the StockAnalysis
class, Bollinger Bands are calculated based on a rolling average and standard deviation of the closing prices. When the closing price crosses above the upper Bollinger Band, it's considered a bearish signal, indicating a potential overbought condition. Conversely, when the closing price crosses below the lower Bollinger Band, it's considered a bullish signal, indicating a potential oversold condition.
The identify_bullish_bearish_signals
method in the StockAnalysis
class identifies these bullish and bearish signals, and they are visualized as green and red markers on the plot.
For examples and usage, please see the code in the stock_correlation_economic_indicators.ipynb
notebook.
Please make sure you have the required libraries installed before running the code. If you encounter any issues, feel free to contribute to the project or create issues on GitHub.
Make sure to replace 'YOUR_FRED_API_KEY'
in the notebook with your actual FRED API key to fetch economic indicator data.
Happy analyzing and visualizing!