Contents

function OptionsStraDemo
%%期权复式策略Demo
% by LiYang @www.matlabsky.com
% Email:farutoliyang@gmail.com
% 2014/01/09

A Little Clean Work

tic;
% clear;
% clc;
% close all;
format compact;

straddle && strangle

scrsz = get(0,'ScreenSize');
figure('Position',[scrsz(3)*1/4 scrsz(4)*1/6 scrsz(3)*4/5 scrsz(4)]*3/4);

% 买入跨式策略损益图(long straddle)
subplot(221)

price = 1000:1:3000;

call_strike = 2000;
call_value = 150;
call_pl = (price<=call_strike).*-1*call_value + (price>call_strike).*(price-call_strike-call_value);
plot(price, call_pl);
hold on;

put_strike = 2000;
put_value = 100;
put_pl = (price>=put_strike).*-1*put_value + (price<put_strike).*(-1*price+put_strike-put_value);
plot(price, put_pl);

total_pl = call_pl + put_pl;
plot(price, total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
ylim( [-300 300] );
grid on;
title('买入跨式策略损益图(long straddle) Demo', 'FontWeight', 'Bold');
% 卖出跨式策略损益图(short straddle)
subplot(222)

price = 1000:1:3000;

call_strike = 2000;
call_value = 150;
call_pl = (price<=call_strike).*-1*call_value + (price>call_strike).*(price-call_strike-call_value);
plot(price, -call_pl);
hold on;

put_strike = 2000;
put_value = 100;
put_pl = (price>=put_strike).*-1*put_value + (price<put_strike).*(-1*price+put_strike-put_value);
plot(price, -put_pl);

total_pl = call_pl + put_pl;
plot(price, -total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
ylim( [-300 300] );
grid on;
title('卖出跨式策略损益图(short straddle) Demo', 'FontWeight', 'Bold');
% 买入勒式(宽跨式)策略损益图(long strangle)
subplot(223)

price = 1000:1:3000;

call_strike = 2000;
call_value = 150;
call_pl = (price<=call_strike).*-1*call_value + (price>call_strike).*(price-call_strike-call_value);
plot(price, call_pl);
hold on;

put_strike = 1500;
put_value = 100;
put_pl = (price>=put_strike).*-1*put_value + (price<put_strike).*(-1*price+put_strike-put_value);
plot(price, put_pl);

total_pl = call_pl + put_pl;
plot(price, total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
ylim( [-300 300] );
grid on;
title('买入勒式(宽跨式)策略损益图(long strangle) Demo', 'FontWeight', 'Bold');
% 卖出勒式(宽跨式)策略损益图(short strangle)
subplot(224)

price = 1000:1:3000;

call_strike = 2000;
call_value = 150;
call_pl = (price<=call_strike).*-1*call_value + (price>call_strike).*(price-call_strike-call_value);
plot(price, -call_pl);
hold on;

put_strike = 1500;
put_value = 100;
put_pl = (price>=put_strike).*-1*put_value + (price<put_strike).*(-1*price+put_strike-put_value);
plot(price, -put_pl);

total_pl = call_pl + put_pl;
plot(price, -total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
ylim( [-300 300] );
grid on;
title('卖出勒式(宽跨式)策略损益图(short strangle) Demo', 'FontWeight', 'Bold');

垂直价差套利

scrsz = get(0,'ScreenSize');
figure('Position',[scrsz(3)*1/4 scrsz(4)*1/6 scrsz(3)*4/5 scrsz(4)]*3/4);

% 牛市看涨期权垂直价差套利
subplot(221)

price = 1000:1:3000;

strike = 1500;
value = 200;
buy_call_pl = BuyCallPL( price,  strike, value);
demopl = buy_call_pl;
plot(price, demopl);
hold on;

strike = 2000;
value = 100;
sell_call_pl = -1*BuyCallPL( price,  strike, value);
demopl = sell_call_pl;
plot(price, demopl);
hold on;

total_pl = buy_call_pl + sell_call_pl;
plot(price, total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('牛市看涨期权垂直价差套利 Demo', 'FontWeight', 'Bold');
% 牛市看跌期权垂直价差套利
subplot(222)

price = 1000:1:3000;

strike = 1500;
value = 100;
buy_put_pl = BuyPutPL( price,  strike, value);
demopl = buy_put_pl;
plot(price, demopl);
hold on;

strike = 2000;
value = 200;
sell_put_pl = -1*BuyPutPL( price,  strike, value);
demopl = sell_put_pl;
plot(price, demopl);
hold on;

total_pl = buy_put_pl + sell_put_pl;
plot(price, total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('牛市看跌期权垂直价差套利 Demo', 'FontWeight', 'Bold');

% 熊市看涨期权垂直价差套利
subplot(223)

price = 1000:1:3000;

strike = 1500;
value = 200;
buy_call_pl = BuyCallPL( price,  strike, value);
demopl = buy_call_pl;
plot(price, -demopl);
hold on;

strike = 2000;
value = 100;
sell_call_pl = -1*BuyCallPL( price,  strike, value);
demopl = sell_call_pl;
plot(price, -demopl);
hold on;

total_pl = buy_call_pl + sell_call_pl;
plot(price, -total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('熊市看涨期权垂直价差套利 Demo', 'FontWeight', 'Bold');
% 熊市看跌期权垂直价差套利
subplot(224)

price = 1000:1:3000;

strike = 1500;
value = 100;
buy_put_pl = BuyPutPL( price,  strike, value);
demopl = buy_put_pl;
plot(price, -demopl);
hold on;

strike = 2000;
value = 200;
sell_put_pl = -1*BuyPutPL( price,  strike, value);
demopl = sell_put_pl;
plot(price, -demopl);
hold on;

total_pl = buy_put_pl + sell_put_pl;
plot(price, -total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('熊市看跌期权垂直价差套利 Demo', 'FontWeight', 'Bold');

butterfly

scrsz = get(0,'ScreenSize');
figure('Position',[scrsz(3)*1/4 scrsz(4)*1/6 scrsz(3)*4/5 scrsz(4)]*3/4);

% 买入蝶式(看涨)价差组合策略(long butterfly using call)
subplot(221)

price = 0:1:3000;

strike = 1000;
value = 400;
buy_call_pl1 = BuyCallPL( price,  strike, value);
demopl = buy_call_pl1;
plot(price, demopl);
hold on;

strike = 2000;
value = 200;
buy_call_pl3 = BuyCallPL( price,  strike, value);
demopl = buy_call_pl3;
plot(price, demopl);
hold on;

strike = 1500;
value = 250;
sell_call_pl = -2*BuyCallPL( price,  strike, value);
demopl = sell_call_pl;
plot(price, demopl);
hold on;

total_pl = buy_call_pl1 + sell_call_pl +buy_call_pl3;
plot(price, total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('买入蝶式(看涨)价差组合策略(long butterfly using call)', 'FontWeight', 'Bold');

% 买入蝶式(看跌)价差组合策略(long butterfly using put)
subplot(222)

price = 0:1:3000;

strike = 1000;
value = 200;
buy_put_pl1 = BuyPutPL( price,  strike, value);
demopl = buy_put_pl1;
plot(price, demopl);
hold on;

strike = 2000;
value = 400;
buy_put_pl3 = BuyPutPL( price,  strike, value);
demopl = buy_put_pl3;
plot(price, demopl);
hold on;

strike = 1500;
value = 250;
sell_put_pl = -2*BuyPutPL( price,  strike, value);
demopl = sell_put_pl;
plot(price, demopl);
hold on;

total_pl = buy_put_pl1 + sell_put_pl +buy_put_pl3;
plot(price, total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('买入蝶式(看跌)价差组合策略(long butterfly using put)', 'FontWeight', 'Bold');

% 卖出蝶式(看涨)价差组合策略(long butterfly using call)
subplot(223)

price = 0:1:3000;

strike = 1000;
value = 400;
buy_call_pl1 = BuyCallPL( price,  strike, value);
demopl = buy_call_pl1;
plot(price, -demopl);
hold on;

strike = 2000;
value = 200;
buy_call_pl3 = BuyCallPL( price,  strike, value);
demopl = buy_call_pl3;
plot(price, -demopl);
hold on;

strike = 1500;
value = 250;
sell_call_pl = -2*BuyCallPL( price,  strike, value);
demopl = sell_call_pl;
plot(price, -demopl);
hold on;

total_pl = buy_call_pl1 + sell_call_pl +buy_call_pl3;
plot(price, -total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('卖出蝶式(看涨)价差组合策略(long butterfly using call)', 'FontWeight', 'Bold');

% 卖出蝶式(看跌)价差组合策略(long butterfly using put)
subplot(224)

price = 0:1:3000;

strike = 1000;
value = 200;
buy_put_pl1 = BuyPutPL( price,  strike, value);
demopl = buy_put_pl1;
plot(price, -demopl);
hold on;

strike = 2000;
value = 400;
buy_put_pl3 = BuyPutPL( price,  strike, value);
demopl = buy_put_pl3;
plot(price, -demopl);
hold on;

strike = 1500;
value = 250;
sell_put_pl = -2*BuyPutPL( price,  strike, value);
demopl = sell_put_pl;
plot(price, -demopl);
hold on;

total_pl = buy_put_pl1 + sell_put_pl +buy_put_pl3;
plot(price, -total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('卖出蝶式(看跌)价差组合策略(long butterfly using put)', 'FontWeight', 'Bold');

condor

scrsz = get(0,'ScreenSize');
figure('Position',[scrsz(3)*1/4 scrsz(4)*1/6 scrsz(3)*4/5 scrsz(4)]*3/4);

% 买入鹰式(看涨)价差组合策略(long condor using call)
subplot(221)

price = 0:1:3000;

strike = 1000;
value = 400;
buy_call_pl1 = BuyCallPL( price,  strike, value);
demopl = buy_call_pl1;
plot(price, demopl);
hold on;

strike = 2000;
value = 200;
buy_call_pl3 = BuyCallPL( price,  strike, value);
demopl = buy_call_pl3;
plot(price, demopl);
hold on;

strike = 1700;
value = 210;
sell_call_pl1 = -1*BuyCallPL( price,  strike, value);
demopl = sell_call_pl1;
plot(price, demopl);
hold on;

strike = 1300;
value = 380;
sell_call_pl2 = -1*BuyCallPL( price,  strike, value);
demopl = sell_call_pl2;
plot(price, demopl);
hold on;

total_pl = buy_call_pl1 + sell_call_pl1 +sell_call_pl2 +buy_call_pl3;
plot(price, total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('买入鹰式(看涨)价差组合策略(long condor using call)', 'FontWeight', 'Bold');

% 买入鹰式(看跌)价差组合策略(long condor using put)
subplot(222)

price = 0:1:3000;

strike = 1000;
value = 200;
buy_put_pl1 = BuyPutPL( price,  strike, value);
demopl = buy_put_pl1;
plot(price, demopl);
hold on;

strike = 2000;
value = 400;
buy_put_pl3 = BuyPutPL( price,  strike, value);
demopl = buy_put_pl3;
plot(price, demopl);
hold on;

strike = 1700;
value = 380;
sell_put_pl1 = -1*BuyPutPL( price,  strike, value);
demopl = sell_put_pl1;
plot(price, demopl);
hold on;

strike = 1300;
value = 210;
sell_put_pl2 = -1*BuyPutPL( price,  strike, value);
demopl = sell_put_pl2;
plot(price, demopl);
hold on;

total_pl = buy_put_pl1 + sell_put_pl1 +sell_put_pl2 +buy_put_pl3;
plot(price, total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('买入鹰式(看跌)价差组合策略(long condor using put)', 'FontWeight', 'Bold');

% 卖出鹰式(看涨)价差组合策略(long condor using call)
subplot(223)

price = 0:1:3000;

strike = 1000;
value = 400;
buy_call_pl1 = BuyCallPL( price,  strike, value);
demopl = buy_call_pl1;
plot(price, -demopl);
hold on;

strike = 2000;
value = 200;
buy_call_pl3 = BuyCallPL( price,  strike, value);
demopl = buy_call_pl3;
plot(price, -demopl);
hold on;

strike = 1700;
value = 210;
sell_call_pl1 = -1*BuyCallPL( price,  strike, value);
demopl = sell_call_pl1;
plot(price, -demopl);
hold on;

strike = 1300;
value = 380;
sell_call_pl2 = -1*BuyCallPL( price,  strike, value);
demopl = sell_call_pl2;
plot(price, -demopl);
hold on;

total_pl = buy_call_pl1 + sell_call_pl1 +sell_call_pl2 +buy_call_pl3;
plot(price, -total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('卖出鹰式(看涨)价差组合策略(long condor using call)', 'FontWeight', 'Bold');

% 卖出鹰式(看跌)价差组合策略(long condor using put)
subplot(224)

price = 0:1:3000;

strike = 1000;
value = 200;
buy_put_pl1 = BuyPutPL( price,  strike, value);
demopl = buy_put_pl1;
plot(price, -demopl);
hold on;

strike = 2000;
value = 400;
buy_put_pl3 = BuyPutPL( price,  strike, value);
demopl = buy_put_pl3;
plot(price, -demopl);
hold on;

strike = 1700;
value = 380;
sell_put_pl1 = -1*BuyPutPL( price,  strike, value);
demopl = sell_put_pl1;
plot(price, -demopl);
hold on;

strike = 1300;
value = 210;
sell_put_pl2 = -1*BuyPutPL( price,  strike, value);
demopl = sell_put_pl2;
plot(price, -demopl);
hold on;

total_pl = buy_put_pl1 + sell_put_pl1 +sell_put_pl2 +buy_put_pl3;
plot(price, -total_pl, 'r', 'LineWidth', 1.5);

ylabel('P&L');
xlabel('标的物价格');
% ylim( [-500 500] );
grid on;
title('卖出鹰式(看跌)价差组合策略(long condor using put)', 'FontWeight', 'Bold');

sub function-BuyCallPL

    function pl = BuyCallPL( price,  call_strike, call_value)
        pl = ...
            (price<=call_strike).*-1*call_value + (price>call_strike).*(price-call_strike-call_value);
    end

sub function-BuyPutPL

    function pl = BuyPutPL( price,  put_strike, put_value)
        pl = ...
            (price>=put_strike).*-1*put_value + (price<put_strike).*(-1*price+put_strike-put_value);
    end

Record Time

toc;
Elapsed time is 4.032251 seconds.
end