================================================================================
  Question 44: Financial Stock Data Visualizations (Alphabet Inc.)
================================================================================

FULL QUESTION:
Task:
Visualize the following using the stock dataset (alphabet_stock_data.csv):
1. Create a line plot of the historical stock prices of Alphabet Inc. between
   two specific dates (e.g. 2020-04-01 to 2020-09-30).
2. Create a bar plot of the trading volume between the two specific dates.
3. Create a stacked histogram plot with more bins of opening, closing, high,
   and low stock prices.
4. Create a scatter plot of the trading volume vs closing stock prices.

SHORT QUESTION:
Visualizes financial time-series stock data with line, bar, stacked histogram, and scatter plots using Matplotlib.

================================================================================
README & SETUP INSTRUCTIONS:
================================================================================
# Question 44: Financial Stock Data Visualizations (Alphabet Inc.)

- Prerequisites: Python 3.x, Pandas, Matplotlib (pip install pandas matplotlib).
- Setup: Uses 'alphabet_stock_data.csv'. If missing, the script automatically generates synthetic stock records covering the target dates.
- How to Run: python question_44.py
- Expected Behavior: Reads stock data, filters by date range, and displays a multi-panel visual dashboard of stock analytics.

================================================================================
SOURCE CODE FILES:
================================================================================

1. question_44.py
--------------------------------------------------------------------------------
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('alphabet_stock_data.csv')

df['Date'] = pd.to_datetime(df['Date'])
df = df.sort_values('Date')

start_date = '2020-04-01'
end_date = '2020-09-30'

mask = (df['Date'] >= start_date) & (df['Date'] <= end_date)
filtered_df = df.loc[mask]

fig, axes = plt.subplots(2, 2, figsize=(16, 10))
fig.suptitle(f'Alphabet Inc. Stock Analysis ({start_date} to {end_date})', fontsize=16, fontweight='bold')

axes[0, 0].plot(filtered_df['Date'], filtered_df['Close'], color='#1f77b4', linewidth=2)
axes[0, 0].set_title('Historical Closing Stock Prices', fontweight='bold')
axes[0, 0].set_xlabel('Date')
axes[0, 0].set_ylabel('Price ($)')
axes[0, 0].grid(True, linestyle='--', alpha=0.6)
axes[0, 0].tick_params(axis='x', rotation=30)

axes[0, 1].bar(filtered_df['Date'], filtered_df['Volume'], color='#2ca02c', width=0.8)
axes[0, 1].set_title('Trading Volume', fontweight='bold')
axes[0, 1].set_xlabel('Date')
axes[0, 1].set_ylabel('Volume (Shares)')
axes[0, 1].grid(axis='y', linestyle='--', alpha=0.6)
axes[0, 1].tick_params(axis='x', rotation=30)

price_data = [filtered_df['Open'], filtered_df['Close'], filtered_df['High'], filtered_df['Low']]
labels = ['Open', 'Close', 'High', 'Low']
colors = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728']

axes[1, 0].hist(price_data, bins=30, stacked=True, label=labels, color=colors, alpha=0.85)
axes[1, 0].set_title('Stacked Histogram of Stock Prices (30 Bins)', fontweight='bold')
axes[1, 0].set_xlabel('Price ($)')
axes[1, 0].set_ylabel('Frequency')
axes[1, 0].legend()
axes[1, 0].grid(True, linestyle='--', alpha=0.6)

scatter = axes[1, 1].scatter(
    filtered_df['Volume'],
    filtered_df['Close'],
    c=filtered_df['Close'],
    cmap='viridis',
    alpha=0.7,
    edgecolors='w'
)
axes[1, 1].set_title('Trading Volume vs. Closing Stock Price', fontweight='bold')
axes[1, 1].set_xlabel('Volume (Shares)')
axes[1, 1].set_ylabel('Closing Price ($)')
axes[1, 1].grid(True, linestyle='--', alpha=0.6)
fig.colorbar(scatter, ax=axes[1, 1], label='Close Price ($)')

plt.tight_layout(rect=[0, 0.03, 1, 0.95])
plt.show()
--------------------------------------------------------------------------------
