In this last part of the tutorial we will explore on how to create, value and plot few standard option strategies and also how to build our own custom strategy.
Import Quantsbin the Derivative pricing module and assign qbdp as alias to it.
import quantsbin.derivativepricing as qbdp
We define Standard Strategies in Quantsbin using StdStrategies object. Let's start with exploring doc string for StdStrategies
print(qbdp.StdStrategies.__doc__)
As we can observe above, to define a standard strategy we have option to choose from many inbuild strategies as listed under 'List of Std. Strategies'. We will start with defining a simple bull call strategy.
Bull Call spread is contructed using two Call options with different strike but all other parameters same. We will be long Call at 50 and short call at 60.
std_stgy_bullcall = qbdp.StdStrategies(name='bull_call', asset='Stock', low_strike=50, strike_spread=10,
expiry_date='20190721', expiry_type='European')
Let's check the payoff of this stratergy.
bull_call_payoff_plt = qbdp.Plotting(std_stgy_bullcall,'payoff', x_axis_range=[20, 100], no_of_points=100).line_plot()
bull_call_payoff_plt.show()
Here we can observe the payoff for the Bull Call sread. Now lets calculate the value of ths spread.
To calculate value of the spread we will start by defining engine similar to option objects.
std_stgy_bullcall_engine = std_stgy_bullcall.engine(model="BSM", spot0=55, pricing_date='20180531', volatility=.25,
rf_rate=.05)
print("Value of Bull Call option strategy is {}".format(std_stgy_bullcall_engine.valuation()))
print("Greeks for Bull Call option strategy are {}".format(std_stgy_bullcall_engine.risk_parameters()))
As we have our engine defined lets plot PnL profile for our strategy
bull_call_pnl_plt = qbdp.Plotting(std_stgy_bullcall_engine,'pnl', x_axis_range=[20, 100], no_of_points=100).line_plot()
bull_call_pnl_plt.show()
Let's explore further into this strategy by plotting valuation and greeks.
Valuation Profile
bull_call_val_plt = qbdp.Plotting(std_stgy_bullcall_engine,'valuation', x_axis_range=[20, 100], no_of_points=100).line_plot()
bull_call_val_plt.show()
Greeks
Delta
bull_call_delta_plt = qbdp.Plotting(std_stgy_bullcall_engine,'delta', x_axis_range=[20, 100], no_of_points=100).line_plot()
bull_call_delta_plt.show()
Gamma
bull_call_gamma_plt = qbdp.Plotting(std_stgy_bullcall_engine,'gamma', x_axis_range=[20, 100], no_of_points=100).line_plot()
bull_call_gamma_plt.show()
Vega
bull_call_vega_plt = qbdp.Plotting(std_stgy_bullcall_engine,'vega', x_axis_range=[20, 100], no_of_points=100).line_plot()
bull_call_vega_plt.show()
In the last part of our tutorial we will see how we can define our own custom strategy by combining options.
Lets start with creating few of options.
eqOption1 = qbdp.EqOption(option_type='Call', strike=50, expiry_date='20180630', expiry_type='European')
eqOption2 = qbdp.EqOption(option_type='Call', strike=55, expiry_date='20180630', expiry_type='European')
eqOption3 = qbdp.EqOption(option_type='Put', strike=50, expiry_date='20180630', expiry_type='European')
eqOption4 = qbdp.EqOption(option_type='Call', strike=70, expiry_date='20180630', expiry_type='European')
Now we will combine them into strategy. We do have an option to add no. of units of each options. For combining options into srtategy we need to create list of tuple containing options and thier correspinding units.
custom_option_port = [(eqOption3,1),(eqOption2, -1),(eqOption1, 1),(eqOption4, 2)]
Now we will use OptionStr1Udl objects from Quantsbin to create strategy using our variable custom_option_port
custom_stgy1 = qbdp.OptionStr1Udl(option_portfolio=custom_option_port)
custom_stgy1_payoff_plt = qbdp.Plotting(custom_stgy1,'payoff', x_axis_range=[20, 100], no_of_points=100).line_plot()
custom_stgy1_payoff_plt.show()
Interesting right!! How easily Quantsbin nable us to visualize the payoff generated from combination of options.
In similar lines to what we discussed earlier we can generate all the graphs as well as greeks for this custom strategy.
To explore more with Quantsbin please visit our official documentation page.
In case of any issues with Quantsbin library please raise at issue
To collaborate with us visit Quantsbin official page or write to us as [contactus@quantsbin.com].