Option Combos

The following functions can be used for handling combinations of options, such as Straddles, Strangles, Condors, Butterflies, etc. Option combos are mainly used for limiting risk. For an introduction to options trading, see Financial Hacker. The image below shows the profit or loss of an Iron Condor combo dependent of the underlying price, at expiration (blue) and halfway to expiration (red). 


Iron Condor payoff diagram (Payoff.c)

 

combo (CONTRACT* C1, int N1, CONTRACT* C2, int N2, CONTRACT* C3, int N3, CONTRACT* C4, int N4): int

Combines up to 4 option contracts C1..C4 to a combo. The number and trade direction of contracts are given by N1..N4; use negative numbers for selling and positive numbers for buying that contract, f.i. -2 for short selling two contracts. Use 0 for not used contracts. Returns the number of combo legs, i.e. the number of different contracts of the combo. If any CONTRACT* pointer is zero, but the associated number N is nonzero, it deletes the combo and returns 0. Source code in contract.c.

comboAdd (CONTRACT* C, int N): int

Adds a copy of the option contract C to the current combo. Amount and trade direction of the contract is given by N; use a negative number for selling and a positive number for buying. Returns the number of the current combo leg. If C is 0, the function deletes all contracts from the combo and returns 0.

comboLegs (): int

Returns the number of legs of the current combo that was defined before with combo() or comboAdd() calls.

comboContract (int Leg): CONTRACT*

Pointer to the CONTRACT struct of the combo leg with the given number (1..4). Macro defined in contract.c.  

comboLeg (int Leg): int

Selects the contract of the combo leg with the given number (1..4), and returns the number assigned to that contract as defined in the combo() function. The number is negative for selling and positive for buying, so it can be directly used for the Lots parameter passed to enterLong

comboStrike (int Leg): var

Returns the strike value of the given combo Leg (1..4). Source code in contract.c.

comboRisk (int Type): var

Returns the maximum loss of the current short (Type == -1) or long (Type == 1) combo. For combos with unlimited loss, returns the loss when the price drops to zero or ends up at twice the strike, whichever is worse. Type, fAsk, fBid, and fStrike of all contracts must be set, so contractPrice must have been called before; the other contract parameters don't matter. Multiplier and transaction costs are not included. Source code in contract.c.

comboPremium (int Type): var

Returns the total premium of the current short (Type == -1) or long (Type == 1) combo. Positive premium is earned, negative premium is paid. fAsk and fBid of all contracts must be set, so contractPrice must have been called before; the other contract parameters don't matter. Multiplier and Transaction costs are not included. Source code in contract.c.

Parameters:

C1..C4 CONTRACT* pointer for leg 1..4, or 0 when the leg is not used in the combo.
N1..N4 Number of contracts for leg 1..4, negative for selling and positive for buying contracts. 0 when the leg is not used in the combo.
Leg Number of the combo leg, 1..4, starting with 1 for the first contract.

Remarks:

Example (see also Workshop 8 and Payoff.c):

if(combo(
  contract(CALL,Days,Strike),1, 
  contract(PUT,Days,Strike),1,
  0,0,0,0)) // Strangle combo
{
   enterLong(comboLeg(1));
   enterLong(comboLeg(2));
}

See also:

contract, contract variables, Workshop 8

 

► latest version online