Welcome to THETAWIKI. If you like to create or edit a page please make sure to login or register an account. All registered users please make sure to provide a valid email address.

# Swap

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

## Description

A Swap is a financial contract where two parties exchange one stream of cash flows with the other. Usually at least one of the cash payment streams has a rate that is variable.

## ThetaML implementation of an interest rate swap

```model swap
import N    "Notional"
import f_r  "Fixed rate"
import T    "Maturity"
import bp   "basis premium"
import EUR  "Numeraire"
import r    "Libor interest rate"
export V    "value of swap(for fixed)"

c = 0
loop T
theta 1
c = c + (r + bp/100 - f_r) * N * EUR
end
V = c
end```

## Knock Out Swap

A Knock-Out Swap is a swap which is cancelled when a given condition is reached. For example, a swap can be knocked out if the LIBOR rate reaches a certain threshold.

## ThetaML implementation of a knock-out swap

```model KnockOutSwap
import N    "Notional"
import f_r  "Fixed rate"
import T    "Maturity"
import bp   "Basis premium"
import EUR  "Numeraire"
import r    "Libor interest rate"
import B    "Barrier"
export P    "value of swap(for fixed)"

P = E(V!)

c = 0
cond = 0
loop T
theta 1

% knock-out?
if r > B
cond = 1
end

% knocked-out earlier?
if cond < 1
c = c + (r + bp/100 - f_r) * N * EUR
end
end

V = c

end```