Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple tickers / adding ticker to result #72

Open
nilshg opened this issue Apr 19, 2021 · 7 comments
Open

Support for multiple tickers / adding ticker to result #72

nilshg opened this issue Apr 19, 2021 · 7 comments

Comments

@nilshg
Copy link

nilshg commented Apr 19, 2021

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

yeah, with the additional kwarg supported

@iblislin
Copy link
Member

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

@chiraganand
Copy link

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
Copy link
Member

Well, I still believe that approach proposed in #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants