Spaces:
Running
Running
import yfinance as yf | |
def fetch_intraday_data(symbol, start_date, end_date): | |
""" | |
Fetches 15-minute intraday stock data for the specified symbol between start_date and end_date. | |
Parameters: | |
- symbol (str): The stock symbol to fetch data for (e.g., 'AAPL'). | |
- start_date (str): The start date for the data in 'YYYY-MM-DD' format. | |
- end_date (str): The end date for the data in 'YYYY-MM-DD' format. | |
Returns: | |
- DataFrame: Pandas DataFrame containing the intraday stock data. | |
""" | |
# Define the ticker object | |
ticker = yf.Ticker(symbol) | |
# Fetch the historical market data | |
data = ticker.history(interval="15m", start=start_date, end=end_date) | |
# Return the data | |
return data | |
if __name__ == "__main__": | |
# Example usage | |
symbol = "AAPL" # Apple Inc. | |
start_date = "2023-01-01" | |
end_date = "2023-01-31" | |
# Fetch the data | |
data = fetch_intraday_data(symbol, start_date, end_date) | |
# Display the first few rows of the data | |
print(data.head()) | |