AI4Finance-Foundation / FinRL

FinRL: Financial Reinforcement Learning. 🔥
https://ai4finance.org
MIT License
9.61k stars 2.33k forks source link

FinRL_Explainable_DRL_For_Portfolio_Management_An_Empirical_Approach.ipynb #427

Closed alialahyari closed 2 years ago

alialahyari commented 2 years ago

I have two questions: 1-I ran the Jupyter notebook (FinRL_Explainable_DRL_For_Portfolio_Management_An_Empirical_Approach.ipynb)on my task and got the following error Screenshot (96) 2- You know how to access minute cryptocurrency data using the yfinance library? And how can I use minute or hourly data in this task? Because inside the module defined for yfinance in the FinRL/blob/master/finrl/finrl_meta/preprocessor/yahoodownloader.py gateway file, there is no argument as an interval so that I can extract minute or hourly data, and by default you can only download daily data. Thanks for guiding me

Athe-kunal commented 2 years ago

Hello @alialahyari. Try going through this tutorial. Here you can see how to instantiate a DataProcessor and pass time_interval to download data from yahoofinance

alialahyari commented 2 years ago

Thank you @Athe-kunal But I had better ask what changes should I make if I want to do portfolio management using hourly data in the Jupiter notebook file

Athe-kunal commented 2 years ago

@alialahyari Alright, instead of downloading the data from yahoo finance, do this. If it does not work, do let me know.

from finrl.finrl_meta.data_processor import DataProcessor
data_source = 'yahoofinance'
time_interval = '1D' #For 1 day
def get_train_data(start_date, end_date, ticker_list, data_source, time_interval, 
          technical_indicator_list,  if_vix = True):

    #fetch data
    DP = DataProcessor(data_source, **kwargs)
    data = DP.download_data(ticker_list, start_date, end_date, time_interval)
    data = DP.clean_data(data)
    data = DP.add_technical_indicator(data, technical_indicator_list)
    if if_vix:
        data = DP.add_vix(data)
    return data
alialahyari commented 2 years ago

@Athe-kunal I used the above code but still could not access the minute or hourly data. It is possible to check the code yourself once. Maybe I did something wrong. I even used the following code(FinRL_PaperTrading_Demo.ipynb) but still got the error. Screenshot (99)

Athe-kunal commented 2 years ago

@alialahyari So okay, when I tried to access data using yahoo finance, it gave me this error

Failed download:
- TSLA: 1m data not available for startTime=1640995200 and endTime=1641945600. Only 7 days worth of 1m granularity data are allowed to be fetched per request.

So you can't really download for yahoo finance for more than 7 days. Also, pass '1m' instead of '1Min'

1 Failed download:
- TSLA: Invalid input - interval=1min is not supported. Valid intervals: [1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo]

So refer to this tutorial on Paper-trading demo and use alpaca to access minute level data. You need to login to alpaca and create an account to get the API_KEYS. Follow this tutorial to get the API_KEYS. It is a better way to access the minute level data

alialahyari commented 2 years ago

@Athe-kunal It was a great explanation. Thank you. Done.

fffanrrr commented 1 year ago

@alialahyari Do you know how to resolve problem one? Thank you!