Specifying Constraints with ConSet
Introduction
Both hedgeopt
and hedgeslf
accept an optional input argument, ConSet
,
that allows you to specify a set of linear inequality constraints
for instruments in your portfolio. The examples in this section are
brief. For additional information regarding portfolio constraint specifications,
refer to Analyzing Portfolios.
Setting Constraints with ConSet
This example shows how to determine the minimum cost of obtaining simultaneous delta, gamma, and vega neutrality (target sensitivities all 0).
Recall that when hedgeopt
computes the cost of rebalancing a portfolio, the input target sensitivities you specify are treated as equality constraints during the optimization process.
Load the example portfolio and use hwsens
to compute the price and sensitivities.
load deriv.mat format bank [Delta, Gamma, Vega, Price] = hwsens(HWTree, HWInstSet);
Extract the current portfolio holdings.
Holdings = instget(HWInstSet, 'FieldName', 'Quantity');
For convenience place the delta, gamma, and vega sensitivity measures into a matrix of sensitivities.
Sensitivities = [Delta Gamma Vega];
Each row of the Sensitivities matrix is associated with a different instrument in the portfolio, and each column with a different sensitivity measure.
To summarize the portfolio information:
disp([Price Holdings Sensitivities])
100.92 20.00 -291.26 858.41 0 99.33 15.00 -374.64 1460.88 -0.00 4.80 -10.00 -200.84 26835.26 119.40 102.99 25.00 -383.57 1487.24 -0.00 100.28 5.00 -0.55 1.28 0.00 0.58 10.00 60.96 5599.37 113.38 2.10 5.00 -209.24 8205.31 122.88 8.78 8.00 -306.78 894.26 -0.00
Use hedgeopt
to minimize the cost of hedging a portfolio given a set of target sensitivities.
FixedInd = [1 3 5 7 8]; TargetSens = [0 0 0]; [Sens, Cost, Quantity] = hedgeopt(Sensitivities, Price, ... Holdings, FixedInd, [], [], TargetSens)
Sens = 1×3
0.00 -0.00 0
Cost = 36589.85
Quantity = 1×8
20.00 24355.42 -10.00 -23806.53 5.00 5.11 5.00 8.00
Suppose you want to place some upper and lower bounds on the individual instruments in your portfolio. You can specify these constraints, along with a variety of general linear inequality constraints, with function portcons
.
As an example, assume that, in addition to holding instruments 1, 3, 5, 7, and 8 fixed as before, you want to bound the position of all instruments to within +/- 180 contracts (for each instrument, you cannot short or long more than 180 contracts). Applying these constraints disallows the current position in the second instrument. All other instruments are currently within the upper/lower bounds.
You can generate these constraints by first specifying the lower and upper bounds vectors and then calling portcons.
LowerBounds = [-180 -180 -180 -180 -180 -180 -180 -180];
UpperBounds = [ 180 180 180 180 180 180 180 180];
ConSet = portcons('AssetLims', LowerBounds, UpperBounds);
To impose these constraints, call hedgeopt
with ConSet
as the last input.
[Sens, Cost, Quantity] = hedgeopt(Sensitivities, Price, ... Holdings, FixedInd, [], [], TargetSens, ConSet)
Sens = 1×3
NaN NaN NaN
Cost = NaN
Quantity = 1×8
NaN NaN NaN NaN NaN NaN NaN NaN
Examine the outputs and see that they are all set to NaN
, indicating that the problem, given the constraints, is not solvable. Intuitively, the results mean that you cannot obtain simultaneous delta, gamma, and vega neutrality with these constraints at any price.
To see how close you can get to portfolio neutrality with these constraints, call hedgeslf
.
[Sens, Value1, Quantity] = hedgeslf(Sensitivities, Price, ... Holdings, FixedInd, ConSet)
Sens = 3×1
-292.71
-75.06
3864.50
Value1 = 1113.94
Quantity = 8×1
20.00
171.91
-10.00
-180.00
5.00
39.20
5.00
8.00
Portfolio Rebalancing
This example shows how to use user-specified constraints to rebalance a portfolio using the hedgeopt
function.
Assume that you are willing to spend as much as $20,000 to rebalance your portfolio, and you want to know what minimum portfolio sensitivities you can get for your money. In this form, recall that the target cost ($20,000) is treated as an inequality constraint during the optimization process.
Load the example portfolio and use hwsens
to compute the price and sensitivities.
load deriv.mat format bank [Delta, Gamma, Vega, Price] = hwsens(HWTree, HWInstSet);
Extract the current portfolio holdings.
Holdings = instget(HWInstSet, 'FieldName', 'Quantity');
For convenience place the delta, gamma, and vega sensitivity measures into a matrix of sensitivities.
Sensitivities = [Delta Gamma Vega];
Each row of the Sensitivities matrix is associated with a different instrument in the portfolio, and each column with a different sensitivity measure.
To summarize the portfolio information:
disp([Price Holdings Sensitivities])
100.92 20.00 -291.26 858.41 0 99.33 15.00 -374.64 1460.88 -0.00 4.80 -10.00 -200.84 26835.26 119.40 102.99 25.00 -383.57 1487.24 -0.00 100.28 5.00 -0.55 1.28 0.00 0.58 10.00 60.96 5599.37 113.38 2.10 5.00 -209.24 8205.31 122.88 8.78 8.00 -306.78 894.26 -0.00
Use hedgeopt
to minimize the cost of hedging a portfolio given a set of target sensitivities.
FixedInd = [1 3 5 7 8]; [Sens, Cost, Quantity] = hedgeopt(Sensitivities, Price, ... Holdings, FixedInd, [], 20000)
Sens = 1×3
-221.17 -39.19 2055.76
Cost = 20000.00
Quantity = 1×8
20.00 11460.13 -10.00 -11208.07 5.00 23.24 5.00 8.00
Assume that, in addition to holding instruments 1, 3, 5, 7, and 8 fixed, you want to bound the position of all instruments to within +/- 150 contracts (for each instrument, you cannot short more than 150 contracts and you cannot long more than 150 contracts). These bounds disallow the current position in the second and third instruments. All other instruments are currently within the upper/lower bounds.
You can generate these constraints by first specifying the lower and upper bounds vectors and then calling portcons
.
LowerBounds = [-150 -150 -150 -150 -150 -150 -150 -150];
UpperBounds = [ 150 150 150 150 150 150 150 150];
ConSet = portcons('AssetLims', LowerBounds, UpperBounds);
To impose these constraints, call hedgeopt
with ConSet
as the last input.
[Sens, Cost, Quantity] = hedgeopt(Sensitivities, Price, ... Holdings,FixedInd, [], 20000, [], ConSet)
Sens = 1×3
-293.08 -75.16 3869.40
Cost = 5469.60
Quantity = 1×8
20.00 141.20 -10.00 -150.00 5.00 39.24 5.00 8.00
With these constraints, hedgeopt
enforces the lower bound for the second and third instruments.
See Also
Topics
- Portfolio Creation Using Functions
- Adding Instruments to an Existing Portfolio Using Functions
- Instrument Constructors
- Creating Instruments or Properties
- Searching or Subsetting a Portfolio
- Pricing a Portfolio Using the Black-Derman-Toy Model
- Pricing and Hedging a Portfolio Using the Black-Karasinski Model
- Hedging with Constrained Portfolios
- Instrument Constructors
- Hedging