Skip Navigation

Simulation model, version 2

This is a real big update to my simulation and reworks the entire logic of it. Though doing so allows me to investigate even more stuff. Check out the post on the old sim if you haven't seen it.

At this point, the sim has become so complex, I don't think I can explain it in as much depth as the previous one.

So I'll keep it simple and show you my assumptions, results, and code. There are 10 sectors in the economy this time (so the visualization has changed)

As always, "economic reproduction" is the condition where nobody in the economy gains or looses money by the end of the production period.

The code and pictures are in the comments.

Also, I'd like /u/Sebrof and /u/pancake@lemmygrad.ml to see this post.

Assumptions:

  1. There are no banks, governments, population growth or technological changes. None of these things are modeled yet since they distract from the point of the model, which is to see how labor prices and economic reproduction are related.

My next model will try to model these things to see if the relationship between labor prices and economic reproduction still holds

  1. The logic of this model is inverted to the last one. In the previous model, we started with a net output (sold to consumers) then calculated how much gross output would be needed (sold to consumers and to factories) to maintain this. This time, I randomly generate a gross output then compute a net output.
  2. I randomly generate 100,000 economies, each with its own technological level (the 10x10 A matrix), a set of prices (10x1 column vector), and employment in industries (10x1 vector). I assume everyone is employed. Also, this time, there is only 1 price vector per economy.
  3. For each economy, I randomly generate a "basket of consumption", which is the amount of products that its people will consume. I scale the basket so that it could be produced by half the labor of the economy, and keep the basket constant for all time.
  4. This time, there is foreign trade. If the economy produces more of a product than what is required for the basket, that's exports. Otherwise it imports.
  5. I simulate 100 time steps for each economy. Every time step, the sectors of the economy will update their prices and employment. There were many possible rules for choosing how these updates happened. I made it so that the sectors hire workers in proportion to how much money they have (divided by how much it costs to hire workers). Prices are scaled down as a sector grows (due to competition)
  6. Then I compute all the financial data (like revenues, wages, incomes, costs, trade imbalances, profits, etc) and plot it.

The important accounting identities are:

National income = Wages + trade balance

National income = Revenues of industry - Costs of industry (not including wages)

17 comments
  • ' %%%%%%%%%%

     
            time = 100;
        n = 10;
        N = 100000;
        connectivity = (2*n)^0.5; %The average number of intermediate commodities that go into making a commodity
        threshold = connectivity/n;
        e_l = 0.025;                 %proportionality rate at which hirings change per timestep
        e_p = 0.025;                 %proportionality rate at which prices can change per timestep
    
        Data = zeros([5 N*time]); %Pre allocating data matrix. Necessary to speed up simulation
        Data_final = zeros([5 N]); %Pre allocating data matrix. Holds data on final time steps of each economy
        w = 0.5; %Percentage of national production that the economy aims to give to labor
        
        %%%%%%%%%%LOOP
        
        for i = 1:N
    
            %Generate random workforce distribution between sectors
            L = rand([n time])*0.998 + 0.001;
            L(:,1) = L(:,1)./sum(L(:,1));    %Normalise the population to 1
    
            %Randomly generate direct labor use
            l = rand([n 1])*0.998 + 0.001;
            
            %Technical matrix:
            A = rand([n n]);
            A = A.*(A<=threshold);
            a = (eye(n)-A)\eye(n); %Storing the productivity matrix so it doesn't have to be recalculated over and over
    
            while sum(sum(a<0))>0     %If a has negative components, regenerate the economy and try again
                A = rand([n n]);
                A = A.*(A<=threshold);
                a = (eye(n)-A)\eye(n);
            end
    
            %LTV prices calculation
            LTV = sum(a.*l)';
    
            %Consumption
            basket = rand([n 1]);
            basket = w*basket./(sum(basket.*LTV)); %Consumption is scaled so that it can be in theory satisfied by the work of half the workforce
    
            %net production
            %o = zeros([n time]);
    
            %net income of sectors + agregate measures (pre-allocation)
            M = zeros([n time]);
            trade_balance = zeros([1 time]);
            profit_var = zeros([1 time]);
            
            %Randomised prices are generated for starting timestep (pre-allocation)
            P = zeros([n time]);
    
            %P(:,1) = rand([n 1]);             %randomly generates a set of prices
    
            
            %P(:,1) = (eye(n) - A - Cw)\rand([n 1]);
            P(:,1) = rand([n 1]);
    
            for k = 1:time
                
                if k>1
                    hirings = e_l*(M(:,k-1))/sum(basket.*P(:,k-1));  %New Hirings are in proportion to the income available divided by wages
                    L(:,k) = L(:,k-1) + hirings;   
                    L(:,k) = L(:,k).*(L(:,k)>=(0.001/n)) + (L(:,k)<(0.001/n))*(0.01/n);   %This puts a floor on the size of sectors. Helps prevent the code from exploding.
                    P(:,k) = P(:,k-1).*(1 - e_p*(hirings./L(:,k-1)));  %If the size of a sector doubles, the price decreases by e_p percent (from competititon)
                    
                    L(:,k) = L(:,k)./sum(L(:,k));    
                end
    
                P(:,k) = P(:,k).*((P(:,k)>=(0.001))) + (P(:,k)<(0.001))*(0.01);   %This puts a floor on the price. Helps prevent the code from exploding.
    
                %Calculate gross output of industries
                O = L(:,k)./l;
    
                P(:,k) = P(:,k)./sum(O.*P(:,k));%Normalises these prices so that total economy wide revenue is always 1
    
                Cw = basket * l';
                profit_var(:,k) = var(((eye(n) - A - Cw)*P(:,k))./P(:,k));
    
                %Calculate net production
                o = O - A*O;       %Net production can be negative. We will assume the existence of imports
                                        %negative net production will show up as
                                        %negative sales (the external market is
                                        %selling to the economy)
        
                %Inter-industry sales
                R = O.*P(:,k);  %Market value of gross production by sector
                C = A' .*O*P(:,k); %Costs of inputs to production by sector
                
                %Industry to market sales
                S = o.*P(:,k); %Sales to consumers by sector
                Y = sum(S); %Total industry income from market sales
                            %Under balanced conditions, this income would be
                            %exactly matched by industry outflows to consumers
                            %(wages + dividends)
        
                            %Here it is assumed that the industry pays enough in
                            %(wages + dividends) to afford a fixed basket of 
                            % consumption.
        
                            %Any leftover income is the trade balance
        
                trade_balance(k) = sum((o - basket).*P(:,k));
        
                W = L(:,k).*(sum(basket.*P(:,k))); %Wages paid out vector by industry
                
                M(:,k) = R - C - W; %Net Income by industry
                
                M_per_worker = (1/n)*M./L(:,k); %I want to see if this givees any interesting results
    
                %Accounting identities
                % Y = sum(W) + trade_balance
                %Y = sum(R - C)
    
            end 
            %%%%%%%%%%%%%%Computing more time steps%%%%%%%%%%%%%%%%%%%%%%%%
            
            
            %%%%%%%%%%%%%Processing data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
            %poopoo = LTV./LTV(1,:); 
            %Peepee = P./P(1,:); 
    
            ratios = P./LTV;
            ratios = log(ratios);
            ratios = ratios - mean(ratios);
            specific_price = sum(abs(ratios))/n;
    
            M = sum(abs(M));
            M_per_worker = sum(abs(M_per_worker));
            
            %specific_price = sum(abs(log(Peepee./poopoo)))/(n-1);
    
            % trade_balance; trade_intensity
            Data(:,(1+ (i-1)*time ):(i*time)) = [specific_price; M; M_per_worker; trade_balance; profit_var];
            Data_final(:,(1+ (i-1) ):(i)) = [specific_price(time); M(time); M_per_worker(time); trade_balance(time); (profit_var(time)).^0.5];
        
        end
        %%%%%%%%%%LOOP end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        
        resolution = 1001;
        scale = 1;
        
        ptsy = linspace(0, 1, resolution);
        ptsx = linspace(0, scale, resolution);
        %ptsx = linspace(-0.1, 5, 1001);
        %H = log(histcounts2(Data_final(2,:), Data_final(1,:), pts, pts));
        H = log(histcounts2(Data(2,:), Data(1,:), ptsy, ptsx));
        imagesc(ptsx, ptsy, H);
        axis xy;
        set(gca, 'XLim', ptsx([1 end]), 'YLim', ptsy([1 end]), 'YDir', 'normal');
        colormap copper
        a=colorbar;
        a.Label.String = "Density of simulation outcomes [natural log scale]";
        xlabel {Deviation from LTV prices [natural log scale]}
        ylabel {Deviation from reproduction [linear scale]}
        title {Absolute sector income vs LTV pricing}
        exportgraphics(gcf,"repro_inv_M10.png","Resolution",600);
        
        figure 
        ptsy = linspace(0, 1, resolution);
        ptsx = linspace(0, scale, resolution);
        %H = log(histcounts2(Data_final(3,:), Data_final(1,:), pts, pts));
        H = log(histcounts2(Data(3,:), Data(1,:), ptsy, ptsx));
        imagesc(ptsx, ptsy, H);
        axis xy;
        set(gca, 'XLim', ptsx([1 end]), 'YLim', ptsy([1 end]), 'YDir', 'normal');
        colormap copper
        a=colorbar;
        a.Label.String = "Density of simulation outcomes [natural log scale]";
        xlabel {Deviation from LTV prices [natural log scale]}
        ylabel {Deviation from reproduction (scaled by employment) [linear scale]}
        title {Per worker sector income vs LTV pricing}
        exportgraphics(gcf,"repro_inv_Mw10.png","Resolution",600);
        
        figure 
        
        ptsy = linspace(-1, 1, resolution);
        ptsx = linspace(0, scale, resolution);
        %H = log(histcounts2(Data_final(4,:), Data_final(1,:), pts, pts));
        H = log(histcounts2(Data(4,:), Data(1,:), ptsy, ptsx));
        imagesc(ptsx, ptsy, H);
        axis xy;
        set(gca, 'XLim', ptsx([1 end]), 'YLim', ptsy([1 end]), 'YDir', 'normal');
        colormap copper
        a=colorbar;
        a.Label.String = "Density of simulation outcomes [natural log scale]";
        xlabel {Deviation from LTV prices [natural log scale]}
        ylabel {Trade balance [linear scale]}
        title {Trade balance vs LTV pricing}
        exportgraphics(gcf,"repro_inv_T10.png","Resolution",600);
    
        figure 
        
        ptsy = linspace(0, 2.5, resolution);
        ptsx = linspace(0, scale, resolution);
        %H = log(histcounts2(Data_final(5,:), Data_final(1,:), pts, pts));
        H = log(histcounts2(Data(5,:), Data(1,:), ptsy, ptsx));
        imagesc(ptsx, ptsy, H);
        axis xy;
        set(gca, 'XLim', ptsx([1 end]), 'YLim', ptsy([1 end]), 'YDir', 'normal');
        colormap copper
        a=colorbar;
        a.Label.String = "Density of simulation outcomes [natural log scale]";
        xlabel {Deviation from LTV prices [natural log scale]}
        ylabel {STD of profitability rates of sectors}
        title {Profit STD vs LTV pricing}
        exportgraphics(gcf,"repro_inv_p10.png","Resolution",600);
        
    
      

    '

17 comments