Explain to me the difference between swaps, futures, options, and forwards.
Then, write out the maths to model their pricings and then code in Python to price them all.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here’s a bird’s-eye view of each instrument, their pricing formulas, and a self-contained Python snippet to price them all.
1. Key Differences
Instrument
Standardization
Exchange vs OTC
Payoff Profile
Margining / Cash‐flow
Forward
Customizable
OTC
(S_T - K) (long)
Single payoff at maturity
Future
Standardized
Exchange
(S_T - K) (long)
Marked‐to‐market daily
Option
Standardized
Exchange/OTC
(\max(S_T-K,0)) for calls(\max(K-S_T,0)) for puts
Premium up front, then optional payoff
Swap
Customizable
OTC
Sum of exchanged cash flows (e.g. fixed vs floating)
Periodic cash flows
2. Mathematical Pricing
2.1 Forward / Future
Under no arbitrage (continuous rates (r), dividend yield (q)),
[
F_{0,T} ;=; S_0,e^{(r - q)T}.
]
The value at time (t) of a long forward with strike (K) is
[
V_t ;=; e^{-r (T-t)}\bigl(F_{t,T} - K\bigr).
]
For futures with the same parameters, the formula is identical assuming no basis risk.
2.2 European Option (Black–Scholes)
Let
[
d_1 = \frac{\ln(S_0/K) + (r - q + \tfrac12\sigma^2)T}{\sigma\sqrt T},
\quad
d_2 = d_1 - \sigma\sqrt T.
]
Then the call and put prices are
[
C = S_0,e^{-qT}N(d_1) ;-; K,e^{-rT}N(d_2),
\qquad
P = K,e^{-rT}N(-d_2) ;-; S_0,e^{-qT}N(-d_1),
]
where (N(\cdot)) is the standard normal CDF.
2.3 Vanilla Interest‐Rate Swap
A payer‐swap (you pay fixed rate (S_{\rm pay}), receive floating) has PV
[
\text{PV}{\rm swap}
= \underbrace{\sum{i=1}^n \tau_i,P(0,T_i),L_i}{\text{floating leg PV}}
;-;
\underbrace{S{\rm pay},\sum_{i=1}^n \tau_i,P(0,T_i)}{\text{fixed leg PV}}.
]
In practice, at inception you choose the par‐swap rate (S^*) such that PV({\rm swap}=0):
[
S^* ;=; \frac{1 - P(0,T_n)}{\sum_{i=1}^n \tau_i,P(0,T_i)},
]
where (P(0,T_i)) are discount factors and (\tau_i) accrual fractions.
3. Python Implementation
python
import numpy as np
import scipy.stats as st
# 1) Forward/Future pricing
def forward_price(S0, r, q, T):
return S0 * np.exp((r - q) * T)
def forward_value(St, FtT, K, r, t, T):
"""Value at time t of a forward struck at K."""
return np.exp(-r*(T-t)) * (FtT - K)
# 2) Black-Scholes Option pricing
def bs_european(S0, K, r, q, sigma, T):
"""Returns (call, put) prices under Black-Scholes."""
d1 = (np.log(S0/K) + (r - q + 0.5*sigma**2)*T) / (sigma*np.sqrt(T))
d2 = d1 - sigma*np.sqrt(T)
call = S0 * np.exp(-q*T) * st.norm.cdf(d1) - K * np.exp(-r*T) * st.norm.cdf(d2)
put = K * np.exp(-r*T) * st.norm.cdf(-d2) - S0 * np.exp(-q*T) * st.norm.cdf(-d1)
return call, put
# 3) Vanilla interest-rate swap PV
def swap_pv(fixed_rate, discount_factors, tau, floating_rates):
"""
discount_factors: array P(0,T_i)
tau : array accrual fractions tau_i
floating_rates : array forward rates L_i (in decimal)
"""
# Floating leg: sum tau_i * P(0,T_i) * L_i
pv_float = np.sum(tau * discount_factors[1:] * floating_rates)
# Fixed leg: fixed_rate * sum tau_i * P(0,T_i)
pv_fixed = fixed_rate * np.sum(tau * discount_factors[1:])
return pv_float - pv_fixed
def par_swap_rate(discount_factors, tau):
"""Compute par-swap rate S* such that PV_swap=0."""
num = discount_factors[0] - discount_factors[-1]
den = np.sum(tau * discount_factors[1:])
return num / den
# ==== Example usage ====
if __name__ == "__main__":
# Common inputs
S0, K, r, q, sigma, T = 100, 105, 0.02, 0.01, 0.20, 1.0
# 1) Forward
F0 = forward_price(S0, r, q, T)
print(f"Forward price F0 = {F0:.4f}")
# 2) Option
call, put = bs_european(S0, K, r, q, sigma, T)
print(f"Call = {call:.4f}, Put = {put:.4f}")
# 3) Swap (annual, 3-year example)
dfs = np.array([1.0, 0.98, 0.95, 0.92]) # P(0,0), P(0,1), P(0,2), P(0,3)
taus = np.array([1.0, 1.0, 1.0])
forwards = (dfs[:-1]/dfs[1:] - 1) / taus # simple forward rates
S_star = par_swap_rate(dfs, taus)
pv = swap_pv(S_star, dfs, taus, forwards)
print(f"Par swap rate = {S_star:.4%}, PV at inception = {pv:.2e}")
What this does
Forward/Future: forward_price gives the fair forward.
Option: bs_european returns European call & put Black–Scholes prices.
Swap: we build a toy discount curve, compute the par‐swap rate, and check that the PV is zero at inception.
Feel free to adapt the discount curve, accrual conventions or add more exotic features (e.g. caps/floors, credit spreads, early exercise) as you see fit. 🚀