Skip to content

Instantly share code, notes, and snippets.

@milktrader
Created January 7, 2014 03:05
Show Gist options
  • Save milktrader/8294066 to your computer and use it in GitHub Desktop.
Save milktrader/8294066 to your computer and use it in GitHub Desktop.
Iterating across parameters in naive backtest script in Julia
julia> using Series, MarketTechnicals, Jig.Quant
julia> fast = [5:15]; slow = [20:2:40];
julia> dailyreturn = percentchange(cl, method="log");
julia> for f in fast
for s in slow
sig = sma(cl,f) .> sma(cl,s)
when(dailyreturn, index(istrue(sig))) |> x -> sum(value(x)) |> expm1 |> x -> print(f," ",s," ",round(x,2), " -- ")
end
end
5 20 0.21 -- 5 22 0.15 -- 5 24 0.22 -- 5 26 0.18 -- 5 28 0.14 -- 5 30 0.16 -- 5 32 0.17 -- 5 34 0.2 -- 5 36 0.16 -- 5 38 0.2 -- 5 40 0.21 -- 6 20 0.18 -- 6 22 0.24 -- 6 24 0.18 -- 6 26 0.16 -- 6 28 0.13 -- 6 30 0.12 -- 6 32 0.15 -- 6 34 0.17 -- 6 36 0.17 -- 6 38 0.21 -- 6 40 0.21 -- 7 20 0.18 -- 7 22 0.19 -- 7 24 0.2 -- 7 26 0.15 -- 7 28 0.17 -- 7 30 0.16 -- 7 32 0.15 -- 7 34 0.17 -- 7 36 0.17 -- 7 38 0.18 -- 7 40 0.16 -- 8 20 0.14 -- 8 22 0.1 -- 8 24 0.17 -- 8 26 0.17 -- 8 28 0.14 -- 8 30 0.09 -- 8 32 0.08 -- 8 34 0.13 -- 8 36 0.11 -- 8 38 0.11 -- 8 40 0.1 -- 9 20 0.09 -- 9 22 0.11 -- 9 24 0.12 -- 9 26 0.18 -- 9 28 0.12 -- 9 30 0.08 -- 9 32 0.09 -- 9 34 0.08 -- 9 36 0.08 -- 9 38 0.08 -- 9 40 0.09 -- 10 20 0.02 -- 10 22 0.04 -- 10 24 0.1 -- 10 26 0.09 -- 10 28 0.09 -- 10 30 0.06 -- 10 32 0.04 -- 10 34 0.07 -- 10 36 0.07 -- 10 38 0.09 -- 10 40 0.13 -- 11 20 0.03 -- 11 22 0.03 -- 11 24 0.08 -- 11 26 0.1 -- 11 28 0.08 -- 11 30 0.03 -- 11 32 0.04 -- 11 34 0.08 -- 11 36 0.06 -- 11 38 0.12 -- 11 40 0.13 -- 12 20 0.03 -- 12 22 0.07 -- 12 24 0.06 -- 12 26 0.08 -- 12 28 0.02 -- 12 30 0.05 -- 12 32 0.07 -- 12 34 0.07 -- 12 36 0.08 -- 12 38 0.12 -- 12 40 0.13 -- 13 20 0.03 -- 13 22 0.05 -- 13 24 0.04 -- 13 26 0.08 -- 13 28 0.11 -- 13 30 0.04 -- 13 32 0.04 -- 13 34 0.09 -- 13 36 0.08 -- 13 38 0.07 -- 13 40 0.08 -- 14 20 0.05 -- 14 22 0.03 -- 14 24 0.04 -- 14 26 0.09 -- 14 28 0.12 -- 14 30 0.06 -- 14 32 0.07 -- 14 34 0.07 -- 14 36 0.06 -- 14 38 0.01 -- 14 40 0.05 -- 15 20 0.05 -- 15 22 0.05 -- 15 24 0.09 -- 15 26 0.14 -- 15 28 0.09 -- 15 30 0.03 -- 15 32 0.01 -- 15 34 0.06 -- 15 36 0.06 -- 15 38 0.07 -- 15 40 0.08 --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment