Using structure matlab code -


i have been working in matlab, there questions. @ code, please. if amountofoptions = 2, should optionprice = [x x] . vector size optionprice(1x2). seems receives output produces gives last result of assignment.

function [startstockprice, strike, barrier, riskfreerate, timetoexpiry, volatility, callorput, upordown, optionprice, time] = outbarrieroption(amountofoptions)     %%%%%%%%%% option parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     startstockprice   = 70 + 40 * rand(1,amountofoptions);      % stock price starts @ $100.     strike = 120 + 30 * rand(1,amountofoptions);                 % strike price option ($).     barrier = 300 + 300 * rand(1,amountofoptions);              % barrier price option ($).     riskfreerate = 0.05 + 0.1 * rand(1,amountofoptions);        % 0.5 annual percent.     timetoexpiry = fix(1 + 3 * rand(1, amountofoptions));       % lifetime of option in years. (time maturity)     volatility   = 0.35 + 0.3 * rand(1,amountofoptions);        % 20% annual volatility.                                          % upordown - 'u' or 'd'     m = 1e4; % number of monte-carlo trials     n = 100; % number of observations     optionprice = 0;     tic;     k = 1:amountofoptions         dt(k)=timetoexpiry(k)/n;         i=1:m             s(1) = startstockprice(k)*exp((riskfreerate(k)-(volatility(k)*volatility(k)/2)*dt(k)) + volatility(k)*sqrt(dt(k))*randn);             final_vals=[s(1)];             j=1:n-1;                 s(j + 1) = s(j)* exp((riskfreerate(k) - 0.5* volatility(k)*volatility(k))*dt(k) + volatility(k)* sqrt(dt(k))* randn);                 final_vals=s(1:j+1);             end         end         if max(final_vals) <= barrier(k)             option_values=max(final_vals - strike(k),0); % evaluate call option options             present_vals = exp(-riskfreerate(k)*timetoexpiry(k))*option_values; % discount under r-n assumption             optionprice = mean(present_vals); % take average         else             % hit barrier, option withdrawn.             present_vals = 0;             optionprice = mean(present_vals);         end      end     time = toc;     end 


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -