% Example computations for the VSE index problem % 1500 stocks, updates for 22 months with 3000 per day % initial index value = 1000.000 % 4 different update variants: floor (If), ceil (Ic), % rounding (Ir), exact double precision (Ie) n = 1500; nUpdPerDay = 2*n; nDays = 440; r = 0.0001; % stock update range (percent) If = 1000; Ic = 1000; Ie = 1000; Ir = 1000; sp = 50+10*(1:n)/n; % stock prices unif. distr. [50,60] w = sum(sp)/1000; % weight w for all stock prices rng('default'); % random number generator settings % compute stock changes: for j = 1:nUpdPerDay*nDays k = randi(n,1,1); % update random stock price z = (1-2*rand(1)) * r; % random change in price: [-r,r] z = sp(k)*z; % absolute change in stock price sp(k) = sp(k) + z; z = z/w; % weighted change in stock price % changes in the index (4 variants) If = floor((If+z)*1000) / 1000; Ic = ceil( 1000*(Ic+z)) / 1000; Ir = round(1000*(Ir+z)) / 1000; Ie = Ie+z; end % compute direct index values (no updates) I = sum(sp)/w; Iw = sum(sp/w); % output to command line: error compared to I floor([If, Ic, Ir, Ie, Iw, I]*1000) [I-If, Ic-I, Ir-I, Ie-I, Iw-I]