フィルターのクリア

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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by