MarketData.jl icon indicating copy to clipboard operation
MarketData.jl copied to clipboard

Support for multiple tickers / adding ticker to result

Open nilshg opened this issue 3 years ago • 7 comments

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?

nilshg avatar Apr 19 '21 09:04 nilshg

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.

Arkoniak avatar Apr 19 '21 11:04 Arkoniak

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.

iblislin avatar Apr 19 '21 12:04 iblislin

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))...)

Arkoniak avatar Apr 19 '21 13:04 Arkoniak

yeah, with the additional kwarg supported

iblislin avatar Apr 19 '21 13:04 iblislin

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

iblislin avatar Apr 19 '21 13:04 iblislin

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.

chiraganand avatar Oct 21 '22 14:10 chiraganand

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.

Arkoniak avatar Oct 24 '22 08:10 Arkoniak