function [result0] = montecarlo(n)

R0=104816548000; % Initial Revenue
sigma0=0.396; % Initial volatility of revenues
mu0=0.5412; % Initial expected rate of growth in revenues
eta0=0.6046; % Initial volatility of expected rates of growth in revenues
muba=0.06; % Long-term rate of growth in revenues
sigmaba=0.15; % Long-term volatility of the rate of growth in revenues
k=0.2773; % Speed of adjustment for the rate of growth process
lambda1=0.04; % Market price of risk for the revenue factor
lambda2=0; % Market price of risk for the expected rate of growth in revenues
alpha0=0.717; % Variable costs
F=4973705340; % Fixed costs
alphaba=0.717; % Long-term variable costs
phi0=0.03; % Initial volatility of variable costs
phiba=0.015; % Long-term volatility of variable costs
tauc=0.25; % Tax rate
DR=0.13; % Depreciation
X0=34397388000; % Initial cash balance available
L0=428077000; % Initial loss carry-forward
CR0=845000000; % Initial Capital expenditure
CR=0.015; % Capital expenditure
P0=2909624000; % Accumulated Property, Plant and Equipment
r=0.02515; % Risk-free interest rate
T=5; % Horizon for the estimation
deltat=1; % Time increment for the discrete version of the model
M=10; % multiplier
debt=23421959000;% Total debt
stocknumcb=0; % stock numbers converted by convertible bonds;
stocknumout=4364192000; % The number of shares outstanding
newstocknum=stocknumcb+stocknumout;% the total stock numbers
t=[0:deltat:T];
lt=length(t);
etat=eta0;
sigmat=sigma0;
mut=mu0.*ones(1,n);
Rt=R0.*ones(1,n);
phit=phi0;
alphat=alpha0.*ones(1,n);
costt=zeros(1,n);
Pt=P0.*ones(1,n);
Capxt=CR.*Rt;
Dept=DR.*Pt;
Yt=(Rt-costt-Dept).*(1-tauc);
Xt=X0.*ones(1,n);
bp(1,:)=zeros(1,n);%bankruptcy probablity

for i=2:lt

% Calculate Rt
etat(i)=eta0.*exp(-k.*t(i));
sigmat(i)=sigma0.*exp(-k.*t(i))+sigmaba.*(1-exp(-k.*t(i)));
epsilon2=randn(1,n);
mut(i,:)=mut(i-1,:).*exp(-k.*deltat)+muba.*(1-exp(-k.*deltat))+etat(i-1).*sqrt((1-exp(-2.*k.*deltat))./(2.*k)).*epsilon2;
epsilon1=randn(1,n);
Rt(i,:)=Rt(i-1,:).*exp((mut(i-1)-lambda1.*sigmat(i-1)-0.5.*(sigmat(i-1).^2)).*deltat+…sigmat(i-1).*sqrt(deltat).*epsilon1);

% Calculate costt
phit(i)=phi0.*exp(-k.*t(i))+phiba.*(1-exp(-k.*t(i)));
epsilon3=randn(1,n);
alphat(i,:)=alphat(i-1,:).*exp(-k.*deltat)+alphaba.*(1-exp(-k.*deltat))+phit(i-1).*sqrt((1-exp(-2.*k.*deltat))./(2.*k)).*epsilon3;
costt(i,:)=alphat(i,:).*Rt(i,:)+F;

% Calculate Xt
Pt(i,:)=CR.*Rt(i-1,:).*deltat+(1-DR).*Pt(i-1,:).*deltat;
Capxt(i,:)=CR.*Rt(i,:);
Dept(i,:)=DR.*Pt(i,:);
Yt(i,:)=(Rt(i,:)-costt(i,:)-Dept(i,:)).*(1-tauc);
Xt0=Xt(i-1,:).*(1+r).*deltat+(Yt(i-1,:)+(Dept(i-1,:)-Capxt(i-1,:))).*deltat;
bp(i,:)=Xt0<=0;%record the bankruptcy times
Xt0(Xt0<=0)=0;
Xt(i,:)=Xt0;
end


V0T=Xt(lt,:)+M.*(Rt(lt,:)-costt(lt,:)).*exp(-r.*T);
V0Tnew=V0T(:,all(bp<=0));
bpp=sum(~all(bp<=0)).*100./n;%bankruptcy probability
V0=mean(V0Tnew);%Company value
stdV0=std(V0Tnew);%standard errors
vstock=(V0-debt)./newstocknum;%stock price
stdvstock=(stdV0-debt)./newstocknum;%standard errors
result0=[deltat,T,n,bpp,V0,stdvstock,vstock]

end