@@ -3,54 +3,64 @@ using Base.Test
33
44EPSILON = 0.0001
55
6+ # Check that there is no problem of definition
67@testset " Risk measure definition" begin
78 @test isa (Expectation (), RiskMeasure)
89 @test isa (WorstCase (), RiskMeasure)
9- for i in 0 : 10
10- @test isa (CVaR (i/ 10 ), RiskMeasure)
11- for j in 0 : 10
12- @test isa (ConvexCombi (i/ 10 , j/ 10 ), RiskMeasure)
13- end
14- end
10+ @test isa (AVaR (0 ), RiskMeasure)
11+ @test isa (AVaR (0.5 ), RiskMeasure)
12+ @test isa (AVaR (1 ), RiskMeasure)
13+ @test isa (ConvexCombi (0 ,0 ), RiskMeasure)
14+ @test isa (ConvexCombi (0 ,1 ), RiskMeasure)
15+ @test isa (ConvexCombi (1 ,0 ), RiskMeasure)
16+ @test isa (ConvexCombi (1 ,1 ), RiskMeasure)
17+ @test isa (ConvexCombi (0.5 ,0.5 ), RiskMeasure)
1518end
1619
17-
20+ # Test limit cases
21+ # An AVaR with beta = 0 is a WorstCase
22+ # An AVaR with beta = 1 is an Expectation
23+ # A ConvexCombi with lambda = 0 is an AVaR
24+ # A ConvexCombi with lambda = 1 is an Expectation
1825@testset " Equality formulations" begin
19- @testset " Equality WorstCase CVaR(1 )" begin
26+ @testset " Equality WorstCase AVaR(0 )" begin
2027 n = 100
2128 prob = 1 / n* ones (n)
22- @test sum (abs .(change_proba_risk (prob,CVaR ( 1 ),1 : n)- change_proba_risk (prob,WorstCase (),1 : n)) .<= EPSILON* ones (n)) == n
29+ @test sum (abs .(argsup_proba_risk (prob,AVaR ( 0 ),1 : n)- argsup_proba_risk (prob,WorstCase (),1 : n)) .<= EPSILON* ones (n)) == n
2330 end
2431
25- @testset " Equality Expectation CVaR(0 )" begin
32+ @testset " Equality Expectation AVaR(1 )" begin
2633 n = 100
2734 prob = 1 / n* ones (n)
28- @test sum (abs .(change_proba_risk (prob,CVaR (0 ),1 : n)- change_proba_risk (prob,Expectation (),1 : n)) .<= EPSILON* ones (n)) == n
35+ @test sum (abs .(argsup_proba_risk (prob,AVaR (0 ),1 : n)- argsup_proba_risk (prob,Expectation (),1 : n)) .<= EPSILON* ones (n)) == n
2936 end
3037
3138 @testset " Equality Expectation ConvexCombi(beta,1)" begin
3239 n = 100
3340 prob = 1 / n* ones (n)
34- @test sum (abs .(change_proba_risk (prob,Expectation (),1 : n)- change_proba_risk (prob,ConvexCombi (rand (),1 ),1 : n)) .<= EPSILON* ones (n)) == n
41+ @test sum (abs .(argsup_proba_risk (prob,Expectation (),1 : n)- argsup_proba_risk (prob,ConvexCombi (rand (),1 ),1 : n)) .<= EPSILON* ones (n)) == n
3542 end
3643
37- @testset " Equality CVaR (beta) ConvexCombi(beta,0)" begin
44+ @testset " Equality AVaR (beta) ConvexCombi(beta,0)" begin
3845 n = 100
3946 beta = rand ()
4047 prob = 1 / n* ones (n)
41- @test sum (abs .(change_proba_risk (prob,CVaR (beta),1 : n)- change_proba_risk (prob,ConvexCombi (beta,0 ),1 : n)) .<= EPSILON* ones (n)) == n
48+ @test sum (abs .(argsup_proba_risk (prob,AVaR (beta),1 : n)- argsup_proba_risk (prob,ConvexCombi (beta,0 ),1 : n)) .<= EPSILON* ones (n)) == n
4249 end
4350
44- @testset " Right sense of CVaR" begin
45- betamin = rand ()/ 2
46- betamax = rand ()/ 2 + 0.5
51+ # Check that in the case of minimization, AVaR find the worst costs
52+ @testset " Right sense of AVaR" begin
53+ betamax = rand ()/ 2
54+ betamin = rand ()/ 2 + 0.5
4755 n = 100
4856 prob = 1 / n* ones (n)
49- @test change_proba_risk (prob, CVaR (betamax), 1 : n)' * (n: - 1 : 1 ) - change_proba_risk (prob, CVaR (betamin), 1 : n)' * (n: - 1 : 1 ) >= 0
57+ @test argsup_proba_risk (prob, AVaR (betamax), 1 : n)' * (n: - 1 : 1 ) - argsup_proba_risk (prob, AVaR (betamin), 1 : n)' * (n: - 1 : 1 ) >= 0
5058 end
5159end
5260
53- @testset " Equality CVaR linear program" begin
61+ # AVaR can be computed as a linear program
62+ # We check equality between the formulation of Rockafellar and Urysev
63+ @testset " Equality AVaR linear program" begin
5464 n = 100
5565 X = rand (- 100 : 100 ,100 )
5666 beta = rand ()
6373
6474 @constraint (m, theta[1 : n] .>= X[1 : n] - alpha)
6575
66- @objective (m, Min, alpha + 1 / (1 - beta)* sum (prob[i]* theta[i] for i in 1 : n))
76+ @objective (m, Min, alpha + 1 / (beta)* sum (prob[i]* theta[i] for i in 1 : n))
6777
6878 status = solve (m)
6979
70- probaCVaR = change_proba_risk (prob, CVaR (beta), sortperm (X, rev = true ))
80+ probaAVaR = argsup_proba_risk (prob, AVaR (beta), sortperm (X, rev = true ))
7181
72- @test abs (probaCVaR ' * X - getobjectivevalue (m)) <= EPSILON
82+ @test abs (probaAVaR ' * X - getobjectivevalue (m)) <= EPSILON
7383end
0 commit comments