ClearAll["Global`*"]
 
(*Setpember 14, new model*)
(* here, d is the default probability, s is the maximum return, rd is the default probability*)
 
probdefault= p/( p+ (1-p)(s-r)/s)

Simplify[Sign[D[probdefault,p]], {b>0,  s>1, 0<p<1 , r<s }  ]
Simplify[Sign[D[probdefault, r]], {b>0,  s>1, 0<p<1 , r<s }  ]

v = Simplify[probdefault*(-b)+ (1-probdefault)r]

(*This is the first derivative of the expected return*)
dvdr= Simplify[D[v,r]]

(*The derivative of v with respect to b is positive---smaller loss means bigger return, pretty obvious*)
Simplify [ D[(((-1+p) (r^2)-b p s+r (s-p s))/((-1+p) r+s)),b]]

dvdp = Simplify[D[v,p]]

(*This is the first derivative of the expected return*)
dvdr = Simplify[D[v,r]]

(*This gives teh maximum expected return*)
Maximize[{v, 0<p<1,b>0,s>0, r<s},r]

(*This gives the r at awhcih expected returnis maximized*)rmax=Simplify[ (1/2) (s-((s+p s)/(-1+p))-2 (Sqrt[-((-b p s+b (p^2) s-p (s^2))/(((-1+p))^2))]))-(1/2) √(1/(-1+p)(4 b p s-(s^2)+p (s^2)-2 s (((s+p s)/(-1+p))+2 (Sqrt[-((-b p s+b (p^2) s-p (s^2))/(((-1+p))^2))]))-2 p s (((s+p s)/(-1+p))+2 (Sqrt[-((-b p s+b (p^2) s-p (s^2))/(((-1+p))^2))]))-(((((s+p s)/(-1+p))+2 (Sqrt[-((-b p s+b (p^2) s-p (s^2))/(((-1+p))^2))])))^2)+p (((((s+p s)/(-1+p))+2 (Sqrt[-((-b p s+b (p^2) s-p (s^2))/(((-1+p))^2))])))^2)))]

Solve[ (((-1+p) (r^2)-b p s+r (s-p s))/((-1+p) r+s)) ==0 /.  r->rmax  , p]

(*Now we taket the derivative with respect to p, the default type,  of the r at which expected rrturn is maximized   We want to show that this derivative  is negative, so higher default types have a lower   r for getting a maximum expected return. *)
drmaxdp= Simplify[ D[rmax,p]]

signdrmaxdp= Sign[drmaxdp];
Simplify [signdrmaxdp, {b>0,s>0, 0<p<1  }]

Plot[rmax /. {s->3,b->-1},{p,0,1}]  
Plot[v/. {s->3 ,r->.2, b->-1} ,{p,0,1}]

(*Now I will make a v function*)
 
return[p_]:=   (((-1+p) (r^2)-b p s+r (s-p s))/((-1+p) r+s))
 
 
a1= Plot[   {{return[.4],return[.01],return[.08], return[.15]}/. {b->.1,s->.2}}  ,{r,0,.2} ]

(*This next one is for b=1. s=1.5, I think.*)

(*this next on is for b=.1, s=.2