Hello,
Below is the practice code for the scenario tree model. I can not run out the result. Would you help me find out where has the problem.
Thank you!
model file:
param T; # number of periods
set investments; # different investment options
set periods:=1..T;
param initwealth; # initial holdings
param target; # target value G at time T
param invest; # value of investing ABOVE target value
param penalty; # penalty for not meeting target
#Parameters to define the random structure
param realizations{t in periods}>0 integer;
param return{k in investments,t in periods, s in 1..realizations[t]}>0; # return on each inv
param cond_prob{t in periods, s in 1..realizations[t]}<=1;
#Auxiliary sets and parameters for easier manipulation of scenarios
param branches{t in 1..T+1}:= (if t<=T then prod{s in t..T}realizations[s] else 1);
set scenarios:= 0..(prod{t in periods}realizations[t]-1);
param starttime{j in scenarios}:=min{t in 1..T+1: (j mod branches[t])=0}t;
param parent{j in scenarios}:=(if j = 0 then 0 else j-(j mod branches[starttime[j]-1]));
set event_nodes:={j in scenarios, t in 1..T+1:t>= starttime [j]};
param rv_address{(j,t) in event_nodes:t>1}:=(((j-(j mod branches[t]))/ branches[t]) mod realizations[t-1])+1;
param previous{(j,t) in event_nodes:t>1}:=( if t=starttime[j] then parent[j] else j );
param path_prob{(j,t) in event_nodes}:=(if t=1 then 1 else path_prob[previous[j,t] ,t-1]*cond_prob[t-1,rv_address[j,t]]);
# variables
var amtinvest{investments,t in periods,s in scenarios:starttime[s]<= t}>= 0; #actual amounts inv’d
var above_target{s in scenarios}>= 0; # amt above final target
var below_target{s in scenarios}>= 0; # amt below final target
# objective
maximize Exp_value:
sum{s in scenarios, (j,t) in event_nodes}path_prob[j,t]*(invest*above_target[s]-penalty*below_target[s]);
# constraints
subject to budget{s in scenarios}:
sum{k in investments}amtinvest[k,1,0]=initwealth;
subject to balance{k in investments,t in 2..T, (s,t) in event_nodes:t>1}:
amtinvest[k,t,s]=return[k,t-1,rv_address[s,t]]*amtinvest[k,t-1,previous[s,t]];
subject to stage{s in scenarios,t in T..T}:
sum{k in investments}return[k,T,s]*amtinvest[k,T,s]-above_target[s]+below_target[s]=target;
Data file
set investments:=stock bond; # different investment options
param T:=3; # number of periods
param realizations:= 1 2
2 2
3 2;
param initwealth:=55000;
param target:=80000; # target value G at time T
param invest:=1; # value of investing beyond target value
param penalty:=4; # penalty for not meeting target
param return:=
[stock,*,*]: 1 2:=
1 1.25 1.06
2 1.25 1.06
3 1.25 1.06
[bond,*,*]: 1 2:=
1 1.12 1.03
2 1.12 1.03
3 1.12 1.03;
param cond_prob:=
[1,*] 1 0.5 2 0.5
[2,*] 1 0.25 2 0.25
[3,*] 1 0.125 2 0.125;