Code
import math
import numpy as np
import pandas as pd
import matplotlib.pyplot as pltimport math
import numpy as np
import pandas as pd
import matplotlib.pyplot as pltA derivative is a contract whose value comes from (“derives from”) an underlying asset, which can be: a stock, an index, an interest rate, a currency, or a commodity. The reasons why firms or individuals use derivatives are:
Hedging: reduce or control a risk you already have (e.g., airlines hedge fuel price risk)
Speculation: take a view on where prices might go with limited upfront capital
Arbitrage: lock in a low‑risk profit when prices are out of line (advanced).
Important keywords to keep in mind:
Underlying asset: the thing the contract is based on (e.g., a stock or the EUR/USD exchange rate).
Long vs. short: long benefits when price goes up; short benefits when price goes down.
Payoff vs. profit: payoff is what you get at the end; profit also subtracts what you paid or financed to get it.
In the next sections I review basic derivatives: Forwards, Futures, Options and Swaps.
A forward is a private (over‑the‑counter) agreement made today to buy or sell an asset at a fixed price on a future date. There is usually no money exchanged when you enter the deal; both sides commit to trade later at the agreed price, called the forward price.
At the delivery date T:
The long (buyer) must buy at K; buyer payoff payoff is S_T − K.
The short (seller) must sell at K; seller payoff is K-S_T
A farmer agrees today to sell 1,000 lbs at K = $2.00 in 3 months.
If S_T = $1.60 :
Buyer (long) payoff = 1.60 - 2.00 = -$0.40 per lb
Seller (short) payoff = +$0.40 per lb
If S_T = $2.40:
Buyer (long) payoff = +$0.40 per lb
Seller (short) payoff = -$0.40 per lb.
Here are 3 scenarios for possible market prices at the end of the contract (3 months):
| Market Price S_T | Long Forward Payoff (S_T - K) | Short Forward Payoff (K - S_T) |
|---|---|---|
| $1.60 | -$0.40 per lb | +$0.40 per lb |
| $2.00 | $0.00 | $0.00 |
| $2.40 | +$0.40 per lb | -$0.40 per lb |
Forward price is today’s price adjusted for the cost and benefits of waiting (interest earned).
If the asset pays income (dividends) while you wait, the forward price is typically lower than simply adding interest.
At settlement (expiration date), the long (the buyer) must buy and the short (the seller) must sell at the forward price K.
Below you can see 2 plots that show the Payoff of a Long and Short Forward at a Forward price K = $100.00 for possible market prices (S_T) of the underlying asset at expiration:
S = np.linspace(50, 150, 401)
K = 100.0
plt.figure()
plt.plot(S, S - K)
plt.title("Long Forward — Payoff at Expiration with K=$100")
plt.xlabel("Underlying price at expiration (S_T)")
plt.ylabel("Payoff")
plt.show()
plt.figure()
plt.plot(S, K - S)
plt.title("Short Forward — Payoff at Expiration with K=$100")
plt.xlabel("Underlying price at expiration (S_T)")
plt.ylabel("Payoff")
plt.show()• Hedging a known future purchase or sale (e.g., a Mexican firm locking in the USD-MX exchange rate for paying a Foreign supplier).
• Custom terms: exact quantity, date, and asset tailored to the user (because forwards are private contracts).
A futures contract is like a forward but traded on an exchange with standard terms and a clearinghouse between buyers and sellers.
It is standardized (fixed contract size and dates) and is supported by a clearinghouse that reduces credit risk.
You post margin and your position is settled daily (mark-to-market).
| Day | Futures Price | Change |
|---|---|---|
| 0 | 100.00 | - |
| 1 | 101.20 | +1.20 |
| 2 | 100.70 | -0.50 |
| 3 | 102.10 | +1.40 |
Suppose you go long 2 futures at a price of 100. Each one moves dollar‑for‑dollar with the asset, and each contract is for 1 unit (for simplicity).
| Day | Settlement Price | Daily Change |
|---|---|---|
| 0 | 100.00 | — |
| 1 | 100.50 | +0.50 |
| 2 | 101.20 | +0.70 |
| 3 | 100.40 | -0.80 |
Goal: reduce the risk of a future purchase or sale price.
Example — A bakery hedges wheat costs:
Approximate number of contracts needed = exposure / contract size = 50,000 / 5,000 = 10 contracts.
An option gives a right, not an obligation. A call option gives the right to buy the asset at a fixed strike price. A put option gives the right to sell the asset at the strike price. You pay an upfront price called the premium for this right.
European options can be exercised only at time T; American options can be exercised at any time up to T.
Payoff at expiration:
Profit at expiration is payoff minus the premium (ignoring interest for simplicity).
A powerful identity links calls, puts, the stock, and a risk‑free bond. At a high level:
Call − Put = Present value of the stock − Present value of the strike.
Practical takeaway: if you know three of these prices, you can estimate the fourth. If the relationship is violated, arbitrageurs can construct trades to profit and restore balance.
Bellow are 2 plots for a Long Call and Long Put with strike price K = $100.00 for different future/market prices S_T at expiration date:
S = np.linspace(50, 150, 401)
K = 100.0
plt.figure()
plt.plot(S, np.maximum(S - K, 0.0))
plt.title("Long Call — Payoff at Expiration")
plt.xlabel("Underlying price at expiration (S_T)")
plt.ylabel("Payoff")
plt.show()
plt.figure()
plt.plot(S, np.maximum(K - S, 0.0))
plt.title("Long Put — Payoff at Expiration")
plt.xlabel("Underlying price at expiration (S_T)")
plt.ylabel("Payoff")
plt.show()Below are two plots to illustrate these strategies with the following strike prices:
Strike price for the Put: K_put = $95.00
Strike price for the Call: K_call = $105.00
The payoffs are relative compared to holding the stock at a price S0=$100.00, and considering the premium for both Call and Put = $3.0.
S = np.linspace(50, 150, 401)
S0 = 100.0
K_put = 95.0
K_call = 105.0
premium = 3.0
# Relative payoffs vs holding stock from S0
holding_payoff = (S - S0)
ppayoff = (S - S0) + np.maximum(K_put - S, 0.0)
pprofit = ppayoff - premium
ccpayoff = (S - S0) - np.maximum(S - K_call, 0.0)
ccprofit = ccpayoff + premium
plt.figure()
plt.plot(S, pprofit, label = "Protective Put")
plt.plot(S, holding_payoff, label="Buy & Hold the Stock")
plt.title("Protective Put — Relative Profit (premium=$3)")
plt.xlabel("Underlying price at expiration (S_T)")
plt.ylabel("Relative payoff vs S0")
plt.legend()
plt.show()
plt.figure()
plt.plot(S, ccprofit, label ="Covered Call")
plt.plot(S, holding_payoff, label="Buy & Hold the Stock")
plt.title("Covered Call — Relative Profit (premium=$3)")
plt.xlabel("Underlying price at expiration (S_T)")
plt.ylabel("Relative payoff vs S0")
plt.legend()
plt.show()A swap is an agreement to exchange cash flows on set dates, based on a notional amount. The most common is an interest rate swap (IRS). In an IRS, one side pays a fixed rate, the other pays a floating rate (like a short‑term benchmark). No principal is exchanged — just the interest differences.
Example 1
Example 2
3‑year pay‑fixed receive‑float
Basic idea of pricing: at the start, the fixed rate is set so that the present value of fixed payments equals the present value of expected floating payments, making the swap’s initial value about zero. Later, when rates move, the swap’s value changes.
Two parties exchange interest payments in two different currencies and typically exchange principal at the start and the end. This can help a firm borrow where it is cheapest and then swap into the currency it needs.
Here are very simple cases as a general guide to chose among the derivatives covered here:
Derivative: A contract whose value depends on another asset (the underlying).
Underlying: The asset or rate a derivative references (stock, index, oil, FX, interest rate).
Forward: Private agreement to buy/sell later at a fixed price K; settles at maturity.
Futures: Exchange‑traded forward; standardized with daily settlement and margin.
Strike (K): The fixed price in an option or forward deal (exercise price for options).
Maturity / Expiration (T): When the contract ends or the option must be exercised.
Long / Short: Long benefits when price rises; short benefits when price falls (opposite positions).
Payoff: Value of the contract at expiration, before considering the premium or financing.
Profit: Payoff minus what you paid (e.g., an option premium).
Premium: Upfront price paid for an option. Call Option: Right to buy the underlying at K by T (or at T if European).
Put Option: Right to sell the underlying at K by T (or at T if European). American / European: American: exercise any time up to T; European: only at T.
In‑the‑Money (ITM): Option that would have positive payoff if exercised now (call: S>K; put: S<K).
At‑the‑Money (ATM): S is about equal to K.
Out‑of‑the‑Money (OTM): Option that would have zero payoff if exercised now (call: S<K; put: S>K).
Marking‑to‑Market: Daily settlement of gains/losses on a futures contract.
Initial Margin: Deposit required to open a futures position.
Maintenance Margin: Minimum account balance before a margin call is triggered.
Basis: Spot price minus futures price (S − F); tends to zero at expiration.
Convergence: Futures price approaches the spot price as expiration nears.
Cost of Carry: Costs/benefits of holding the asset to T (financing, storage, income).
Dividend Yield (q): Rate at which an asset pays income (e.g., index dividends).
Convenience Yield: Benefit from physically holding a commodity (e.g., avoiding stockouts).
Hedging: Reducing risk you already have (e.g., lock a future price).
Speculation: Taking a risk to profit from expected price moves.
Arbitrage: Exploiting mispricing to earn low‑risk profit (advanced).
Put–Call Parity: Relationship linking prices of calls, puts, the stock, and a bond.
Volatility (sigma): How much the underlying price tends to move (uncertainty).
Implied Volatility: Volatility number that makes a pricing model match a market option price.
Greeks: Sensitivities of option price to inputs (Delta, Gamma, Vega, Theta, Rho).
Delta: Sensitivity to the underlying price (hedge ratio).
Gamma: Sensitivity of Delta to the underlying price (curvature).
Vega: Sensitivity to volatility. Theta: Sensitivity to time (time decay).
Rho: Sensitivity to interest rates.
Interest‑Rate Swap (IRS): Contract to exchange fixed and floating interest payments.
Fixed Leg: Side of a swap that pays/receives a fixed interest rate.
Floating Leg: Side that pays/receives a rate that resets periodically (e.g., benchmark).
Notional: Reference amount used to calculate swap payments (not exchanged).
Currency Swap: Swap where cash flows are in two different currencies, typically with principal exchange.
Discount Factor: Present value of $1 received at a future date.
Par Swap Rate: Fixed rate that makes the swap’s initial value ~0.
Counterparty Risk: Risk that the other side of a private contract fails to pay.
Clearinghouse: Central counterparty for futures that reduces credit risk.
Go to Chapter 5 of Hull Book and solve the following exercises:
5.3, 5.4, 5.6, 5.9, 5.15
Go to Chapter 10 and do the following:
10.1, 10.2, 10.3, 10.9, 10.11