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

Improve return_type method #9

Merged
merged 9 commits into from
Aug 22, 2024
Merged

Improve return_type method #9

merged 9 commits into from
Aug 22, 2024

Conversation

artememelin
Copy link
Contributor

Pull request checklist

  • Did you bump the project version?
  • Did you add a description to the Pull Request?
  • Did you add new tests?
  • Did you add reviewers?

@artememelin artememelin self-assigned this Aug 22, 2024
@artememelin artememelin requested a review from gryumov as a code owner August 22, 2024 12:28
@artememelin
Copy link
Contributor Author

artememelin commented Aug 22, 2024

using Dates
using TimeArrays

struct Trade
    price::Float64
    volume::Float64
end

function w_avg(p::AbstractVector{Trade})
    return sum(x -> x.price * x.volume, p) / sum(x -> x.volume, p)
end

function TimeArrays.return_type(::typeof(w_avg), ::Type{T}) where {T<:Trade}
    return Float64
end

t_array = TimeArray([
   TimeTick(DateTime("2024-01-02"), Trade(1.0, 10)),
   TimeTick(DateTime("2024-01-03"), Trade(2.0, 20)),
   TimeTick(DateTime("2024-01-05"), Trade(3.0, 30)),
   TimeTick(DateTime("2024-01-06"), Trade(4.0, 40)),
   TimeTick(DateTime("2024-01-09"), Trade(5.0, 50)),
])

ta_rolling(w_avg, t_array, Day(3))

Copy link

📘 A preview of the documentation will be here soon

@gryumov gryumov changed the title [Enhancement] Improve return_type method Improve return_type method Aug 22, 2024
@gryumov gryumov merged commit 6f24b76 into master Aug 22, 2024
6 checks passed
@gryumov gryumov deleted the enhancement/return_type branch August 22, 2024 15:55
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

Successfully merging this pull request may close these issues.

2 participants