首页
编程语言
数据库
网络开发
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
热点文章
更多
辅导 cs1b spring 2024 tth hw...
2024-04-19
讲解 managing financial risk...
2024-04-19
辅导 cs 0449 – project 5: /...
2024-04-19
辅导 elec 2141 digital circu...
2024-04-19
讲解 csc171 — videogame pro...
2024-04-19
讲解 comp3411 artificial int...
2024-04-19
讲解 stat3061: random proces...
2024-04-19
辅导 accounting 452, spring ...
2024-04-19
辅导 finc5001 foundations in...
2024-04-19
辅导 7ssmm712 – topics in a...
2024-04-19
讲解 com 337 - film studies ...
2024-04-19
辅导 mes202tc - digital vlsi...
2024-04-19
辅导 geography 2041b distanc...
2024-04-19
辅导 ecos3006 international ...
2024-04-19
讲解 fit5225 2024 sm1 creati...
2024-04-19
讲解 cit 593: introduction t...
2024-04-19
讲解 math 4931: take home ex...
2024-04-19
辅导 csci 547|info 533: syst...
2024-04-19
辅导 cs536-s24 intro to pls ...
2024-04-19
讲解 fit5212 - assignment 1辅...
2024-04-19
热点标签
com6521
can202
cs 6476
basc0003
ee3121
acct2002
comp5313
busi2131
ise529
csit940/csit440
cenv6141
comp3027/comp3927
ftec5580
comp1433
msci223
mark203
en3098
eden1000
ece6483
econ4410
mats16302
elec372/472
ecmt1010
comp222
comp3211
engg1340
fit5216
csc1002
comp10002
cmpsc311
chc6186
econ3208
cs 161
comp27112
comp282
swen20003
comm1190
elec9764
acfi3308
acct7101
fin6035
comp2048
geog0163
comp2013
coen 146
dts101tc
sehh2042
comp30023
comp4880/8880
cs 455
07
stat0045.
fil-30023
celen085
psyc40005
math40082
are271
comp9311
ee5311
imse2113
comp 2322
acct2102
fnd109
int102
is3s664
is6153
data4000
accfin5034
fit5212
cs536-s24
fit5225
ecos3006
mes202tc
finc5001
stat3061
csc171
cs1b
7ssmm712
bu.450.760
comp3411
cs170
swen90004
cpt206
comp5313/comp4313—large
bl5611
kxo206
comp532
elec207
kxo151
cs 2820
cpt108
math2319
dts204tc
qm222
comp2511
ccs599
infs1001
mat2355
eeee4123
25721
ifn647
pols0010
hpm 573
stat0023
csci 1100
qbus6860
comp9417
comp2003j
cse340
cs 2550
cs 61b
cs360
fin 3080
ierg 4080
cs6238
cit 594
finm7406
hw6
elec9713
asb-2522
mso3610
lit301
mcd4540
geog0030
125.330
biol0006
125.320
cs3334
fit2093
acct1101
110.309
masy1-gc
cs314
elec0048
gds104
mg5637
fit2096
math5905
eel4837
sehs4515
cpt s 321
asb2522 investment
ma214
co2104
mgmt2015
32516
math32051
econ1012
mark2052
econ0019
comp3310
dsci 525
abmf3184
aps106
antc27
finm7401
itp122
tech2300
math3026
comp9024
cao107
36318
is2022
cs 211
fit1047
ics4u
2xc3
en.540.635
4qqmn506
finn3081
phys10362
sta601
ec481e
math5165
csi 2120
el1205
comp7250
ecos3013
beam065
info1113
comp2051
csc325
mne 6130
ai6126
ecs150
is61x6
cse115
seng6110
bus265
cpts260
mphy0009
csc306
eco2011
ee3004
inu1111
st332
idepg001
info6001
cpt106
finm7409
联系我们
- QQ: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!