dimensions - Fix matlab code with error -


i understand there error dimensions in line dr=(r-v*v/2)*dt . have little knowledge of matlab. fix it, please. code small , simple. maybe find time look

 function [optionprice] = upandoutcalloption(s,r,v,x,b,t,dt)     t = 0;     dr=[];     pert=[];     while (t < t) & (s < b)         t = t + dt;         dr = (r - v.*v./2).*dt;         pert = v.*sqrt( dt ).*randn();         s = s.*exp(dr + pert);     end     if s<b         % within barrier, price european option.         optionprice = exp(-r.*t).* max(0, s - x);     else         % hit barrier, option withdrawn.         optionprice = 0;     end     end 

call function of kind: k=1:amountofoptions [optionprices(k)] = upandoutcalloption(stockprice(k)*o,riskfreerate(k)*o,... volatility(k)*o, strike(k)*o, barrier(k)*o, timetoexpiry(k)*o, samplerate(k)*o); result(k) = mean(optionprices(k)); end

therefore, difficulties.

it's know problem within dr = (r - v.*v./2).*dt;. command has many possible problems related dimensions:

  1. here doing element-wise multiplication (because of .*) matrices, requires (in case of command) r has same number of rows , columns v (since because of element-wise, v.*v/2 has same size v).

  2. moreover, unnecessary element-wise division scalar number, means there no need have ./2 in matlab.

  3. and, finally, since it's element-wise multiplication again, matrix (r - v.*v./2) must have same number of rows , columns matrix dt.

check here more information matlab's matrix operations.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -