How can I get this graph in MATLAB? This is the payoff of down-and-out call option with barrier B=120
, strike K=100
. Should I somehow combine two graphs in one picture?
You can do it in various ways. Here are two of them:
function q54615569(B, K)
y = @(x)(x>=B).*(x-K);
x = 0:2*K;
figure(); plot(x, y(x));
xlabel('S(T)');
function q54615569(B, K)
y = @(x)x-K;
x = 0:2*K;
figure(); hL = plot( x(x<=B), 0.*x(x<=B), x(x>=B), y(x(x>=B)) );
set(hL, 'Color', lines(1), 'Linestyle', 'none', 'Marker','o','MarkerSize', 2,...
'MarkerFaceColor', lines(1));
xlabel('S(T)');