lundi 28 novembre 2016

Replace a row with zeros if one of its elements is higher than a fix number

I am doing the pricing of a Barrier option (if the underlying asset goes above 120, it cease to exist) in R using MC simulation.

Basically, I have a matrix (10000X100) that can have values raning from around 30 to 200 and I would like that if a value in a row goes above 120, all the values in this row will be set to 0.

I think people do it like that in MatLab but I can't do it in R:

nbrsim = 10000;
nbr_step = 100;
S = zeros(nbrsim,nbre_step+1);
    for j = 1:nbrsim
    if min(S(j,:)) <= B
       l(j) = 0;
    else
        l(j) = 1;
    end
    vectpayoffs(j) = l(j)*max(ST(j) - K,0);
    end

I will be very glad if someone knows how to do this computation

Aucun commentaire:

Enregistrer un commentaire