首页
编程语言
数据库
网络开发
Algorithm算法
移动开发
系统相关
金融统计
人工智能
其他
首页
>
> 详细
辅导FRE6831留学生、讲解PYTHON程序语言、PYTHON辅导、program讲解 讲解留学生Processing|讲解数据库SQ
FRE6831
COMPUTATIONAL FINANCE LABORATORY (PYTHON)
Adjunct Professor
Dept. of Finance and Risk Engineering
Office Hours by appointment
PROJECT: IMPLEMENTING A LIBOR YIELD CURVE OBJECT
The class project is to write a Python program that infers the short end of the USD LIBOR yield curve
from market observations, via the methodology in use prior to 2008 (More modern methodologies are too
complex for an introductory course.). It is to support two calculations:
1. The “discount factor,” or present value of a US dollar for a given future date, up to 3 years after a
given “spot” date (See below for a definition of the spot date.).
2. The “forward rate,” which is the simple interest rate, expressed as a percentage, over a given
period between two dates, computed from the above discount factor curve as explained below.
Because this calculation uses the above discount factor calculation, both of the input dates must
also be less than approximately 3 years after the spot date.
The yield curve is to be implemented as a Python class that I will import into my environment and run via
the commands
import USDYieldCurve
usdCurve = USDYieldCurve(“depoRates.txt”, “futuresPrices.txt”,
“tradeDate.txt”, “holidayCalendar.txt”)
print(usdCurve.getDfToDate(d1)) #d1 is a string in YYYY-MM-DD format
print usdCurve.getFwdRate(d2, d3) #inputs are in YYYY-MM-DD firnat
Inputs
Typical inputs to such a calculation – and the inputs to assume here – are to be read from the four text
files named above.
1. depoRates.txt contains a series of annualized cash deposit rates. These cash deposits are
effectively jumbo versions of the certificates of deposit that are on offer at any bank. These
deposits should be read from a text file, each line of which has the following format:
<5 character instrument code> white space
The instrument code will always have the prefix “USD” and the suffix “D”, “W”, or “M”, which
will indicate whether the deposit is for a period of days, weeks or months. In between this prefix
and suffix will be a number, indicating the number of days, weeks, or months to maturity. For
example, “USD1W” would be the code for the cash deposit maturing in one week; “USD2M”
would be the cash deposit maturing in 2 months, etc. The start date of these cash deposits is
always assumed to be the “spot date” (More about the “spot date” later.).
The first few lines of such a file might read
USD1D 2.73
USD1W 2.74
USD1M 2.75
USD3M 2.80
USD6M 2.85
You can assume that the number in the above codes is only a single digit (Although 12 month
LIBOR deposits do exist, they are seldom used to construct yield curves.). Some of the above
tenors may be omitted; in fact, the only one that is really necessary is USD6M (Why?).
2. futuresPrices.txt contains a series of prices of Eurodollar futures, which are futures on 3
month cash LIBOR deposits. You can assume that the futures on successive lines of the file
mature on successively later dates. Each line of the file has the following format:
<4 character instrument code>
The instrument code will always have the prefix “ED”, followed by one of the letters “H”, “M”,
“U”, or “Z”, followed by a single numeric character. The letters “H”, “M”, “U”, and “Z”
correspond to the maturity date of the future: the respective 3rd Wednesdays of March, June,
September, and December of the year indicated by the numeric character. Thus, “EDZ2” would
be the code for the future expiring in December, 2022. Necessarily, these maturity dates are dates
in the future, so there is no ambiguity, given that all futures must mature prior to ten years from
the current date. To see this, suppose
Thus, the first few lines of such a file might read
EDH9 97.25
EDM9 97.20
EDU9 97.19
3. tradeDate.txt contains the date at which the rates/prices are being observed, given as
character strings in the form YYYY-MM-DD.
4. holidayCalendar.txt contains the dates of Federal Reserve holidays, given as character
strings in the form YYYY-MM-DD, for the next five years (available from, among other places,
the Federal Reserve website).
As we will see in more detail in the calculation below, it may be impossible to compute the yield curve if
the input files are incomplete. In this case, an error condition should be raised and the error message
“Cannot build curve from given inputs” should be generated.
Calculation
“Modified Following” date adjustment
USD payments can only be made on days in which the US Federal Reserve (the “Fed”) is open. If the
date of a scheduled payment falls on a weekend or a Federal Reserve holiday, it must be adjusted
according to the so-called modified following business convention. Under this convention, if a payment
would otherwise be scheduled on a non-business day, the payment date “rolls forward” to the next
business day unless the next business day falls into the subsequent month. If so, the payment date “rolls
backward” to the next previous month. Thus, a payment that would be scheduled for December 30, 2018
(a Sunday) would be rolled forward to December 31, 2018 (a Monday and a business day), but a payment
scheduled for January 1, 2019 (New Year’s Day and a bank holiday) would be rolled backward to
December 31.
There are two additions to this convention. If the spot date is the end of a month, the maturity date of
deposits for one month would be the last date of the next month (So, when spot is February 28, the one
month deposit matures on March 31.). Same with 2, 3, … month deposits.
Also, if the spot date is January 29 or January 30, the one month deposit matures on February 28 (or
February 29 on leap years.).
The spot date
The beginning of the period over which USD interest is computed is usually the so-called “spot date,”
which is always two business days after the trade date (The intervening time period is required for
clearing and settlement.). Given this interest computation convention, discount factors are also only
defined from the spot date. The spot date will be denoted as s below.
Date arithmetic
Here and subsequently, if dates are to appear in a formula at all, one date will be subtracted from a later
date. Use the Python built-in library datetime to do the date arithmetic. If d1 and d2 are two such
dates, d1 – d2 is interpreted as the number of calendar days between them (More precisely, this difference
calculation results in a timedelta object, which can then be converted to a Python int.). As we
will see, this is just what is needed for the calculations below.
Computing discount factors from cash deposit rates
LIBOR interest calculations for periods less than a year always assume simple interest applied to the
relevant fraction of a year, computed as the actual number of days that a loan is outstanding, including
weekends and holidays, divided by 360 (Remember, all of this was standardized before there were
computers to facilitate the calculations!). Thus, if the given rate is R and the maturity date of the deposit
is d and the spot date is s, the amount to be repaid for every dollar lent is 1 + R(d - s)/36000. It follows
that the discount factor, or present value of a dollar n days from the spot date is (1 + Rn/36000)-1
. If a
discount factors df1 and df2 have been computed for dates d1 and d2 after the spot date, the discount factor,
df, for a date d between d1 and d2 is given by logarithmic interpolation
ln(df) = ln(df1) + [(d – d1)/(d2 – d1)] [ln(df2) – ln(df1)].
Computing discount factors from futures prices
Interest rate futures are futures on forward rates, i.e. rates over some pair of fixed future dates (In
actuality, 3 month LIBOR really means 3 calendar months, but assume, for simplicity, that it is the period
between successive futures maturity dates.). Thus, these futures are the market’s best guess as to what
these rates will actually be when the beginning of the forward period coincides with the spot date, and 3
month “cash” LIBOR becomes known. In the meantime, the rate implied by a futures price P is
computed as a percentage according to the formula
R = 100.0 – P/100.0
As before, simple interest is assumed, with the number of days in the three calendar months starting with
the futures expiration date.
However, the discount factor thus computed is a forward discount factor; that is, it is the discount factor
from the expiration of the future to the expiration of the underlying 3 month LIBOR deposit. To get the
discount factor from spot to the expiration of the LIBOR deposit, this forward discount factor must be
multiplied by the discount factor from spot to the start date of the LIBOR deposit, which is also the
maturity date of the future. Thus, given the discount factor, dfs, from spot to the earliest futures expiration
date and the forward discount factor, df1, computed as above, the discount factor to the expiration date of
the first future is dfs x df1. In general, the maturity dates of the any of the futures will not coincide with
any of the expiration dates of the cash deposits, so the interpolation formula given above will be required.
This computation cannot be done if the rates for cash LIBOR deposits are unavailable for the required
maturities. If this is the case, an error condition should be raised, and the message “Insufficient LIBOR
cash rate data” should be printed.
Again, we simplify things by ignoring the awkward fact that the futures maturity dates are almost never
exactly three months apart; instead, we assume that the maturity date of the 3 month LIBOR deposit
underlying one futures contract is also the expiration date of the next futures contract. Thus, the discount
factor to the maturity date of the underlying of the second future is dfs x df1x df2, where df2 is the forward
discount factor computed from the price of second future. This process can be continued to calculate the
discount factor from spot to the n
th futures underlying expiry date as dfs x df1x df2 x … x dfn.
The df method
This method should return the value of the df curve for the date, d, that has been passed as an argument.
In general, d will not coincide with any of the dates for which the above calculation will have produced
discount factors. In that case, determine the required df curve value by finding dates d1 and d2 from the
spot date, the discount factor, df, for a number, d, of days between d1 and d2 is given by logarithmic
interpolation
ln(df) = ln(df1) + [( d – d1)/(d2 – d1)] [ln(df2) – ln(df1)]
If d is before the spot date or d is after the last date for which the discount factor curve is defined, an error
condition should be raised, and an appropriate error message should be printed to STDOUT.
The fwdRate method
Given two dates, d1 < d2, this method should return the forward rate, rf , between these two dates, inferred
from the discount curve computed above, according to the formula.
Use Python’s built-in datetime library to do the date arithmetic. This formula will compute the rate as
a decimal fraction, rather than a percentage (e.g. something like 0.03, rather than 3%.).
If d1 is before the spot date, d1 ≥ d2, or d2 is after the last date for which the discount factor curve is
defined, an error condition should be raised, and an appropriate error message should be printed to
STDOUT.
Testing
In the “Project” folder on the Course website, I have posted the spreadsheet “YCtestcase.xlsx”,
which implements the calculations for the spot date April 24, 2015.
Notes:
1. More modern methodologies take into consideration the changes in the LIBOR markets that arose
from the debt crisis of 2008, which involves the use of a truly risk free curve for discounting (As
the financial community learned to its chagrin, interbank lending, the “I” in LIBOR, is not risk
free!). Thus, one curve is needed for discounting and another is needed for predicting forward
rates.
2. There is considerable disagreement about exactly which mix of the available cash deposits,
futures, and swaps – or even whether instruments besides these – should be used in the above
calculation. What is generally agreed upon is that the most liquid instruments should be used, as
these are the best indicators of the market.
3. Although you are to use the interpolation methods given above, they are often replaced in practice
by more sophisticated methods, such as splines.
4. Because owners of futures contracts are required to post margin daily as their futures prices vary,
the rates inferred from futures are actually biased estimates. In practice, a so-called “convexity
adjustment” is often applied to these rates. For simplicity, we will ignore this adjustment.
5. The above conventions and instrument details are only applicable to USD. The construction of
the LIBOR discount curve for other currencies differs in detail, but not in general, from this
outline. For example, GBP has a spot date one day after the trade date, and 365 replaces 360 in
the above calculations.
联系我们
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-21:00
微信:codinghelp
热点文章
更多
辅导 comm2000 creating socia...
2026-01-08
讲解 isen1000 – introductio...
2026-01-08
讲解 cme213 radix sort讲解 c...
2026-01-08
辅导 csc370 database讲解 迭代
2026-01-08
讲解 ca2401 a list of colleg...
2026-01-08
讲解 nfe2140 midi scale play...
2026-01-08
讲解 ca2401 the universal li...
2026-01-08
辅导 engg7302 advanced compu...
2026-01-08
辅导 comp331/557 – class te...
2026-01-08
讲解 soft2412 comp9412 exam辅...
2026-01-08
讲解 scenario # 1 honesty讲解...
2026-01-08
讲解 002499 accounting infor...
2026-01-08
讲解 comp9313 2021t3 project...
2026-01-08
讲解 stat1201 analysis of sc...
2026-01-08
辅导 stat5611: statistical m...
2026-01-08
辅导 mth2010-mth2015 - multi...
2026-01-08
辅导 eeet2387 switched mode ...
2026-01-08
讲解 an online payment servi...
2026-01-08
讲解 textfilter辅导 r语言
2026-01-08
讲解 rutgers ece 434 linux o...
2026-01-08
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!