#python program to download data from yahoo finance and plot it # (c) Gabriel Turinici 2023 # Acknowledgements : program model coherent with chatGPT suggestions import yfinance as yf import matplotlib.pyplot as plt def download_stock_data(symbols, start_date, end_date): data = yf.download(symbols, start=start_date, end=end_date) return data['Close'] def plot_stock_data(data, symbols): plt.figure(figsize=(10, 6)) for symbol in symbols: plt.plot(data[symbol], label=f'{symbol} Close Price') plt.title('Stock Prices') plt.xlabel('Date') plt.ylabel('Price (USD)') plt.legend() plt.show() if __name__ == "__main__": # Define the list of stock symbols, start date, and end date stock_symbols = ['AAPL', 'GOOGL', 'MSFT'] start_date = '2022-01-01' end_date = '2023-01-01' # Download stock data stock_data = download_stock_data(stock_symbols, start_date, end_date) # Display the first few rows of the data print(stock_data.head()) # Plot stock data plot_stock_data(stock_data, stock_symbols)