%% data tsc=yahoo_prices({'GOOG'},'30-Sep-2009','30-Sep-2011'); prices=tsc.GOOG.Data(not(isnan(tsc.GOOG.Data))); % adjusted close prices returns=log(prices(2:end)./prices(1:end-1)); % compound returns %% Gosset student-t density % theta(1) is location, theta(2) is scale, nu is shape density=@(x,theta,nu)gamma(nu/2+1/2)/gamma(nu/2)/gamma(1/2)/sqrt(nu)... *(1+((x-theta(1))./theta(2)).^2/nu).^(-nu/2-1/2)/theta(2); %% likelihood logLikelihood=@(returns,theta,nu)sum(log(density(returns,theta,nu))); estimate=@(nu)fminsearch(@(theta)-logLikelihood(returns,theta,nu),[0.0 0.01]); %% plot fplot(@(nu)logLikelihood(returns,estimate(nu),nu),[1 10])