Selecting the correct output.

2 次查看(过去 30 天)
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 中查找有关 Price and Analyze Financial Instruments 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by