Financial Algorithms Cookbook | Engineering
Algorithm: Forward Exchange Rate Calculations
f = currentSpot*[1+iQ*(DAYS/BASISQ)]/[1+iB*(DAYS/BASISB)]def forwardRate(currentSpot, quoted_i, base_i, DAYS, quotedBASIS, baseBASIS): quoted = 1+ quoted_i*DAYS/quotedBASIS base = 1 + base_i*DAYS/baseBASIS forwardRate = currentSpot*quoted/base return forwardRate
Example
An foreign exchange dealer in Zurich is asked by a US client to quote a rate for Euro against the dollar for delivery in one year after spot. The client wants to buy 1980k Euro:
- What is the price of these Euro in USD.
- What is the far exchange rate for USD-Euro one year forward.
- currentSpot 1USD = 1.8 Euro
- US interest for one year = 6%
- Euro = 10%
- The bank needs to lend 1.8M Euro now @10% to get in one year 1980K Euro.
- This means the bank has to buy 1.8M Euro at spot rate, i.e. 1M USD.
- 1M USD is borrowed @ 6% costing over the year 1060K USD.
>>> >>> currentSpot=1.8 >>> quoted_i=10 >>> base_i=.06 >>> quoted_i=.10 >>> DAYS=360 >>> quotedBASIS=360 >>> baseBASIS=360 >>> forwardRate(currentSpot, quoted_i, base_i, DAYS, quotedBASIS, baseBASIS) 1.8679245283018868 >>>
Algorithm: FRA - Forward rate Agreement
FRA's are forward-forward loans granted at a fixed interest rate, but are without an actual lending commitment. They are used as an agreement between two parties that want to either hedge against or speculate on a movement in future interest rates. The seller of a FRA nominally agrees to lend a sum of money to the buyer. The buyer agrees to nominally borrow this sum. The sum (Contracyt Amount) is specified in a currency (Contract Currency) at a fixed rate of interest for a specified period starting on a fixed date in the future. here is the time line. An example should illustrate things better:
1x4 FRa in 1m USD @ 6.25%
| Dealing Date | Typically 2 days | Spot Date | Deferment Period | Fixing Date | Typically 2 days | Settlement Date | Contract Period | Maturity Date |
| Mon. 12th April 03 | 2 days | Wed. 14th April 03 | 1 month | Fri. 14th May | 2 days | 94 days | Mon. 16th August | |
| Reference Rate (LIBOR) 7% |
FRA - Settlement Sum
effectiveInterestCost= [(referenceRate -contractRate)*contractAmount]*(BASIS/DAYS) discount= 1+[referenceRate* (BASIS/DAYS)] fraSettlementSum = effectiveInterestCost/discount
def fraSettlementSum(referenceRate, contractRate, contractAmount, DAYS, BASIS): return ((referenceRate - contractRate)*contractAmount)/(BASIS/DAYS+referenceRate)
Example
An foreign exchange dealer in Zurich is asked by a US client to quote a rate for Euro against the dollar for delivery in one year after spot. The client wants to buy 1980k Euro:
- What is the price of these Euro in USD.
- What is the far exchange rate for USD-Euro one year forward.
- currentSpot 1USD = 1.8 Euro
- US interest for one year = 6%
- Euro = 10%
- The bank needs to lend 1.8M Euro now @10% to get in one year 1980K Euro.
- This means the bank has to buy 1.8M Euro at spot rate, i.e. 1M USD.
- 1M USD is borrowed @ 6% costing over the year 1060K USD.
>>> >>> currentSpot=1.8 >>> quoted_i=10 >>> base_i=.06 >>> quoted_i=.10 >>> DAYS=360 >>> quotedBASIS=360 >>> baseBASIS=360 >>> forwardRate(currentSpot, quoted_i, base_i, DAYS, quotedBASIS, baseBASIS) 1.8679245283018868 >>>
FRA - Price
fraRate = (imDm-isDs)/Df(1+isDs/B) where: is - is the cash market interest rate to settlement date. im is the cash market interest rate to maturity date. Ds - is the number of days from spot date to settlement date. Dm - is the number of days from spot date to maturity date. Df - days in contract period. B - is the day count convenstion (i.e: 360 or 365)
def fraRate (rate2Settlement, rate2Maturity, days2Settlement, days2Maturity, contractDays, BASIS): num = rate2Maturity*days2Maturity- rate2Settlement*days2Settlement) dem = contractDays*(1+ rate2Settlement*days2Settlement/BASIS) return num/dem
Example
>>> days2Settlement = 30 >>> days2Maturity = 124 >>> contarctDays = 94 >>> B = 360 >>> rate2Settlement = 8.125/100.0 >>> rate2Maturity = 6.25/100.0 >>> fraRate (rate2Settlement , rate2Maturity , days2Settlement , contractDays , BASIS) 0.062580 >>> 0.062580 * 100 6.26
