function [R Gr] = risk(weigths,sig1,sig2,ro)
% [R Gr] = risk(weigths,sig2_1,sig2_2,ro)
% weigths(1): the wiegth associated to the first asset
% weigths(2): the wiegth associated to the second asset
% sig2_1: the variance associated to the first asset
% sig2_2: the variance associated to the first asset
% ro: the correlation between the first and the second assets.

w1 = weigths(1);
w2 = weigths(2);
eps = 0.000001;
sig2_1 = sig1^2;
sig2_2 = sig2^2;

w1_b = w1 + eps;
w2_b = w2 + eps;
R = sqrt((w1^2)*sig2_1 + (w2^2)*sig2_2 + 2*w1*w2*sqrt(sig2_1)*sqrt(sig2_2)*ro);
R_1 = sqrt((w1_b^2)*sig2_1 + (w2^2)*sig2_2 + 2*w1_b*w2*sqrt(sig2_1)*sqrt(sig2_2)*ro);
R_2 = sqrt((w1^2)*sig2_1 + (w2_b^2)*sig2_2 + 2*w1*w2_b*sqrt(sig2_1)*sqrt(sig2_2)*ro);
Gr(1,1) = (R_1 - R)/eps;
Gr(2,1) = (R_2 - R)/eps;
