function z=defaultpayoff(v_bar,x_star,eta,c,mu,sigma)

global x_lbar;
global x_bar;


%this is the payoff to an investor given that the entrepreneur announced
%default. This payoff must be non-negative in order for the investor to be
%willing to seek payment rather than forgiving the debt.

%v_bar: face value of the debt contrast
%eta: percent of assets retained in bankruptcy by the borrower


%below are the upper and lower bounds for project realizations. If we
%choose a normal or a T-distribution for the project, then x_lbar must be
%sufficiently low and x_bar sufficiently large such that almost no
%probability mass is outside [x_lbar,x_bar]


if v_bar/(1-eta)<x_star-eps  && v_bar/(1-eta)<x_bar
    %deducting eps avoids intergration where the upper bound and lower bound are the same (which would result in an error message)
    z=quad(@(x) (1-eta).*x.*density(x,mu,sigma),x_lbar,v_bar/(1-eta))+quad(@(x) v_bar.*density(x,mu,sigma),v_bar/(1-eta),min(x_star,x_bar));
    %the following division gives us the conditional probability
    z=z/quad(@(x) density(x,mu,sigma),x_lbar,min(x_star,x_bar))-c;
else
    z=quad(@(x) (1-eta).*x.*density(x,mu,sigma),x_lbar,min(v_bar/(1-eta),x_bar));
    %the following division gives us the conditional probability
    z=z/quad(@(x) density(x,mu,sigma),x_lbar,min(v_bar/(1-eta),x_bar))-c;
end;



