# Failing to find area under a curve/integrate

I'm trying to calculate the are under a curve and no matter what integration method I use I get many errors and the integral can't be calculated. I feel this should not be the case because I'm indeed able to plot the curve, just not calculate it's area. The plot looks like:

But when I try to obtain the integral I get a long list of errors:

The code to replicate all this is a bit long, here it is:

    σA = 0.2;
σX = 0.4;
fBar = 0.015;
sD = 0.13;
sS = 0.2;
ρ :=
0.2;                          (* Subjective discount rate  *)
α := -2;                                 (* Relative Risk \
aversion is := 1 - α  *)
lev = 1;                                 (* Leverage*)                \

ϕ = 95/100;
η = 1;
fA = fBar;
gA = (σX^2 (σX^2 (1 - ϕ) + \
σA^2))/(σX^2 + σA^2);
gB = (σX^2 σA^2)/(σX^2 + σA^2);
λA :=
1/2;                         (* Lagrange multiplier for Agent A's \
budget constraint at date 0  *)
λB :=
1/2;                         (* Lagrange multiplier for Agent B's \
budget constraint at date 0  *)
ω0 = ((1/λA)^((1/(
1 - α)))) /((1/λA)^(1/(
1 - α)) + ((η λB)/λA)^(1/(
1 - α)));

γA1[t_] := γA1[t] = 1/(
t (1/sD^2 + ϕ^2/sS^2) + 1/gA);
γB1[t_] := γB1[t] = sD^2/ (t + sD^2/gB);
HF1[fA_, t_, u_, ε_] :=
HF1[fA, t, u, ε] =
Exp[-(((t -
u) ε (sD^2 (2 fA + (-1 + ε) sD^2) \
sS^2 + gA (t (-1 + ε) ϕ^2 sD^4 + 2 fA t sS^2 +
sD^2 (2 fA t ϕ^2 + (-t + u ε) sS^2))))/(
2 (sD^2 sS^2 + t gA (ϕ^2 sD^2 + sS^2))))];

Off[InterpolatingFunction::dmval]
Hg1[gHat_, t0_, u0_, ϵ_, x0_] :=
Module[{x = x0, u = u0, t = t0},
PDEC := - 2 HC[
p] (γB1[-p + u]/sD^2 - (
x (γB1[-p + u] - γA1[-p + u]) )/sD^2) + ( (
x (x - 1))/(2 sD^2)) +
2 HC[p]^2 ((γB1[-p + u] - γA1[-p + u])^2/
sD^2 + (ϕ^2 (γA1[-p + u])^2)/sS^2) -
Derivative[1][HC][p];
solC =
NDSolve[{PDEC == 0, HC[0] == 0},
HC, {p, Re[(u - t) - 0.1], Re[(u - t) + 0.1]}];
PDEB :=
HB[p] (( x (γB1[-p + u] - γA1[-p + u]) )/
sD^2 - γB1[-p + u]/sD^2 +
2 (HC[p] /.
solC) ((γB1[-p + u] - γA1[-p + u])^2/
sD^2 + (ϕ^2 (γA1[-p + u])^2)/sS^2)) +
2 (HC[p] /. solC) (γB1[-p + u] - γA1[-p + u] +
p (( γA1[-p +
u] (γB1[-p + u] - γA1[-p + u]) )/
sD^2 - (ϕ^2 (γA1[-p + u])^2)/sS^2)) +
x (1 + (p γA1[-p + u])/sD^2) - Derivative[1][HB][p];
solB =
NDSolve[{PDEB == 0, HB[0] == 0},
HB, {p, (u - t) - 0.1, (u - t) + 0.1}];
PDEA1 :=  (HC[p] /.
solC) ((γB1[-p + u] - γA1[-p + u])^2/
sD^2 + (ϕ^2 (γA1[-p + u])^2)/sS^2) -
Derivative[1][HA1][p];
solA1 =
NDSolve[{PDEA1 == 0, HA1[0] == 0},
HA1, {p, (u - t) - 0.1, (u - t) + 0.1}];
PDEA2 :=  (HB[p] /.
solB) (1/
2 ((γB1[-p + u] - γA1[-p + u])^2/
sD^2 + (ϕ^2 (γA1[-p + u])^2)/
sS^2) + γB1[-p + u] - γA1[-p + u] +
p (( γA1[-p +
u] (γB1[-p + u] - γA1[-p + u]) )/
sD^2 - (ϕ^2 (γA1[-p + u])^2)/sS^2)) -
Derivative[1][HA2][p];
solA2 =
NDSolve[{PDEA2 == 0, HA2[0] == 0},
HA2, {p, (u - t) - 0.1, (u - t) + 0.1}];
Evaluate[HC[u - t] /. solC] gHat^2 +
gHat ϵ Evaluate[
HB[u - t] /. solB] + ϵ^2 Evaluate[
HA1[u - t] /. solA1] + Evaluate[HA2[u - t] /. solA2]];

EqPricej1[ω_, gHat_, fA_, t_, u_, j_] :=
EqPricej1[ω, gHat, fA, t, u, j] =
Exp[-ρ (u - t)]  HF1[fA, t, u, α] (ω)^(
1 - α) Binomial[1 - α, j] (1/ω - 1)^
j Hg1[gHat, t, u, α, j/(1 - α)];
EquityPrice1[ω_, gHat_, fA_, t_, u_] :=
EquityPrice1[ω, gHat, fA, t, u] =
Sum[EqPricej1[ω, gHat, fA, t, u, j], {j, 0, 1 - α}] ;
Plot[EquityPrice1[ω0, -0.03, fA, 0.1, u], {u, 0.1, 1/8}]


Replace your EqPricej1 and EquityPrice1 functions with the below. Note the restriction on u so the function only fires when u is numeric. Also note the removal of the memoization terms.

EqPricej1[ω_, gHat_, fA_, t_, u_?NumericQ, j_] :=
Exp[-ρ (u - t)] HF1[fA, t,  u, α] (ω)^(1 - α)
Binomial[1 - α, j] (1/ω - 1)^j  Hg1[gHat, t, u, α, j/(1 - α)];

EquityPrice1[ω_, gHat_, fA_, t_, u_?NumericQ] :=
Sum[EqPricej1[ω, gHat, fA, t, u, j], {j, 0, 1 - α}];


Then integrate it, note that your EquityPrice1 funtion returns a list, so you have to pick off the element of the list.

NIntegrate[EquityPrice1[ω0, -0.03, fA, 0.1, u] // First, {u, 1/10, 1/8}]

(*  0.0139377  *)

• @Jason B., is there an easy way to properly typeset the posts? Jun 14, 2017 at 19:59
• why certainly, a browser plugin written by one of our own. That made the greek-character changes and I just added some line breaks so you could see everything at once Jun 14, 2017 at 20:00
• Great! Thank you! it does work! :D :D :D Jun 15, 2017 at 20:38