function R=profit(x, M)
% Calculates profit of a company vs. fraction 'x' invested in expansion
% (1-x) corresponds in money fraction spent in speculations.
% M - money  available for  spending

% Some useful estimates from the used model point of view
% M=10^6 - small business company
% M=10^7 - intermediate
% M=10^8 - large

Me=M*x; % money for business expansion, i.e. new tools, goods making machines etc.
Ms=M*(1-x); % money for speculations on a stock market

% Re - return from expansion investments
% Re should decrease for a large sum of money due to overhead, 
% think about extra buildings for extra workers or management overhead which grows
Mt=10^7; % the threshold for the low overhead investment
Re= Me.*(0.9 +0.2*exp(-(Me./Mt).^2)); % after certain threshold overhead eats up the profit

% Rs - return from speculations 
% For a small investment the return is proportional to input
% but a large sum of money allows to manipulate the market and increases the profit
% after Mst  threshold,  speculations bring very high profits
Mst=1e8;
Rs=Ms.*(1.5-0.6*exp(-(Ms./Mst).^2) );

R=(Rs+Re)./M; % profit as ratio to investment

end



