dysonance / Strategems.jl

Quantitative systematic trading strategy development and backtesting in Julia
Other
163 stars 39 forks source link

get_run_params is broken #14

Closed femtotrader closed 6 years ago

femtotrader commented 6 years ago
julia> using Strategems

julia> arg_names     = [:fastlimit, :slowlimit]
2-element Array{Symbol,1}:
 :fastlimit
 :slowlimit

julia> arg_defaults  = [0.5, 0.05]
2-element Array{Float64,1}:
 0.5 
 0.05

julia> arg_ranges    = [0.01:0.01:0.99, 0.01:0.01:0.99]
2-element Array{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},1}:
 0.01:0.01:0.99
 0.01:0.01:0.99

julia> paramset      = ParameterSet(arg_names, arg_defaults, arg_ranges)
Parameters:
    (1) fastlimit  →  0.5  ∈  {0.01:0.01:0.99} :: Float64
    (2) slowlimit  →  0.05  ∈  {0.01:0.01:0.99} :: Float64

julia> get_run_params(paramset)
ERROR: function get_param_combos does not accept keyword arguments
Stacktrace:
 [1] kwfunc(::Any) at ./boot.jl:237
 [2] #get_run_params#4(::Int64, ::Function, ::Strategems.ParameterSet) at /home/femto/.julia/v0.6/Strategems/src/paramset.jl:50
 [3] get_run_params(::Strategems.ParameterSet) at /home/femto/.julia/v0.6/Strategems/src/paramset.jl:49
dysonance commented 6 years ago

@femtotrader Out of curiosity, why might this be a desired feature?

femtotrader commented 6 years ago

n_runs have a default value, I think only keyword arguments can have default value, not positionnal arguments

dysonance commented 6 years ago

Positional arguments can have a default value. It's just that the default value cannot be changed by name, only by position.

julia> f(a, b::Int=1) = a + b
f (generic function with 2 methods)

julia> a = rand(3,3)
3×3 Array{Float64,2}:
 0.677264  0.910714  0.818402
 0.638666  0.976895  0.98091
 0.939763  0.105193  0.575674

julia> f(a)
3×3 Array{Float64,2}:
 1.67726  1.91071  1.8184
 1.63867  1.97689  1.98091
 1.93976  1.10519  1.57567

julia> f(a, 2)
3×3 Array{Float64,2}:
 2.67726  2.91071  2.8184
 2.63867  2.97689  2.98091
 2.93976  2.10519  2.57567
femtotrader commented 6 years ago

There is an inconsistancy between 2 function calls

get_run_params calls get_param_combos with n_runs as keyword argument (which lead to an error that I'm fixing in #15 )

On the other side, optimize and optimize! call get_param_combos with n_runs as positional argument

So anyway I think there is a fix to do.

femtotrader commented 6 years ago

Renaming issue "get_run_params is broken" because a fix can be done without adding a keyword argument to get_param_combos

dysonance commented 6 years ago

Pull request merged, closing this now.