Code covered by the BSD License  

Highlights from
Exercises in Advanced Risk and Portfolio Management

from Exercises in Advanced Risk and Portfolio Management by Attilio Meucci
text and comments on solutions available at http://symmys.com/node/170

h=pHist(X,p,nBins)
function h=pHist(X,p,nBins)

[n,x] = hist(X,nBins);
D=x(2)-x(1);
np=0;
for s=1:length(x)
    Index=find( (X>=x(s)-D/2) & (X<=x(s)+D/2) );
    np(s)=sum(p(Index));
    f=np/D;
end

h=bar(x,f,1);
h = findobj(gca,'Type','patch');
set(h,'FaceColor',.6*[1 1 1],'EdgeColor',.6*[1 1 1])
grid on

Contact us at files@mathworks.com