You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: StationaryDist_FHorz_Case1_RiskyAsset_Iteration_e_raw.m
    path of file: ./repos/VFIToolkit-matlab/StationaryDist/FHorz/RiskyAsset
    
    the code of the file until where you have to start completion: function StationaryDistKron=StationaryDist_FHorz_Case1_RiskyAsset_Iteration_e_raw(jequaloneDistKron,AgeWeightParamNames,PolicyKron,n_d,n_a,n_z,n_e,n_u,N_j,d_grid,a_grid,u_grid,pi_z_J,pi_e_J,pi_u,aprimeFn,Parameters,aprimeFnParamNames,simoptions)
% Case3: aprime(d,u)
% Will treat the agent
    
function and the transition fn for exogenous shocks)
        P=zeros(N_a,N_z,N_e,N_a,N_z); %P(a,z,e,aprime,zprime)=proby of going to (a',z') given in (a,z,e)
        for a_c=1:N_a
            for z_c=1:N_z
                for e_c=1:N_e
                    optd=PolicyKron(a_c,z_c,e_c,jj);
                    for zprime_c=1:N_z
                        for u_c=1:N_u
                            optaprime=aprimeIndex(optd+N_d*(u_c-1)); % Case3; a'(d,u)
                            % Add to lower grid point
                            P(a_c,z_c,e_c,optaprime,zprime_c)=P(a_c,z_c,e_c,optaprime,zprime_c)+aprimeProbs(u_c)*pi_u(u_c)*pi_z(z_c,zprime_c)/sum(pi_z(z_c,:));
                            % Add to upper grid point
                            P(a_c,z_c,e_c,optaprime,zprime_c)=P(a_c,z_c,e_c,optaprime,zprime_c)+(1-aprimeProbs(u_c))*pi_u(u_c)*pi_z(z_c,zprime_c)/sum(pi_z(z_c,:));
                        end