jmfernandes / robin_stocks

This is a library to use with Robinhood Financial App. It currently supports trading crypto-currencies, options, and stocks. In addition, it can be used to get real time ticker information, assess the performance of your portfolio, and can also get tax documents, total dividends paid, and more. More info at
http://www.robin-stocks.com
MIT License
1.72k stars 465 forks source link

The sum of all the 5 minute or 1 hour volume data does not add upto the daily volume data #484

Open fsagir123 opened 4 months ago

fsagir123 commented 4 months ago

I have been trying to get the volume traded from the begining of market hours until the current time on a trading day. To check if adding the 5 minute or 1 hour volumes add correctly to estimate the volume traded for a day I tested it for TSLA and AAPL for July 19th 2024. But the results show that they are highly divergent.

The daily volumes are more than twice the sum of the 5 minute or 1 hour for TSLA and more than thrice for AAPL. Is this an issue with robin_stocks or with the app itself? Is there another way to find the total volume traded up until the current time using any other method?

I have attached the below excel files which show the discrepency. The last line is the volume extracted from add the 5 minute or 1 hour data and the second last line is extracted from the get_historical_data for the previous day.

RF_past_year_AAPL_data_with_prediction.xlsx RF_past_year_TSLA_data_with_prediction.xlsx

I used the below code to extract that day's trading data if interval == "day":

    stock_data_shorter_interval = rs.get_stock_historicals(stock_ticker, interval=shorter_interval, span=interval, bounds="trading")
    stock_data_shorter_interval = pd.DataFrame.from_dict(stock_data_shorter_interval)
    stock_data_shorter_interval[['close_price', 'high_price','low_price','open_price','volume']] = stock_data_shorter_interval[['close_price', 
    'high_price','low_price','open_price','volume']].apply(pd.to_numeric, errors='coerce')

    todays_data = pd.DataFrame({'open_price':[stock_data_shorter_interval['open_price'].iloc[0]],
               'high_price':[stock_data_shorter_interval['high_price'].max()],
               'low_price':[stock_data_shorter_interval['low_price'].min()],
               'close_price':[stock_data_shorter_interval['close_price'].iloc[-1]],
               'volume':[stock_data_shorter_interval['volume'].sum()]})