Skip to content

Commit 71c3625

Browse files
committed
benchmarks
1 parent e457e8e commit 71c3625

File tree

5 files changed

+56
-43
lines changed

5 files changed

+56
-43
lines changed

benchmark/bench_impv.jl

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ d = 0.01;
1010
price = blsprice(S0, K, r, T, sigma, d);
1111
inputs = [S0, K, r, T, price, d];
1212
output = similar(inputs);
13-
suite["implied volatility"] = @benchmarkable blsimpv($S0, $K, $r, $T, $price, $d)
14-
suite["implied volatility forward"] = @benchmarkable @views ForwardDiff.gradient!(output, x -> blsimpv(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
15-
suite["implied volatility ReverseDiff"] = @benchmarkable @views ReverseDiff.gradient(x -> blsimpv(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
13+
suite["evaluation"] = @benchmarkable blsimpv($S0, $K, $r, $T, $price, $d)
14+
suite["forward"] = @benchmarkable @views ForwardDiff.gradient!(output, x -> blsimpv(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
15+
suite["ReverseDiff"] = @benchmarkable @views ReverseDiff.gradient(x -> blsimpv(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
1616
cfg = ReverseDiff.GradientConfig(similar(inputs))
1717
f_tape = ReverseDiff.compile(ReverseDiff.GradientTape(x -> blsimpv(x[1], x[2], x[3], x[4], x[5], x[6]), inputs, cfg))
18-
suite["implied volatility ReverseDiff compiled"] = @benchmarkable ReverseDiff.gradient!($output, $f_tape, $inputs);
19-
suite["implied volatility Zygote"] = @benchmarkable Zygote.gradient(blsimpv, $S0, $K, $r, $T, $price, $d);
18+
suite["ReverseDiff compiled"] = @benchmarkable ReverseDiff.gradient!($output, $f_tape, $inputs);
19+
suite["Zygote"] = @benchmarkable Zygote.gradient(blsimpv, $S0, $K, $r, $T, $price, $d);
2020

2121
spot_taylor = taylor_expand(identity, S0, order = 22)
2222
price_taylor = blsprice(spot_taylor, K, r, T, sigma, d);
23-
suite["implied volatility taylor_series"] = @benchmarkable blsimpv($spot_taylor, $K, $r, $T, $price_taylor, $d);
24-
tune!(suite)
25-
@show run(suite)
23+
suite["taylor_series"] = @benchmarkable blsimpv($spot_taylor, $K, $r, $T, $price_taylor, $d);
24+
SUITE["implied volatility"] = suite
25+
# tune!(suite)
26+
# @show run(suite)

benchmark/bench_pricer.jl

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ sigma = 0.2;
99
d = 0.01;
1010
inputs = [S0, K, r, T, sigma, d];
1111
suite = BenchmarkGroup()
12-
suite["standard evaluation"] = @benchmarkable blsprice(S0, K, r, T, sigma, d);
12+
suite["standard"] = @benchmarkable blsprice(S0, K, r, T, sigma, d);
1313

1414
output = similar(inputs);
15-
suite["forwarddiff evaluation"] = @benchmarkable @views ForwardDiff.gradient!(output, x -> blsprice(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
15+
suite["forwarddiff"] = @benchmarkable @views ForwardDiff.gradient!(output, x -> blsprice(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
1616

17-
suite["reversediff evaluation"] = @benchmarkable @views ReverseDiff.gradient(x -> blsprice(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
17+
suite["reversediff"] = @benchmarkable @views ReverseDiff.gradient(x -> blsprice(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
1818
cfg = ReverseDiff.GradientConfig(similar(inputs))
1919
f_tape = ReverseDiff.compile(ReverseDiff.GradientTape(x -> blsprice(x[1], x[2], x[3], x[4], x[5], x[6]), inputs, cfg))
20-
suite["reversediff evaluation compiled"] = @benchmarkable ReverseDiff.gradient!($output, $f_tape, $inputs);
20+
suite["reversediff compiled"] = @benchmarkable ReverseDiff.gradient!($output, $f_tape, $inputs);
2121
# suite["implied volatility forward"] = @benchmarkable ReverseDiff.gradient(x->blsprice(x...),inputs);
2222

2323
# suite["implied volatility forward"] = @benchmarkable @views Zygote.gradient(x -> blsprice(x[1], x[2], x[3], x[4], x[5], x[6]), inputs);
24-
suite["zygote evaluation"] = @benchmarkable Zygote.gradient(blsprice, $S0, $K, $r, $T, $sigma, $d);
24+
suite["zygote"] = @benchmarkable Zygote.gradient(blsprice, $S0, $K, $r, $T, $sigma, $d);
2525
# suite["implied volatility forward"] = @benchmarkable Zygote.gradient(x->blsprice(x...),inputs);
2626

2727
spot_taylor = taylor_expand(identity, S0, order = 22)
28-
suite["taylor_series evaluation"] = @benchmarkable blsprice($spot_taylor, $K, $r, $T, $sigma, $d);
29-
tune!(suite)
30-
@show run(suite)
28+
suite["taylor_series"] = @benchmarkable blsprice($spot_taylor, $K, $r, $T, $sigma, $d);
29+
SUITE["Pricer"] = suite
30+
# tune!(suite)
31+
# @show run(suite)

benchmark/bench_vega.jl

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ sigma = 0.2;
88
d = 0.01;
99
inputs = [S0, K, r, T, sigma, d];
1010
suite = BenchmarkGroup()
11-
suite["standard evaluation vega"] = @benchmarkable blsvega($S0, $K, $r, $T, $sigma, $d);
11+
suite["standard"] = @benchmarkable blsvega($S0, $K, $r, $T, $sigma, $d);
1212
output = similar(inputs);
13-
suite["forwarddiff evaluation vega"] = @benchmarkable @views ForwardDiff.gradient!(output, x -> blsvega(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
14-
suite["reversediff evaluation vega"] = @benchmarkable @views ReverseDiff.gradient(x -> blsvega(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
13+
suite["forwarddiff"] = @benchmarkable @views ForwardDiff.gradient!(output, x -> blsvega(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
14+
suite["reversediff"] = @benchmarkable @views ReverseDiff.gradient(x -> blsvega(x[1], x[2], x[3], x[4], x[5], x[6]), $inputs);
1515
cfg = ReverseDiff.GradientConfig(similar(inputs))
1616
f_tape = ReverseDiff.compile(ReverseDiff.GradientTape(x -> blsvega(x[1], x[2], x[3], x[4], x[5], x[6]), inputs, cfg))
17-
suite["reversediff evaluation vega compiled"] = @benchmarkable ReverseDiff.gradient!($output, $f_tape, $inputs);
18-
suite["zygote evaluation vega"] = @benchmarkable @views Zygote.gradient(blsvega, $S0, $K, $r, $T, $sigma, $d);
17+
suite["reversediff compiled"] = @benchmarkable ReverseDiff.gradient!($output, $f_tape, $inputs);
18+
suite["zygote"] = @benchmarkable @views Zygote.gradient(blsvega, $S0, $K, $r, $T, $sigma, $d);
1919

2020
spot_taylor = taylor_expand(identity, S0, order = 22)
21-
suite["taylor_series evaluation vega"] = @benchmarkable blsvega($spot_taylor, $K, $r, $T, $sigma, $d);
22-
tune!(suite)
23-
@show run(suite)
21+
suite["taylor_series"] = @benchmarkable blsvega($spot_taylor, $K, $r, $T, $sigma, $d);
22+
SUITE["Vega"] = suite
23+
# tune!(suite)
24+
# @show run(suite)

benchmark/benchmarks.jl

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
using Pkg, FinancialToolbox;
2-
#get(ENV, "CI", nothing) == "true" ? Pkg.instantiate() : nothing;
3-
path1 = joinpath(dirname(pathof(FinancialToolbox)), "..", "benchmark")
4-
test_listTmp = readdir(path1);
5-
BlackList = ["Project.toml", "benchmarks.jl", "runner.jl", "cuda", "af", "Manifest.toml", "bench_kou_rev_diff_grad.jl", "bench_black_mp.jl", "bench_black_mn.jl", "bench_black_mt.jl"]
6-
test_list = [test_element for test_element in test_listTmp if !Bool(sum(test_element .== BlackList))]
7-
println("Running tests:\n")
8-
function eval_current_file(path1,current_test, i,test_list)
9-
println("------------------------------------------------------------")
10-
println(" * $(current_test) *")
11-
include(joinpath(path1, current_test))
12-
println("------------------------------------------------------------")
13-
if (i < length(test_list))
14-
println("")
15-
end
16-
end
17-
for (current_test, i) in zip(test_list, 1:length(test_list))
18-
eval_current_file(path1,current_test, i,test_list)
19-
end
1+
using BenchmarkTools
2+
using Random
3+
4+
const SUITE = BenchmarkGroup()
5+
include("bench_pricer.jl")
6+
include("bench_vega.jl")
7+
include("bench_impv.jl")
8+
9+
# SUITE["utf8"] = BenchmarkGroup(["string", "unicode"])
10+
# teststr = String(join(rand(MersenneTwister(1), 'a':'d', 10^4)))
11+
# SUITE["utf8"]["replace"] = @benchmarkable replace($teststr, "a" => "b")
12+
# SUITE["utf8"]["join"] = @benchmarkable join($teststr, $teststr)
13+
# SUITE["utf8"]["plots"] = BenchmarkGroup()
14+
15+
# SUITE["trigonometry"] = BenchmarkGroup(["math", "triangles"])
16+
# SUITE["trigonometry"]["circular"] = BenchmarkGroup()
17+
# for f in (sin, cos, tan)
18+
# for x in (0.0, pi)
19+
# SUITE["trigonometry"]["circular"][string(f), x] = @benchmarkable ($f)($x)
20+
# end
21+
# end
22+
23+
# SUITE["trigonometry"]["hyperbolic"] = BenchmarkGroup()
24+
# for f in (sin, cos, tan)
25+
# for x in (0.0, pi)
26+
# SUITE["trigonometry"]["hyperbolic"][string(f), x] = @benchmarkable ($f)($x)
27+
# end
28+
# end

benchmark/tune.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"Julia":"1.9.3","BenchmarkTools":"1.0.0"},[["BenchmarkGroup",{"data":{"Vega":["BenchmarkGroup",{"data":{"forwarddiff":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":205,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"reversediff compiled":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":10,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"reversediff":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":5,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"zygote":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":909,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"standard":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":990,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"taylor_series":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":8,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}],"Pricer":["BenchmarkGroup",{"data":{"forwarddiff":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":199,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"reversediff compiled":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":10,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"reversediff":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":3,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"zygote":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":898,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"standard":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":930,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"taylor_series":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":6,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}],"implied volatility":["BenchmarkGroup",{"data":{"forward":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":70,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"ReverseDiff compiled":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":10,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"Zygote":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":97,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"ReverseDiff":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"evaluation":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":207,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"taylor_series":["Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}]},"tags":[]}]]]

0 commit comments

Comments
 (0)