Вы находитесь на странице: 1из 3

金融商品設計與評價 HW1

第七組

PV

設定變數 r:利率,n:期數,df:折現因子,x:現值。cont 為是否要繼續,Y 為繼續執行,N 則為離開。先


輸入利率、期數後,將當期的現金流折現,計算出本利和後,直到 n 期結束,x 即為現值。int2str 將整數轉換
成字串 w 顯示。

% HW1 present value


cont='Y';Y='Y';N='N'; %重複執行
while cont == 'Y'
r=input('請輸入利率(r):');
n=input('請輸入期數(n):');
INP = zeros(1,n);
x=0;
df=1+r;
for t=1:n
Code a=num2str(t);
INP(t)=input(['請輸入第',a,'期現金流:']);
INP(t)=INP(t)/df;
x=x+INP(t);
df=df*(1+r);
end
w=int2str(x);
disp(['PV=',w]);
cont =input('是否繼續(Y/N)?');
end

>>請輸入利率(r):0.1
請輸入期數(n):3
請輸入第 1 期現金流:10
Outcome 請輸入第 2 期現金流:10
請輸入第 3 期現金流:110
PV=100
是否繼續(Y/N)?N

Black-Scholes formula

設定變數 C:買權價格,P:賣權價格,S0:標的資產現貨價格,X:選擇權的履約價格,r:無風險利率,T:
到期日,sigma:股價報酬的波動性。將以上變數帶入 Black-Scholes formula,最後得出買權價格 C 為
8.9160,賣權價格 P 為 6.9359。

function blackscholes()
cont='Y';Y='Y';N='N'; % Continuous Execution
while cont == 'Y'
Code S0=input('Please enter the current stock price (S0): ');
X=input('Please enter the strike price (X): ');
r=input('Please enter the risk-free rate (r): ');
T=input('Please enter the time to maturity (T): ');
sigma=input('Please enter the volatility of returns of the
underlying asset (sigma): ');

d1=(log(S0/X)+(r+sigma^2/2)*T) / (sigma*sqrt(T));
d2=d1-(sigma*sqrt(T));

% normcdf() is the cumulative distribution function of the


standard normal distribution
C=S0*normcdf(d1)-X*(exp(-r*T)*normcdf(d2)); % The call premium
P=X*exp(-r*T)*normcdf(-d2)-S0*normcdf(-d1); % The put premium

C_str=num2str(C);
P_str=num2str(P);
disp(['Call Premium = ',C_str]);
disp(['Put Premium = ',P_str]);

cont =input('Continue (Y/N)? ');


end

>> blackscholes
Please enter the current stock price (S0): 100
Please enter the strike price (X): 100
Please enter the risk-free rate (r): 0.02
Please enter the time to maturity (T): 1
Outcome
Please enter the volatility of returns of the underlying asset
(sigma): 0.2
Call Premium = 8.916
Put Premium = 6.9359
Continue (Y/N)?

Graphs of options

選擇權的履約價格 X 設定為 50,權利金設定為 2,標的資產價格區間以 0.05 間隔,從 40 遞增至 60,依序畫出


"long call"、"short call"、"long put"、"short put"四張圖。

function plotoptions()
X = 50; % The strike price
c = 2; % The option premium
St = 40:0.05:60; % The range of the price of the underlying asset

% Plot Long Call


subplot(2,2,1);
plot(St, max(St-X, 0) - c);
title("long call");
Code xlabel("S");
ylabel("profit");
axis([40 60 -10 10])

% Plot Short Call


subplot(2,2,2);
plot(St, -max(St-X, 0) + c);
title("short call");
xlabel("S");
ylabel("profit");
axis([40 60 -10 10])

% Plot Long Put


subplot(2,2,3);
plot(St, max(X-St, 0) - c);
title("long put");
xlabel("S");
ylabel("profit");
axis([40 60 -10 10])

% Plot Short Put


subplot(2,2,4);
plot(St, -max(X-St, 0) + c);
title("short put");
xlabel("S");
ylabel("profit");
axis([40 60 -10 10])
end

Outcome

Вам также может понравиться