Last active
August 30, 2025 09:26
-
-
Save scubamut/f8a7295a3559937c18b91c81ddbf4baf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import yfinance as yf | |
| from datetime import datetime, date, timedelta | |
| data = yf.download('QQQ', '2020-01-01', date.today().strftime('%Y-%m-%d')) | |
| daily_df = data['Close'] | |
| weekly_df = daily_df.resample('W-Fri').last() | |
| monthly_df = daily_df.resample('BME').last() | |
| # Create the plot | |
| plt.figure(figsize=(12, 6)) | |
| # Plot daily data with lower opacity | |
| plt.plot(daily_df.index, daily_df.values, | |
| alpha=0.3, label='Daily Values', color='blue') | |
| # Plot weekly data with solid line | |
| plt.plot(weekly_df.index, weekly_df.values, \ | |
| linewidth=2, label='Weekly Average', color='green') | |
| # Plot monthly data with solid line | |
| plt.plot(monthly_df.index, monthly_df.values, \ | |
| linewidth=2, label='Monthly Average', color='red') | |
| # Customize the plot | |
| plt.title('Daily Values vs Weekly and Monthly Average', pad=15) | |
| plt.xlabel('Date') | |
| plt.ylabel('Value') | |
| plt.grid(True, alpha=0.3) | |
| plt.legend() | |
| # Rotate x-axis labels for better readability | |
| plt.xticks(rotation=45) | |
| # Adjust layout to prevent label cutoff | |
| plt.tight_layout() | |
| # Show the plot | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment