clear;

%Parameters

M = 200;

dt = 0.5;

T = repmat(365/4:-dt:0,M,1);

N = size(T,2);

K(1:M,1:N) = 50;

r(1:M,1:N) = 0.01;

sigma(1:M,1:N) = 0.25;

toss = randn(M,N-1);

S = cumsum([K(:,1), toss],2); %Stock Paths

V = blsprice(S, K, r, T, sigma); %BSM Price

delta = blsdelta(S, K, r, T, sigma); %BSM delta

X = V-(delta.*S); %Portfolio value

mean = mean(mean(X)) %Sample mean

var = var(var(X)) %Sample variance

So my problem is that when I decrease dt to make the time steps smaller, some of the underlyings (stock prices, S) become negative and then the 'blsprice' function cannot compute the price of the option because it is expecting a non-negative entry. Any suggestions on how to solve this? The model works fine for dt = 0.5, I just cannot make it smaller. Thanks for any input.