% odhady vasickovho modelu
% dr=(a-b*r)dt+sigma*dw
% z dat r=(r_1,r_2,..., r_n)

% transformovane parametre: 
% beta=b/a, alfa=exp(-a*dt), v2=(sigma^2/(2*a))*(1-exp(-2*a*dt))

% Damiano Brigo, Fabio Mercurio: Interest Rate Models - Theory and Practice. Second Edition. Springer, 2007
% Kapitola 3.1.2, str. 61-62

n=length(r);

alfa=((n-1)*sum(r(2:n).*r(1:n-1))-sum(r(2:n))*sum(r(1:n-1)))/((n-1)*sum(r(1:n-1).^2)-(sum(r(1:n-1)))^2);
beta=sum(r(2:n)-alfa*r(1:n-1))/((n-1)*(1-alfa));
v2=sum((r(2:n)-alfa*r(1:n-1)-beta*(1-alfa)*ones(n-1,1)).^2)/(n-1);

