yahoofinancelive / yliveticker

Get market data from Yahoo Finance websocket in near-real time.
MIT License
143 stars 30 forks source link

is there any existing code collecting data to generate pandas time series #15

Open FlynnMa opened 2 years ago

FlynnMa commented 2 years ago

I think most of people will need it As this lib continously report event based message, to convert into time series will make it more useful.

Or has anyone done that?

alparamonov commented 2 years ago

@FlynnMa This sounds interesting. Can you elaborate more? I could imagine using the library for pumping data into time series db with near real time and cold processing capabilities around it. But for me it is more like how you use the lib and not about implementation of the lib. What's your idea?

FlynnMa commented 2 years ago

Hi,

Here is a quick pandas based time series for example, it looks like: image

Here is piece of code fetching data use yfinance for your reference

import yfinance as yf
sym = 'AAPL'

apple = yf.Ticker(sym)
apple_dataframe = apple.history(period='1d', interval='1m')
apple_dataframe

once you got a time series based dataframe, it can be easily resampled like:

 ohlcv_dict = {
                'Open': 'first',
                'High': 'max',
                'Low': 'min',
                'Close': 'last',
                'Volume': 'sum'}
apple_dataframe = apple_dataframe .resample('10min').agg(ohlcv_dict)
alparamonov commented 2 years ago

Ok, got you. Would like this functionality to be added to this lib or better another separate lib?

FlynnMa commented 2 years ago

I would suggest add into this lib, For most data analysis, the time series based data would enable everyone's life easier, or else I am afraid all of them will need to do the data cooking before they can go.