File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import yfinance as yf
22import pandas as pd
3- from typing import Optional
43
54def fetch_crypto_data (
6- symbol : str = "BTC-USD" ,
7- period : str = "2y" ,
5+ symbol : str = "BTC-USD" ,
6+ period : str = "2y" ,
87 interval : str = "1d"
98) -> pd .DataFrame :
109 """
11- Fetches historical crypto data from Yahoo Finance and formats it
10+ Fetches historical crypto data from Yahoo Finance and formats it
1211 specifically for the QuantRL-Lab environment.
13-
12+
1413 Args:
1514 symbol: The cryptocurrency ticker (e.g., 'BTC-USD', 'ETH-USD').
1615 period: Data period to download (e.g., '1mo', '1y', 'max').
1716 interval: Data interval (e.g., '1d', '1h', '15m').
18-
17+
1918 Returns:
2019 pd.DataFrame: OHLCV dataframe formatted with float32 for RL agents.
2120 """
2221 ticker = yf .Ticker (symbol )
2322 df = ticker .history (period = period , interval = interval )
24-
23+
2524 if df .empty :
2625 raise ValueError (f"No data found for symbol { symbol } . Check if the ticker is correct." )
2726
@@ -37,4 +36,4 @@ def fetch_crypto_data(
3736 df .index = df .index .tz_localize (None )
3837
3938 # Cast to float32 for Neural Network memory efficiency
40- return df .astype ("float32" )
39+ return df .astype ("float32" )
You can’t perform that action at this time.
0 commit comments