SHARE
TWEET

Hello

a guest Apr 26th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function price = GenericLS(S0,X,r,T,sigma,NSteps,NRepl,fhandles)
  2. dt = T/NSteps;discount = exp(-r*dt);
  3. discountVet = exp(-r*dt*(1:NSteps));
  4. NBasis = length(fhandles); % number of basis functions
  5. a = zeros(NBasis,1); % regression
  6. parametersRegrMat = zeros(NRepl,NBasis);
  7. % generate sample paths
  8. SPaths=GenPathsA(S0,r,sigma,T,NSteps,NRepl);
  9. SPaths(:,1) = []; % get rid of starting prices
  10. %
  11. CashFlows = max(0, X - SPaths(:,NSteps));
  12. ExerciseTime = NSteps*ones(NRepl,1);
  13. for step = NSteps-1:-1:1
  14.     InMoney = find(SPaths(:,step) < X);
  15.     XData = SPaths(InMoney,step);
  16.     for i=1:NBasis
  17.         RegrMat(1:length(XData), i) = feval(fhandles(i), XData);
  18.     end
  19.     YData = CashFlows(InMoney) .* discountVet(ExerciseTime(InMoney) - step);
  20.     a = RegrMat(1:length(XData),:) \ YData;
  21.     IntrinsicValue = X - XData;
  22.     ContinuationValue = RegrMat(1:length(XData),:) * a;
  23.     Exercise = find(IntrinsicValue > ContinuationValue);
  24.     k = InMoney(Exercise);
  25.     CashFlows(k) = IntrinsicValue(Exercise);
  26.     ExerciseTime(k) = step;
  27. end % for
  28. price = mean(CashFlows.*discountVet(ExerciseTime));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top