813 Ddaa 7 Bee 22585 B 451

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

PV

% Algorithm for evaluating present value


% y discount rate
% n number of cash flow
% cash flow
input y;
input n;
input cashflow;
real x;
real d;
x = 0;
d = 1 + y;
for i = 1 : n
x = x + cashflow(i)/d;
d = d * (1 + y);
end
% Display the result
fprintf('Present Value: $%.2f\n', x);
BS
% Black-Scholes Model
S0 = 100; % Current stock price
X = 100; % Strike price
r = 0.02; % Risk-free interest rate
T = 1; % Time to expiration (1 year)
sigma = 0.2; % Volatility
% Type of option ('call')
option_type = 'call';
% Calculate the option price
option_price_call = blackscholes(S0, X, r, T, sigma, option_type);
% Type of option ('put')
option_type = 'put';
% Calculate the option price
option_price_put = blackscholes(S0, X, r, T, sigma, option_type);
% Display the result
fprintf('Option price call: $%.2f\n', option_price_call);
fprintf('Option price put: $%.2f\n', option_price_put);
%function
function price = blackscholes(S0, X, r, T, sigma, option_type)
% S0: Current stock price
% X: Strike price
% r: Risk-free interest rate
% T: Time to expiration (in years)
% sigma: Volatility of the underlying stock
% option_type: 'call' or 'put'
% Calculate d1 and d2
d1 = (log(S0 / X) + (r + (sigma^2) / 2) * T) / (sigma * sqrt(T));
d2 = d1 - sigma * sqrt(T);
% Calculate option price based on the option type
if strcmp(option_type, 'call')
price = S0 * normcdf(d1) - X * exp(-r * T) * normcdf(d2);
elseif strcmp(option_type, 'put')
price = X * exp(-r * T) * normcdf(-d2) - S0 * normcdf(-d1);
else
error('Invalid option type. Use ''call'' or ''put''.');
end
end

You might also like