Integral construction and betainv

1 次查看(过去 30 天)
Hi everyone!!!
I need some help to construct the fun in order to run the integral that contains betainv.
My code is the following:
m=1000;
l=1000000*0.6;
pbar= [0.02,0.02,0.05,0.05,0.1,0.1];
rho=[0.2,0.8,0.2,0.8,0.2,0.8];
a=pbar.*(1-rho)./rho;
b= (1-pbar).*(1-rho)./rho;
format long
VaR_95=m*l*betainv(0.95,a,b)
VaR_99=m*l*betainv(0.99,a,b)
VaR_999=m*l*betainv(0.999,a,b)
alpha=0.95;
fun = @(a,b, alpha) l*m*betainv(0.95,a,b) ;
ES_95=(1/(1-alpha))*integral(@(alpha) fun(a,b, alpha),alpha,1)
In the end, in finding ES_95, matlab gives me errors and not result.
Thank you in advance!

采纳的回答

Star Strider
Star Strider 2020-11-20
Since ‘pbar’ and ‘rho’ are vectors, use the 'ArrayValued' name-value pair in the integral call:
ES_95=(1/(1-alpha))*integral(@(alpha) fun(a,b, alpha),alpha,1, 'ArrayValued',1)
That worked when I tried it, and produced:
ES_95 =
1.0e+08 * [0.751401809017565 0.008479691310700 1.560368870762743 2.757477132869889 2.361442477520542 5.742979039200923]
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by