MarketTechnicals.jl
MarketTechnicals.jl copied to clipboard
Dispatch on now
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
I guess we can use macro to implement this feature?
Something like a @now
macro could work. Are you working on this @milktrader?
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.