This project involves the extraction and analysis of historical stock data, retrieved using the Yahoo Finance API ('yfinance'), from five different companies in the healthcare sector: JNJ, PFE, UNH, RHHBY, AZN. The primary goal is to gain insights into the stock performance of these companies over time.
JNJ (Johnson & Johnson): A diversified healthcare company involved in pharmaceuticals, medical devices, and consumer goods. They are known for products like Band-Aid, Tylenol, and prescription drugs.
PFE (Pfizer): A pharmaceutical company known for developing and manufacturing a wide range of medications, including vaccines, oncology drugs, and various therapeutic areas.
UNH (UnitedHealth Group): A health insurance and healthcare services company. They operate through various subsidiaries, providing health benefits and servicesto individuals and businesses.
RHHBY (Roche Holding AG): A Swiss multinational healthcare company specializing in pharmaceuticals and diagnostics. They are known for drugs in oncology, immunology, infectious diseases, and other therapeutic areas.
AZN (AstraZeneca): A global biopharmaceutical company focused on the discovery, development, and commercialization of prescription medicines. They are known for their contributions in areas such as cardiovascular, respiratory, and oncology drugs, as well as vaccines.
Data for each ticker symbol includes daily closing prices, which are aggregated over the past 5 years. Moving averages were calculated to smooth out price fluctuations and identify trends. Specifically, the 50-day and 200-day moving averages were computed for each stock. The plots reveal the historical stock prices for each ticker symbol, alongside their respective 50-day and 200-day moving averages. Trends and patterns in stock price movements can be observed, aiding in the interpretation of long-term performance.
Weekly returns are calculated to assess the performance of each stock over shorter time intervals. The weekly return is computed as the percent change in stock price from one week to the next. Weekly return plots depict the volatility and performance of each stock on a weekly basis. Fluctuations in weekly returns provide insights into the stock's sensitivity to market conditions and external factors.
![](/n8tmps/heathcare-stock/raw/main/MA_WeeklyReturns.jpg)
Principal Component Analysis (PCA) is a statistical technique used to reduce the dimensionality of a dataset while preserving as much variance as possible. It transforms high-dimensional data into a smaller set of uncorrelated variables called principal components, which capture the most significant patterns in the data. The process involves standardizing the data, computing the covariance matrix, and deriving eigenvalues and eigenvectors. The principal components are sorted by the variance they explain, allowing the data to be projected onto these components for analysis.
The weekly rates of return for Johnson & Johnson, Pfizer, UnitedHealth Group, Roche Holding AG, and AstraZeneca were determined for the period May 2019 through May 2024. The observations appear to be independently distributed, but the rates of return across stocks are correlated, because stocks tend to move together in response to general economic condtions.
Let
The principal components are:
The proportion of the total sample variance explained by the first three principal components is computed as:
- The first principal component is a measure of the rates of return for JNJ, PFE, UNH, RHHBY, and AZN.
- The second principal component is a measure of the rates of return for UNH, RHHBY, AZN, and to some extent, JNJ, and PFE.
- The third principal component is a measure of the rates of return for PFE, UNH, and to some extent, RHHBY.
![](/n8tmps/heathcare-stock/raw/main/healthstock.jpg)
- Dashboard Creation:
- An interactive dashboard is crafted in Tableau to visualize the stock data comprehensively.
- Key Features in Dashboard:
- Stock Volume: Visual representation of each company's stock volume over the selected period.
- Price Percent Change: Highlighting the percentage change in stock prices.
- Moving Averages: Displaying moving averages to smoothen stock price trends.