Borrar filtros
Borrar filtros

Error: Not enough input arguments

4 visualizaciones (últimos 30 días)
Dawid Brits
Dawid Brits el 24 de Sept. de 2019
Respondida: Walter Roberson el 24 de Sept. de 2019
Hi all, Im working on a code that simulates a stock price over two years and then compares it to a strike price (call options). I want to simulate the stock price 3000 for each starting value (30 to 150), then take the average payout (for that particular staring price) and plot that vs the starting price. The idea is that if the final price is higher than the strike price (starting price) you get a payout equal to the difference between the final and strike price, if not you get 0.
I keep getting an error (Not enough input arguments.) gives the error in the line.
for m = 1 : n_iterations
Here is my code.
r = 0.05;
T = 2;
dt = 1/365;
sigma = sqrt(r);
rng('shuffle')
n_iterations = 3000;
eta = randn(365*T+1, n_iterations);
S = zeros(365*T, n_iterations);
for S_0 = 30 : 150
S(1, :) = S_0 ;
n = 1 : n_iterations;
for k = 1 : 365*T
S(k+1, n) = S(k, n) + S(k, n).*r.*dt + sqrt(dt).*sigma.*S(k, n).*eta(k, n);
end
strike = S_0;
price = S((365*T + 1), :);
eurocallreturn(strike, price, n_iterations);
avereturn = mean(eurocallreturn);
% hold on
% plot(strike, avereturn)
% xlabel('Price')
% ylabel('Return')
end
%plot([50:130], exp(0.05*2)*blsprice([50:130], 90, 0.05, 2, sqrt(0.05)))
function R = eurocallreturn(strike, price, n_iterations)
for m = 1 : n_iterations
R = zeros(1, n_iterations);
if price(m) > strike
R(m) = price(m) - strike;
else if price(m) <= strike
R(m) = 0;
end
end
end
end
%Why is it giving me this error? I have 3 inputs into the function,
% and all these inputs are clearly defined before the function is called?

Respuesta aceptada

Walter Roberson
Walter Roberson el 24 de Sept. de 2019
eurocallreturn(strike, price, n_iterations);
That line calls the function to compute a value, and then discards the value because the semi-colon says not to display what was returned.
avereturn = mean(eurocallreturn);
And there is a second call to eurocallreturn, this one without arguments -- not enough input arguments.
Perhaps
euroreturns = eurocallreturn(strike, price, n_iterations);
avereturn = mean(euroreturns);

Más respuestas (0)

Categorías

Más información sobre Price and Analyze Financial Instruments en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by