({{, (RefLink[Expectation, paclet:ref/Expectation])[expr,x\[Distributed]dist] 
gives the expectation of expr under the assumption that x follows the probability distribution dist. }, {, (RefLink[Expectation, paclet:ref/Expectation])[expr,x\[Distributed]data]
gives the expectation of expr under the assumption that x follows the probability distribution given by data.}, {, (RefLink[Expectation, paclet:ref/Expectation])[expr,{(Subscript[x, 1]),(Subscript[x, 2]),…}\[Distributed]dist]
gives the expectation of expr under the assumption that {(Subscript[x, 1]),(Subscript[x, 2]),…} follows the multivariate distribution dist. }, {, (RefLink[Expectation, paclet:ref/Expectation])[expr,{(Subscript[x, 1])\[Distributed](Subscript[dist, 1]),(Subscript[x, 2])\[Distributed](Subscript[dist, 2]),…}]
gives the expectation of expr under the assumption that (Subscript[x, 1]), (Subscript[x, 2]), … are independent and follow the distributions (Subscript[dist, 1]), (Subscript[dist, 2]), …. }, {, (RefLink[Expectation, paclet:ref/Expectation])[expr\[Conditioned]pred,…]
gives the conditional expectation of expr given pred.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[Expectation, paclet:ref/Expectation]) is also known as expected value.

x\[Distributed]dist can be entered as x (Key0[esc]) dist (Key0[esc]) dist or x∖[Distributed]dist.

expr\[Conditioned]pred can be entered as expr (Key0[esc]) cond (Key0[esc]) pred or expr∖[Conditioned]pred.

For a continuous distribution dist, the expectation of expr is given by ∫ expr f(x) dx where f(x) is the probability density function of dist and the integral is taken over the domain of dist.

For a discrete distribution dist, the probability of expr is given by ∑expr f(x)  where f(x) is the probability density function of dist and the summation is taken over the domain of dist.

For a dataset data, the expectation of expr is given by (RefLink[Sum, paclet:ref/Sum])[expr,{x,data}]/(RefLink[Length, paclet:ref/Length])[data].

Univariate data is given as a list of values {(Subscript[v, 1]),(Subscript[v, 2]),…} and multivariate data is given as a list of vectors {{(Subscript[v, 11]),…,(Subscript[v, 1m])},{(Subscript[v, 21]),…,(Subscript[v, 2m])},…}.

(RefLink[Expectation, paclet:ref/Expectation])[expr,{(Subscript[x, 1])\[Distributed](Subscript[dist, 1]),(Subscript[x, 2])\[Distributed](Subscript[dist, 2])}] corresponds to (RefLink[Expectation, paclet:ref/Expectation])[Expectation[expr,(Subscript[x, 2])\[Distributed](Subscript[dist, 2])],(Subscript[x, 1])\[Distributed](Subscript[dist, 1])] so that the last variable is summed or integrated first.

(RefLink[N, paclet:ref/N])[Expectation[…]] calls (RefLink[NExpectation, paclet:ref/NExpectation]) for expectations that cannot be done symbolically.

The following options can be given:

OpenersPrimaryExamplesSection(Spacer1)Examples  (72)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Compute the expectation of a polynomial expression:

Expectation[2x+3,x\[Distributed]NormalDistribution[]]

Expectation[x^2+7x+8,x\[Distributed]PoissonDistribution[μ]]

Expectation[x^2+3y^2+11,{x,y}\[Distributed]DirichletDistribution[{1,4,5}]]

Expectation[x^3+4y-a z,{x,y,z}\[Distributed]MultinomialDistribution[10,{1/2,1/3,1/6}]]

Compute the expectation of an arbitrary expression:

Expectation[(((x-1))^2)+E^(-x),x\[Distributed]NormalDistribution[]]

Expectation[Abs[2x-1],x\[Distributed]ExponentialDistribution[λ]]

Expectation[x^2+E^(x+y),{x,y}\[Distributed]DirichletDistribution[{2,3,4}]]

Compute a conditional expectation:

Expectation[(x^2)+1\[Conditioned]x>1/2,x\[Distributed]LaplaceDistribution[0,1/2]]

Expectation[x+(y^2)-(3/10)\[Conditioned](1/2<x<3/4),{x,y}\[Distributed]DirichletDistribution[{1,3,4}]]

OpenersExampleSection1(Spacer1)Scope  (31)

OpenersExampleSubsection0(Spacer1)Basic Uses  (9)

Compute the expectation for an expression in a continuous univariate distribution:

Expectation[3x^2+5,x\[Distributed]NormalDistribution[]]

Discrete univariate distribution:

Expectation[2x+7,x\[Distributed]PoissonDistribution[1]]

Continuous multivariate distribution:

Expectation[5x+3y^2+11,{x,y}\[Distributed]BinormalDistribution[1/2]]

Discrete multivariate distribution:

Expectation[3x^2+8x y+1,{x,y}\[Distributed]MultivariatePoissonDistribution[2,{2,3}]]

Find the expectation of an expression in a distribution specified by a list:

r=RandomVariate[NormalDistribution[],1000];

Expectation[x^2+3x+11,x\[Distributed]r]

Compute the expectation using independently distributed random variables:

Expectation[2x+3y^2+a,{x\[Distributed]ExponentialDistribution[1],y\[Distributed]NormalDistribution[]}]

Find the conditional expectation with general nonzero probability conditioning:

Expectation[x+2\[Conditioned]1/2<x^2<5,x\[Distributed]ExponentialDistribution[λ]]

Plot[%,{λ,0,5}]

Discrete univariate distribution:

Expectation[x^2+12\[Conditioned]x>2,x\[Distributed]PoissonDistribution[λ]]

Plot[%,{λ,0,10}]

Multivariate continuous distribution:

Expectation[(x+y)\[Conditioned](y>1/3),{x,y}\[Distributed]DirichletDistribution[{1,3,4}]]

Multivariate discrete distribution:

Expectation[x+y+5\[Conditioned]z>2,{x,y,z}\[Distributed]MultinomialDistribution[10,{1/3,1/2,1/6}]]

Compute the conditional expectation with a zero-probability conditioning event:

Expectation[x+y^2\[Conditioned](x==1/7),{x,y}\[Distributed]ProductDistribution[{ExponentialDistribution[3],2}]]

Apply (RefLink[N, paclet:ref/N])[Expectation[…]] to invoke (RefLink[NExpectation, paclet:ref/NExpectation]) if symbolic evaluation fails: »

f[x_?NumericQ]:=x^2+3x^4

Expectation[f[x],x\[Distributed]NormalDistribution[]]

N[%]

NExpectation[f[x],x\[Distributed]NormalDistribution[]]

With no (RefLink[Assumptions, paclet:ref/Assumptions]), conditions are generated:

Expectation[UnitStep[x-a],x\[Distributed]UniformDistribution[{2,8}]]

With (RefLink[Assumptions, paclet:ref/Assumptions]), a result valid under the given assumptions is returned:

Expectation[UnitStep[x-a],x\[Distributed]UniformDistribution[{2,8}], Assumptions-> 3<a<4]

Assuming[3<a<4,Expectation[UnitStep[x-a],x\[Distributed]UniformDistribution[{2,8}]]]

Find the expectation of a rational function:

Expectation[(x+3)/(x+5),x\[Distributed]ExponentialDistribution[2]]

Transcendental function:

Expectation[E^(-3x^2)+1,x\[Distributed]ExponentialDistribution[2]]

Piecewise function:

Expectation[Piecewise[{{5,x<1},{x^2+3,x≥1}}],x\[Distributed]ExponentialDistribution[2]]

Complex function:

Expectation[E^(I x),x\[Distributed]UniformDistribution[{3,4}]]

Compute an expectation for a time slice of a Poisson process:

Expectation[x[t]^2+x[t]+3E^(-x[t]),x\[Distributed]PoissonProcess[μ]]

OpenersExampleSubsection1(Spacer1)Quantity Uses  (5)

Find expectations of quantity expressions:

Expectation[Quantity[x,"Meters"]*Quantity[3.5,"Feet"],x\[Distributed]LogNormalDistribution[2,3]]

Expectation[Quantity[v,"Meters"/"Seconds"] Quantity[t,"Minutes"],{v\[Distributed]MaxwellDistribution[σ],t\[Distributed]GammaDistribution[a,b]}]

Find expectations specified using (RefLink[QuantityDistribution, paclet:ref/QuantityDistribution]):

freq𝒟=UniformDistribution[{(Quantity[2, "Hz", hertz, "Hertz"]),(Quantity[5, "Hz", hertz, "Hertz"])}]

dur𝒟=UniformDistribution[{Quantity[.5,"Seconds"],Quantity[.9,"Seconds"]}]

ampl𝒟=RayleighDistribution[(Quantity[5, "V", volts, "Volts"])]

Expectation[a Sin[ω t],{ω\[Distributed]freq𝒟,t\[Distributed]dur𝒟,a\[Distributed]ampl𝒟}]

Find conditional expectations:

Expectation[t1-t2\[Conditioned]t1>t2,{t1,t2}\[Distributed]CopulaDistribution[{"FGM",α},{UniformDistribution[{(QuantityMixedUnit2[1, 15,  "h",  "min", hours,minutes, {"Hours","Minutes"}]),(Quantity[2, "h", hours, "Hours"])}],UniformDistribution[{(Quantity[80, "min", minutes, "Minutes"]),(QuantityMixedUnit2[1, 45,  "h",  "min", hours,minutes, {"Hours","Minutes"}])}]}]]

Calculate expectation with (RefLink[QuantityMagnitude, paclet:ref/QuantityMagnitude]):

𝒟=QuantityDistribution[NormalDistribution[0,.3],"Yards"];

Expectation[QuantityMagnitude[x,"Meters"]^2,x\[Distributed]𝒟]

Equivalent calculation:

Expectation[x^2,Quantity[x,"Meters"]\[Distributed]𝒟]

Calculate expectation with distribution given by (RefLink[Quantity, paclet:ref/Quantity]) data:

Expectation[x,x\[Distributed]Quantity[RandomReal[1,100],"Meters"]]

Distribution given by (RefLink[QuantityArray, paclet:ref/QuantityArray]):

Expectation[x^2,x\[Distributed]QuantityArray[RandomReal[1,100],"Yards"]]

OpenersExampleSubsection2(Spacer1)Parametric Distributions  (4)

Compute expectations for univariate continuous distributions:

Expectation[x+1/2,x\[Distributed]BetaDistribution[α,β]]

Expectation[x^2+7E^x,x\[Distributed]UniformDistribution[{-2,11}]]

Expectation[(x-3)^2+5UnitStep[x^2-1],x\[Distributed]NormalDistribution[0,1]]

Expectation[E^(-x)+3x,x\[Distributed]ChiSquareDistribution[ν]]

Compute expectations for univariate discrete distributions:

Expectation[x^2+9,x\[Distributed]BinomialDistribution[10,p]]

Expectation[x+10E^x,x\[Distributed]DiscreteUniformDistribution[{5,max}]]

Expectation[x^3+12,x\[Distributed]ZipfDistribution[4]]

Expectation[E^(2x)+3,x\[Distributed]PoissonDistribution[λ]]

Expectations for multivariate continuous distributions:

Expectation[x+y^2+7,{x\[Distributed]UniformDistribution[{0,1}],y\[Distributed]LaplaceDistribution[0,1]}]

Expectation[x^6+3y+1,{x\[Distributed]NormalDistribution[0,1],y\[Distributed]ExponentialDistribution[m]}]

Expectation[2x^2+3y^2+z,{x,y,z}\[Distributed]DirichletDistribution[{2,3,4,7}]]

Expectations for multivariate discrete distributions:

Expectation[x+y^2,{x,y}\[Distributed]ProductDistribution[DiscreteUniformDistribution[{2,5}],BernoulliDistribution[p]]]

Expectation[x y^2,{x\[Distributed]GeometricDistribution[1/3],y\[Distributed]PoissonDistribution[λ]}]

Expectation[2x+3y+Abs[z-2],{x,y,z}\[Distributed]MultinomialDistribution[10,{1/2,1/3,1/6}]]

OpenersExampleSubsection3(Spacer1)Nonparametric Distributions  (4)

Compute an expectation using a univariate (RefLink[EmpiricalDistribution, paclet:ref/EmpiricalDistribution]):

𝒟=EmpiricalDistribution[RandomVariate[NormalDistribution[],100]];

Expectation[(x^2)+1,x\[Distributed]𝒟]

Using a multivariate empirical distribution:

𝒟=EmpiricalDistribution[RandomVariate[BinormalDistribution[1/3],100]];

Expectation[x+(y^2)+4,{x,y}\[Distributed]𝒟]

Using a univariate (RefLink[HistogramDistribution, paclet:ref/HistogramDistribution]):

𝒟=HistogramDistribution[RandomVariate[ExponentialDistribution[2],100]];

Expectation[x^2+x+3,x\[Distributed]𝒟]

A multivariate histogram distribution:

𝒟=HistogramDistribution[RandomVariate[BinormalDistribution[1/3],100]];

Expectation[x+(y^2)+1,{x,y}\[Distributed]𝒟]

Using a univariate (RefLink[KernelMixtureDistribution, paclet:ref/KernelMixtureDistribution]):

𝒟=KernelMixtureDistribution[RandomVariate[NormalDistribution[],30]];

Expectation[x^4+2x^2+7,x\[Distributed]𝒟]

Using censored data with (RefLink[SurvivalDistribution, paclet:ref/SurvivalDistribution]):

eventTimes={10,7,23,22,6,25,20,19,6,17,6,13};

censorIndicators={0,0,0,0,0,1,1,1,0,1,0,0};

𝒟=SurvivalDistribution[EventData[eventTimes,censorIndicators]];

Expectation[x+25,x\[Distributed]𝒟]

OpenersExampleSubsection4(Spacer1)Derived Distributions  (9)

Compute the expectation using a (RefLink[TransformedDistribution, paclet:ref/TransformedDistribution]):

Expectation[x+2,x\[Distributed]TransformedDistribution[y^2,y\[Distributed]NormalDistribution[0,1]]]

An equivalent way of formulating the same expectation:

Expectation[y^2+2,y\[Distributed]NormalDistribution[0,1]]

Find the expectation using a (RefLink[ProductDistribution, paclet:ref/ProductDistribution]):

Expectation[x+y+4,{x,y}\[Distributed]ProductDistribution[ExponentialDistribution[m],TriangularDistribution[{3,7}]]]

An equivalent formulation for the same expectation:

Expectation[x+y+4,{x\[Distributed]ExponentialDistribution[m],y\[Distributed]TriangularDistribution[{3,7}]}]//Together

Using a component mixture of normal distributions:

Expectation[E^x+2,x\[Distributed]MixtureDistribution[{1,2},{NormalDistribution[2,3],NormalDistribution[4,5]}]]

Parameter mixture of exponential distributions:

Expectation[2x+3, x \[Distributed] ParameterMixtureDistribution[
   ExponentialDistribution[λ], λ \[Distributed] UniformDistribution[{1, 2}]]]

Truncated Dirichlet distribution:

Expectation[x^2+y+4,{x,y}\[Distributed]TruncatedDistribution[{{1/3,1/2},{1/6,5/6}},DirichletDistribution[{2,4,7}]]]

Censored triangular distribution:

Expectation[UnitBox[x^2-35],x\[Distributed]CensoredDistribution[{5,30},TriangularDistribution[{1,50}]]]

Marginal distribution:

Expectation[(x^2)+13 x+6E^x,x\[Distributed]MarginalDistribution[DirichletDistribution[{1,2,3}],1]]

An equivalent way of formulating the same expectation:

Expectation[(x^2)+13 x+6E^x,{x,y}\[Distributed]DirichletDistribution[{1,2,3}]]

Copula distribution:

Expectation[x+y^2+1, {x,y}\[Distributed]CopulaDistribution[{"AMH",1/5}, {UniformDistribution[{0,1}], UniformDistribution[{0,1}]}]]

Formula distribution:

Expectation[E^(-x^2)+2,x\[Distributed]ProbabilityDistribution[3/4(x^2+2x),{x,0,1}]]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (2)

Use a pure function to compute an expectation for a list of values:

r=RandomVariate[NormalDistribution[],1000];

Expectation[#^2+3#&,r]

Compute an expectation for a mixture of continuous and discrete distributions:

Expectation[k^2+3,k\[Distributed]MixtureDistribution[{1,2},{ExponentialDistribution[1/7],PoissonDistribution[2/7]}]]

OpenersExampleSection3(Spacer1)Options  (6)

OpenersExampleSubsection5(Spacer1)Assumptions  (1)

With no (RefLink[Assumptions, paclet:ref/Assumptions]), conditions are generated:

Expectation[UnitStep[x-a],x\[Distributed]UniformDistribution[{2,m}]]

With (RefLink[Assumptions, paclet:ref/Assumptions]), a result valid under the given assumptions is returned:

Expectation[UnitStep[x-a],x\[Distributed]UniformDistribution[{2,m}], Assumptions-> 3<a<4&&m>a]

Assuming[3<a<4&&m>a,Expectation[UnitStep[x-a],x\[Distributed]UniformDistribution[{2,m}]]]

OpenersExampleSubsection6(Spacer1)Method  (4)

Compute the expectation of a polynomial function:

Expectation[x^2+x^10,x\[Distributed]NormalDistribution[]]

Obtain the same result using the moments of the distribution:

Expectation[x^2+x^10,x\[Distributed]NormalDistribution[],Method->"Moment"]//Timing

The evaluation is slower using the definition of (RefLink[Expectation, paclet:ref/Expectation]) as an integral:

Expectation[x^2+x^10,x\[Distributed]NormalDistribution[],Method->"Integrate"]//Timing

Compute the expectation of a transcendental function:

Expectation[E^(-x),x\[Distributed]PoissonDistribution[3]]

Here, the method based on moments fails because the expression is nonpolynomial:

Expectation[E^(-x),x\[Distributed]PoissonDistribution[3],Method->"Moment"]

The result can be obtained using the definition of (RefLink[Expectation, paclet:ref/Expectation]) as a symbolic sum:

Expectation[E^(-x),x\[Distributed]PoissonDistribution[3],Method->"Sum"]

Find the expectation of a function in a (RefLink[TukeyLambdaDistribution, paclet:ref/TukeyLambdaDistribution]):

Expectation[UnitStep[2x+1],x\[Distributed]TukeyLambdaDistribution[1/3]]

The PDF of this distribution is not available in closed form:

PDF[TukeyLambdaDistribution[1/3],x]

Hence a direct application of the definition fails:

Expectation[UnitStep[2x+1],x\[Distributed]TukeyLambdaDistribution[1/3],Method->"Integrate"]

The expectation can be computed using (RefLink[Quantile, paclet:ref/Quantile]):

Expectation[UnitStep[2x+1],x\[Distributed]TukeyLambdaDistribution[1/3],Method->"Quantile"]

q=Quantile[TukeyLambdaDistribution[1/3],p]

Integrate[(UnitStep[2x+1]/.{x->q}),{p,0,1}]

Calculate the expectation of an expression:

Expectation[E^(2x+1),x\[Distributed]NormalDistribution[]]

This example uses (RefLink[Integrate, paclet:ref/Integrate]):

Expectation[E^(2x+1),x\[Distributed]NormalDistribution[],Method->"Trace"]

Use (RefLink[Activate, paclet:ref/Activate]) to evaluate the result:

Activate[%]

OpenersExampleSubsection7(Spacer1)TargetUnits  (1)

Create a distribution object with quantity:

𝒟=UniformDistribution[{1,5} Quantity[1,"Seconds"]]

(RefLink[Expectation, paclet:ref/Expectation]) uses the quantity provided in the distribution as default:

Expectation[x^2,x\[Distributed]𝒟]

Specify the target unit to "Hours":

Expectation[x^2,x\[Distributed]𝒟,TargetUnits->"Hours"^2]

OpenersExampleSection4(Spacer1)Applications  (20)

OpenersExampleSubsection8(Spacer1)Distribution Properties  (5)

Obtain the raw moments of a continuous distribution:

Expectation[x^n,x\[Distributed]ChiSquareDistribution[ν],Assumptions->n>0]

Moment[ChiSquareDistribution[ν],n]//FunctionExpand

Obtain the mean of a discrete distribution:

Expectation[x,x\[Distributed]PoissonDistribution[μ]]

Mean[PoissonDistribution[μ]]

Obtain the variance of a truncated distribution:

dist=TruncatedDistribution[{1,3},ExponentialDistribution[2]];

Expectation[(x-Mean[dist])^2,x\[Distributed]dist]

Variance[dist]

Construct a mixture density, here a Poisson-inverse Gaussian mixture:

Expectation[PDF[PoissonDistribution[μ],k],μ\[Distributed]InverseGaussianDistribution[m,λ]]

Obtain the same result directly using (RefLink[ParameterMixtureDistribution, paclet:ref/ParameterMixtureDistribution]):

PDF[ParameterMixtureDistribution[PoissonDistribution[μ],μ\[Distributed]InverseGaussianDistribution[m,λ]],k]

FullSimplify[%-%%,m∈Reals&&m>0&&λ∈Reals&&λ>0]

Verify Jensen inequality Mean (u (X))≤u(Mean (X)) for a concave function u==log(x) and a lognormal distribution:

𝒟=LogNormalDistribution[μ,σ];

Expectation[Log[X],X\[Distributed]𝒟]≤Log[Expectation[X,X\[Distributed]𝒟]]

FullSimplify[%,σ>0&&μ∈Reals]

OpenersExampleSubsection9(Spacer1)Actuarial Science  (5)

An insurance policy reimburses a loss up to a benefit limit of 10. The policy holder's loss y follows a distribution with density function 2/(y^3) for y>1 and 0 otherwise. Find the expected value of the benefit paid under the insurance policy:

𝒟=CensoredDistribution[{1,10},ProbabilityDistribution[2/y^3,{y,1,Infinity}]];

Expectation[x, x\[Distributed]𝒟]//N

An insurance company's monthly claims are modeled by a continuous, positive random variable x, whose probability density function is proportional to 1/(((x+1))^4) where 0<x<∞. Determine the company's expected monthly claims:

claimDistribution=ProbabilityDistribution[3/(1+x)^4,{x,0,Infinity}];

Expectation[x,x\[Distributed]claimDistribution]

Claim amounts for wind damage to insured homes are independent random variables with common density function 3/(x^4) for x>1 and 0 otherwise, where x is the amount of a claim in thousands. Suppose three such claims will be made. Find the expected value of the largest of the three claims:

windClaims=ProductDistribution[{ProbabilityDistribution[3/y^4,{y,1,Infinity}],3}];

Expectation[1000Max[x,y,z],{x,y,z}\[Distributed]windClaims]

Let x represent the age of an insured automobile involved in an accident. Let y represent the length of time the owner has insured the automobile at the time of the accident. x and y have joint probability density function  (10-x (y^2))/64 for 2≤x≤10 and 0≤y≤1, and 0 otherwise. Calculate the expected age of an insured automobile involved in an accident:

ageDistribution=ProbabilityDistribution[(10-x y^2)/64,{x,2,10},{y,0,1}];

Expectation[x,{x,y}\[Distributed]ageDistribution]

N[%,2]

Under an excess of loss reinsurance agreement, a claim is shared between the insurer and reinsurer only if the claim exceeds a fixed amount, called the retention level. Otherwise, the insurer pays the claim in full. Compute the expected value of the amounts y and z, paid by the insurer and the reinsurer for a retention level of m if the claims follow a lognormal distribution with parameters μ and σ. Find the expected insurer claim payouts:

insurerPayouts=TransformedDistribution[Min[x,m],x\[Distributed]LogNormalDistribution[μ,σ], Assumptions->m>0];

Expectation[y, y\[Distributed]insurerPayouts]

Find the expected reinsurer payouts to the insurer:

reinsurerPayouts=TransformedDistribution[Max[0,x-m],x\[Distributed]LogNormalDistribution[μ,σ], Assumptions->m>0];

Expectation[z, z\[Distributed]reinsurerPayouts]

OpenersExampleSubsection10(Spacer1)Finance  (2)

Compute the expected time value of a death benefit of $1 paid at time t, where t is drawn from a Gompertz–Makeham distribution:

tv=TimeValue[Cashflow[{{t,1}}],EffectiveInterest[r,0],0]

nsp=Expectation[tv,t\[Distributed]GompertzMakehamDistribution[a,b]]

Find the annual premium, which is usually paid at the beginning of a policy year, that is necessary to make the expected time value of that payment stream for t periods (where t is drawn from a Gompertz–Makeham distribution) equal to the net single premium:

nap=TimeValue[AnnuityDue[premium,t],EffectiveInterest[r,0],0]

etv=Expectation[nap,t\[Distributed]GompertzMakehamDistribution[a,b]]

The resulting net annual premium:

Solve[etv==nsp,premium]//FullSimplify

The fractional change of stock price (Subscript[S, t])/(Subscript[S, 0]) at time t (in years) is assumed lognormally distributed with parameters μ t and σ (Sqrt[t]):

f𝒟[μ_,σ_,t_]=LogNormalDistribution[μ t,σ (Sqrt[t])];

Compute expected stock price at epoch t:

PriceAtEpoch[S0_,μ_,σ_,t_]=S0 Mean[f𝒟[μ,σ,t]]

Assuming an investor can invest money in a stock with dividend yield q for a year at a continuously compounded yearly rate r risk-free, the risk-neutral pricing condition requires:

PriceAtEpoch[(Subscript[S, 0]),μ,σ,t+1]==PriceAtEpoch[(Subscript[S, 0]),μ,σ,t] Exp[r-q]

Solve for parameter μ:

{sol}=Solve[ForAll[{t,(Subscript[S, 0])},%],μ,Reals]

Consider a call option to buy this stock a year from now, at a fixed price 𝒦. The value of such an option is:

CallOptVal[s_,𝒦_]=Max[s-𝒦,0];

Similarly, consider a put option to sell this stock a year from now, at a fixed price 𝒦. The value of such an option is:

PutOptVal[s_,𝒦_]=Max[𝒦-s,0];

The risk-neutral price of the call and put options are determined as the present value of their expected option values:

BlackScholesCallOptionPrice[S0_,𝒦_,r_,q_,σ_,t_]=Assuming[S0>0&&r>0&&q>0&&σ>0&&t>0&&𝒦>0,Exp[-r t]Expectation[CallOptVal[𝒻 S0,𝒦],𝒻\[Distributed]f𝒟[μ/.sol,σ,t]]//FullSimplify]

BlackScholesPutOptionPrice[S0_,𝒦_,r_,q_,σ_,t_]=Assuming[S0>0&&r>0&&q>0&&σ>0&&t>0&&𝒦>0,Exp[-r t]Expectation[PutOptVal[𝒻 S0,𝒦],𝒻\[Distributed]f𝒟[μ/.sol,σ,t]]//FullSimplify]

You can now establish the celebrated Put-Call Parity relationship that (Subscript[C, t])-(Subscript[P, t])= S0-𝒦 (e^(-r t)):

(BlackScholesCallOptionPrice[S0,𝒦,r,q,σ,t]-BlackScholesPutOptionPrice[S0,𝒦,r,q,σ,t]==S0 (E^(-q t))-𝒦 (E^(-r t)))//FullSimplify

Assuming rate r of 5%, dividend yield of 2%, volatility parameter σ of 0.087, an initial price of $200 per share of stock, and a strike price of $190 per share, the Black–Scholes call and put option prices are:

values={𝒦->190,t->1,r->0.05,σ->0.087,S0->200,q->0.02};

BlackScholesCallOptionPrice[S0,𝒦,r,q,σ,t]/.values

BlackScholesPutOptionPrice[S0,𝒦,r,q,σ,t]/.values

The above results can be compared favorably with (RefLink[FinancialDerivative, paclet:ref/FinancialDerivative]):

FinancialDerivative[{"European","Call"}, Evaluate[{"StrikePrice"-> 𝒦, "Expiration"->t}/.values],  Evaluate[{"InterestRate"-> r, "Volatility" -> σ, "CurrentPrice"-> S0, "Dividend"->q}/.values]]

FinancialDerivative[{"European","Put"}, Evaluate[{"StrikePrice"-> 𝒦, "Expiration"->t}/.values],  Evaluate[{"InterestRate"-> r, "Volatility" -> σ, "CurrentPrice"-> S0, "Dividend"->q}/.values]]

OpenersExampleSubsection11(Spacer1)Risk and Reliability  (2)

Study the tail value at risk (TVaR) for the exponential distribution:

MeanExcessLoss[dist_,d_]:=Expectation[\[FormalX]-d\[Conditioned]\[FormalX]>d,\[FormalX]\[Distributed]dist]
VaR[dist_,p_]:=Quantile[dist,p]
TVaR[dist_,p_]:=VaR[dist,p]+MeanExcessLoss[dist,Quantile[dist,p]]

Simplify[MeanExcessLoss[ExponentialDistribution[λ],d],d>0]

Simplify[VaR[ExponentialDistribution[λ],p],0<p<1]

Simplify[TVaR[ExponentialDistribution[λ],p],0<p<1&&λ>0]

Plot[Table[%,{ λ,1,3,0.5}]//Evaluate,{p,0,1},PlotLegends->(StringJoin["λ = ",ToString[#]]&/@Range[1,3,0.5])]

Find the mean time to failure (MTTF) for an exponential life distribution:

MTTF=Expectation[T,T\[Distributed]ExponentialDistribution[λ]]

OpenersExampleSubsection12(Spacer1)Random Experiments  (2)

A random sample of size 10 from a continuous distribution 𝒟 is sorted in ascending order. A new random variate is generated. Find the probability that the 11(^th) sample falls between the fourth and fifth smallest values in the sorted list:

𝒟=UniformDistribution[];n=10;k=4;

Expectation[Probability[x<z<y,z\[Distributed]𝒟],{x,y}\[Distributed]OrderDistribution[{𝒟,n},{k,k+1}]]

The probability equals 1/(n+1) and is independent of k:

Table[Expectation[Probability[x<z<y,z\[Distributed]𝒟],{x,y}\[Distributed]OrderDistribution[{𝒟,n},{k,k+1}]],{k,1,n-1}]

It is also independent of the distribution:

𝒟=ExponentialDistribution[1];n=6;

Table[Expectation[Probability[x<z<y,z\[Distributed]𝒟],{x,y}\[Distributed]OrderDistribution[{𝒟,n},{k,k+1}]],{k,1,n-1}]

Four six-sided dice are rolled. Find the expectation of the minimum value:

Expectation[x,x\[Distributed]OrderDistribution[{DiscreteUniformDistribution[{1,6}],4},1]]

N[%]

Find the expectation of the maximum value:

Expectation[x,x\[Distributed]OrderDistribution[{DiscreteUniformDistribution[{1,6}],4},4]]

N[%]

Find the expectation of the sum of the three largest values. Using the identity (Subscript[x, (4)])+ (Subscript[x, (3)])+ (Subscript[x, (2)])==(Subscript[x, 1])+ (Subscript[x, 2])+ (Subscript[x, 3])+ (Subscript[x, 4])- (Subscript[x, (1)]) and linearity of (RefLink[Expectation, paclet:ref/Expectation]), you get:

Expectation[x1+x2+x3+x4,{x1,x2,x3,x4}\[Distributed]ProductDistribution[{DiscreteUniformDistribution[{1,6}],4}]]-Expectation[x,x\[Distributed]OrderDistribution[{DiscreteUniformDistribution[{1,6}],4},1]]

N[%]

OpenersExampleSubsection13(Spacer1)Other Applications  (4)

A player bets amount a in a casino with no betting limit in a game with a chance of winning p. If he loses he doubles the bet, and if he wins he quits, hence the number of games played follows a geometric distribution, with expected number of games played represented as follows:

Expectation[k+1,k\[Distributed]GeometricDistribution[p]]

The cash reserve needed to win the k(^th) game:

cashReserve[k_]:=Sum[a (2^(n-1)),{n,1,k-1}]

The player always leaves the casino collecting the amount of the initial bet:

a (2^(k-1))- cashReserve[k]//Simplify

The cash reserve needed to execute the above strategy is finite only for strictly favorable games, where (1/2)<p≤1:

Expectation[cashReserve[k+1],k\[Distributed]GeometricDistribution[p],GenerateConditions->True]

A drug has proven to be effective in 40% of cases. Find the expected number of successes when applied to 700 cases:

Expectation[x,x\[Distributed]BinomialDistribution[700,0.4]]

A baseball player is a 0.300 hitter. Find the expected number of hits if the player comes to bat 3 times:

Expectation[x,x\[Distributed]BinomialDistribution[3,0.300]]

Find the mean if the signal-to-noise ratio has a Weibull distribution:

AverageSNR=Expectation[γ,γ\[Distributed]WeibullDistribution[α,β]]

OpenersExampleSection5(Spacer1)Properties & Relations  (9)

The expectation of an expression in a continuous distribution is defined by an integral:

Expectation[E^x, x\[Distributed]NormalDistribution[]]

Integrate[E^x PDF[NormalDistribution[],x],{x,-Infinity,Infinity}]

The expectation of an expression in a discrete distribution is defined by a sum:

Expectation[E^x, x\[Distributed]PoissonDistribution[1]]

Sum[E^x PDF[PoissonDistribution[1],x],{x,-Infinity,Infinity}]

A conditional expectation is defined by a ratio of expectation and probability:

𝒟=ExponentialDistribution[λ];

expr=x^2;cond=x>1;

Expectation[expr\[Conditioned]cond,x\[Distributed]𝒟]==((Expectation[Piecewise[{{expr, cond}}],x\[Distributed]𝒟])/(Probability[cond,x\[Distributed]𝒟]))

Use (RefLink[NExpectation, paclet:ref/NExpectation]) to find the numerical value of an expectation:

dist=ExponentialDistribution[1];

Expectation[E^(-x^2),x\[Distributed]dist]

N[%]

NExpectation[E^(-x^2),x\[Distributed]dist]

Compute the probability of an event:

Probability[1<x<3,x\[Distributed]ExponentialDistribution[2]]

Obtain the same result using (RefLink[Expectation, paclet:ref/Expectation]):

Expectation[Boole[1<x<3],x\[Distributed]ExponentialDistribution[2]]

(RefLink[N, paclet:ref/N])[Expectation[…]] is equivalent to (RefLink[NExpectation, paclet:ref/NExpectation]) if symbolic evaluation fails:

f[x_?NumericQ]:=x^2+2

Expectation[f[x],x\[Distributed]NormalDistribution[]]

N[%]

NExpectation[f[x],x\[Distributed]NormalDistribution[]]

(RefLink[Mean, paclet:ref/Mean]), (RefLink[Moment, paclet:ref/Moment]), (RefLink[Variance, paclet:ref/Variance]), and other properties are defined as expectations:

dist=ExponentialDistribution[3];

{Mean[dist],Expectation[x,x\[Distributed]dist]}

{Variance[dist],Expectation[(x-Mean[dist])^2,x\[Distributed]dist]}

{Moment[dist,5],Expectation[x^5,x\[Distributed]dist]}

{CentralMoment[dist,5],Expectation[(x-Mean[dist])^5,x\[Distributed]dist]}

{FactorialMoment[dist,5],Expectation[FactorialPower[x,5]//FunctionExpand,x\[Distributed]dist]}

Generating functions including (RefLink[MomentGeneratingFunction, paclet:ref/MomentGeneratingFunction]) are defined by an expectation:

dist=ExponentialDistribution[3];

{MomentGeneratingFunction[dist,t],Expectation[E^(t x),x\[Distributed]dist]}//Simplify

{CharacteristicFunction[dist,t],Expectation[E^(I t x),x\[Distributed]dist]}//Simplify

{CentralMomentGeneratingFunction[dist,t],Expectation[E^(t (x-Mean[dist])),x\[Distributed]dist]}//Simplify

{FactorialMomentGeneratingFunction[dist,t],Expectation[t^x,x\[Distributed]dist]}//Simplify

For a distribution specified by a list, (RefLink[Expectation, paclet:ref/Expectation]) is equivalent to using (RefLink[Mean, paclet:ref/Mean]):

data={1,2,3,4,5,6,7,8,9,10,11};

Expectation[x^2+3,x\[Distributed]data]

Mean[Table[x^2+3,{x,data}]]

OpenersExampleSection6(Spacer1)Possible Issues  (1)

By default, the (RefLink[GenerateConditions, paclet:ref/GenerateConditions]) for (RefLink[Integrate, paclet:ref/Integrate]) is set to (RefLink[False, paclet:ref/False]) and (RefLink[Expectation, paclet:ref/Expectation]) may give the wrong result:

Expectation[x,x\[Distributed]CauchyDistribution[a,b]]

In fact, this expectation is undefined:

Mean[CauchyDistribution[a,b]]

Set (RefLink[GenerateConditions, paclet:ref/GenerateConditions]) to (RefLink[True, paclet:ref/True]) to ensure the correct result:

Expectation[x,x\[Distributed]CauchyDistribution[a,b],GenerateConditions->True]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NExpectation, paclet:ref/NExpectation])  ▪  (RefLink[Distributed, paclet:ref/Distributed])  ▪  (RefLink[Conditioned, paclet:ref/Conditioned])  ▪  (RefLink[Probability, paclet:ref/Probability])  ▪  (RefLink[NProbability, paclet:ref/NProbability])  ▪  (RefLink[Mean, paclet:ref/Mean])  ▪  (RefLink[Moment, paclet:ref/Moment])  ▪  (RefLink[CentralMoment, paclet:ref/CentralMoment])  ▪  (RefLink[FactorialMoment, paclet:ref/FactorialMoment])  ▪  (RefLink[Sum, paclet:ref/Sum])  ▪  (RefLink[Integrate, paclet:ref/Integrate])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Probability & Statistics, paclet:guide/ProbabilityAndStatistics])}, {▪(RefLinkPlain[Random Variables, paclet:guide/RandomVariables])}, {▪(RefLinkPlain[Actuarial Computation, paclet:guide/ActuarialComputation])}, {▪(RefLinkPlain[Probability & Statistics with Quantities, paclet:guide/ProbabilityWithQuantities])}, {▪(RefLinkPlain[Numerical Data, paclet:guide/NumericalData])}, {▪(RefLinkPlain[Descriptive Statistics, paclet:guide/DescriptiveStatistics])}, {▪(RefLinkPlain[Reliability, paclet:guide/Reliability])}, {▪(RefLinkPlain[Solvers over Regions, paclet:guide/GeometricSolvers])}, {▪(RefLinkPlain[Random Graphs, paclet:guide/RandomGraphs])}})}})