% this script estimates the probability of drawdowns in excess of
% 25% for a fixed mixture of a riskless and risky asset
sims=10000;
steps=252;
weight=0.55; % initial proportion of portfolio in risky asset
risky_paths=exp(cumsum([zeros(1,sims); ...
        (.10-.30*.30/2)/steps+.30/sqrt(steps)*randn(steps,sims)]));
riskless_paths=repmat(exp(0:.05/steps:.05)',1,sims);
portfolio_paths=weight*risky_paths+(1-weight)*riskless_paths;
drawdowns=max(1-portfolio_paths./ ...
    arrayfun(@(n,m)max(portfolio_paths(1:n,m)), ...
        repmat(1:steps+1,sims,1)',repmat(1:sims,steps+1,1)));
alpha=mean(drawdowns>.25);

% plot([risky_paths(:,1:5),riskless_paths(:,1)]);
% hist(drawdowns,100);