stocks = ["MSFT", "GOOGL", "AMZN", "TSLA", "META", "NVDA", "JPM", "UNH", "V", "MA",…
- User
stocks = ["MSFT", "GOOGL", "AMZN", "TSLA", "META", "NVDA", "JPM", "UNH", "V", "MA", "HD", "KO", "PFE", "JNJ", "WMT", "DIS", "BAC", "MCD", "VZ"]
Define the dictionary to store historical prices
historical_prices = {}
Download the historical prices data
for stock in stocks: ticker = yf.Ticker(stock) historical_prices[stock] = ticker.history(start="2022-01-01", end="2022-12-31") replace the code to fetch from vag website
- Assistant
To fetch historical stock prices from a website, you need to find a source that provides the data in a format that can be easily accessed and parsed. Once you have identified a suitable website and its data format, you can use Python libraries like
BeautifulSouporrequeststo scrape the data from the website.Here's an example of how you can modify the code to fetch historical prices from a website instead of using the Yahoo Finance API: