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

Dispatch on now

Open milktrader opened this issue 8 years ago • 3 comments

Add a TimeType argument to all the indicators that produces a scalar (or boolean) result.

For example, the sma method would look like this:

function sma{T,N}(ta::TimeArray{T,N}, n::Int, now::TimeType)
    t = find(ta.timestamp .== now)[1]
    mean(ta.values[t-n:t])
end

And it would function like this:

julia> dt = Date(2001,12,31)
2001-12-31

julia> sma(cl, 10, dt)
21.323636363636368

milktrader avatar Oct 27 '16 13:10 milktrader

I guess we can use macro to implement this feature?

iblislin avatar May 14 '17 07:05 iblislin

Something like a @now macro could work. Are you working on this @milktrader?

alexandrebrilhante avatar Jul 28 '18 20:07 alexandrebrilhante

Now, I have a more clear idea about implementing this and #52: Put an option struct at the head of all the function body. e.g.

struct Option
 ...
end

function ta_args(opt)  # return the args need to be passed to TimeArray functions, e.g. `padding`
...
end

function myma(...; ..., kw...)
  opt = Option(kw...)
  lag(...; ta_args(opt)...)
  ...
end

and the functionta_args can be implemented as a macro.

iblislin avatar Jul 29 '18 10:07 iblislin