필터 지우기
필터 지우기

Selecting the correct output.

조회 수: 1 (최근 30일)
Lewis Watson
Lewis Watson 2012년 11월 9일
I have writen this section of code.
function SPaths=AssetPaths(S0,mu,sigma,T,NSteps,NRepl)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
SPaths = zeros(NRepl, 1+NSteps);
SPaths(:,1) = S0;
dt = T/NSteps;
nudt = (mu-0.5*sigma^2)*dt;
sidt = sigma*sqrt(dt);
for i=1:NRepl
for j=1:NSteps
SPaths(i,j+1)=SPaths(i,j)*exp(nudt + sidt*randn);
end
end
end
It represents the price of an option with s0 as the start price, mu as the drift, sigma as the volitality, T as time horizon, Nsteps as the time steps and NRepl as the number of runs.
With input - AssetPaths(10,.2,.05,1,60,1) I generate 61 coloums of prices and can plot a graph from those, what I need to be able to do is select the price at a set time eg coloum 10 or coloum 61 (the end) to find diffrences from the start price etc. any Ideas on what command to use or how to go about this would be much appreciated.

채택된 답변

Taniadi
Taniadi 2012년 11월 9일
If you want to the difference, eg. the tenth column and the start price, I think that it can be done with 1. define start price (maybe the first data or anywhere) as a variable (e.g. first_prize), 2. if you want to get the difference between tenth column and the first price then: diference = A(:,10) - first_price (or you can substitute first_prize with known value). Here, the pize data is assumed to be stored as A. And A(:,10) is the command to call all values in tenth column in matrix A.
Is it like what you're asking?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by