www.gusucode.com > GAVPai_Book_MathworksCntrlFileEx_May2019 > GAVPai_Book_MathworksCntrlFileEx_May2019/generate_bounded_popln.m

    % To generate an initial popln of xi+ and xi-, the buy sell proportions of weights for
% portfolio rebalancing
% The buy sell weights satisfy their respective lower bounds of 0 (sell_low, buy_low)
% and the sell_high (the respective crisp portfolio weights) and buy high (fixed bounds of 0.025) bounds 


function [ popln_raw ] = generate_bounded_popln( popln_rows,popln_cols, sell_low, sell_high, buy_low, buy_high )

    for i=1:popln_cols
        a=sell_low(i);
        b= sell_high(i);
        r = a + (b-a).*rand(popln_rows,1);
        popln_raw(:,i) = -r;
    end


    for i=1:popln_cols
        a=buy_low(i);
        t= randperm(popln_rows);
        b=buy_high(i);
        r = a + (b-a).*rand(popln_rows,1);
        for j=1:popln_rows
            if rand > 0.5
            popln_raw(j,i) = r(t(j));   
            else
            continue;
            end
        end

    end
                

 end