Spaces:
Running
Running
File size: 1,037 Bytes
329fec8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
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())
|