JuliaQuant / MarketData.jl

Time series market data
https://juliaquant.github.io/MarketData.jl/stable/
Other
149 stars 21 forks source link

Support for multiple tickers / adding ticker to result #72

Open nilshg opened 3 years ago

nilshg commented 3 years ago

I often find myself doing something like

tickers = ["^FTSE", "^N225", "^DJI"]

result_df = DataFrame(yahoo(tickers[1]))
result_df = [fill(tickers[1], nrow(result_df)) first_ticker]

for t in tickers[2:end]
    new_df = DataFrame(yahoo(t))
    new_df = [fill(t, nrow(new_df) new_df]
    result_df = vcat(result_df, new_df)
end

Could something like this (this might not be the best way of doing it of course, just a quick hack) be implemented as a yahoo(tickers::Vector{Union{String, Symbol}}) method?

If not (and this could be a separate issue but I thought it would be a bit small) could we have a add_ticker kwarg that includes the ticker in the TimeArray that's being returned?

Arkoniak commented 3 years ago

While general solution is not yet ready, there is a one-liner which at least makes it smaller.

tickers = ["SPY", "AGG", "IEI"]

vcat(((df[!, :ticker] .= tickers[i]; df) for (i, df) in pairs(DataFrame.(yahoo.(tickers))))...)

I suppose problem with TimeArray is that ticker name can be written only as metadata. But metadata is something generic so it's not quite clear how to transform it to DataFrame in general case.

iblislin commented 3 years ago

well, TimeArray cannot have different type in single column, since the underlying implementation is Matrix. Although one can build an instance of TimeArray{Union{Float64, String}, ...}, that breaks almost all operations on it. Adding ticker to metadata field is similar to zip a variable with TimeArray, so there isn't an easy way to add the ticker in TimeArray table at this moment.

I think the code snippets can be added to document and make a quick lookup sheet.

Arkoniak commented 3 years ago

By the way, I think that if #71 is resolved, then one can extend sink with this sort of metadata. Then the resulting user code is just

vcat(DataFrame.(yahoo.(tickers))...)
iblislin commented 3 years ago

yeah, with the additional kwarg supported

iblislin commented 3 years ago

(Let me re-read that issue again :p)

chiraganand commented 2 years ago

Was there progress on this issue (multiple tickers in one call)? Looking to integrate this package with TSx.

Also, the metadata can be stored in TSx in the future because DataFrames.jl now supports storing metadata.

Arkoniak commented 2 years ago

Well, I still believe that approach proposed in https://github.com/JuliaQuant/MarketData.jl/issues/71 (with proposed https://github.com/Arkoniak/ProtoMarketData.jl approach) is still the best solution to this kind of problems. As far as I remember it worked fine as a prototype, but for some reasons it was not included as a part of JuliaQuant. Probably it's because of type piracy in aforementioned package.