date2time
Time and frequency from dates
Syntax
Description
[ computes
time factors appropriate to compounded rate quotes between the TFactors,F]
= date2time(___,Compounding,Basis,EndMonthRule)Settle and Maturity dates
using optional input arguments for Compounding, Basis,
and EndMonthRule. date2time is
the inverse of time2date.
Examples
To get the date2time period between '31-Jul-2015' and '30-Sep-2015' using an actual/actual basis:
date2time(datetime(2015,7,31),datetime(2015,9,30), 2, 0, 1)
ans = 0.3333
When using date2time quasi coupon, two quasi coupon dates are computed for a bond with a maturity corresponding to the Dates input. In this case, that would be "30-Sep-2015". Assuming that the compounding frequency is 2, the other quasi coupon date is six months prior to this date. Assuming the end of month rule is in place, then the other quasi coupon date is "31-Mar-2015". You can use these two dates to compute the total number of actual days in a period (which is 183). Given this, the fraction of time between the start and end date for the actual/actual basis is computed as follows.
(Actual Days between Start Date and End Date)/(Actual Number of Days between Quasi Coupon Dates)
There are 61 days between 31-Jul-2015 and 30-Sep-2015 and 183 days between the quasi coupon dates ("31-Mar-2015" and "30-Sep-2015") which leads to a final result of 61/183 or exactly 1/3.
Input Arguments
Settlement date, specified as a scalar datetime, string, or date character vector.
To support existing code, date2time also
accepts serial date numbers as inputs, but they are not recommended.
Data Types: char | string | datetime
Maturity date, specified as a scalar or N-by-1 vector
using a datetime array, string array, or date character vectors.
To support existing code, date2time also
accepts serial date numbers as inputs, but they are not recommended.
Data Types: char | string | datetime
Rate at which input zero rates are compounded when annualized,
specified as a scalar with numeric values of: 0, 1, 2, 3, 4, 5, 6, 12, 365,
or –1. Allowed values are defined as:
0— Simple interest (no compounding)1— Annual compounding2— Semiannual compounding (default)3— Compounding three times per year4— Quarterly compounding6— Bimonthly compounding12— Monthly compounding365— Daily compounding-1— Continuous compounding
The optional Compounding argument determines
the formula for the discount factors (Disc):
Compounding=0for simple interestDisc = 1/(1 + Z * T), whereTis time in years and simple interest assumes annual timesF = 1.
Compounding=1,2,3,4,6,12Disc = (1 + Z/F)^(-T), whereFis the compounding frequency,Zis the zero rate, andTis the time in periodic units, for example,T = Fis one year.
Compounding=365Disc = (1 + Z/F)^(-T), whereFis the number of days in the basis year andTis a number of days elapsed computed by basis.
Compounding=-1Disc = exp(-T*Z), whereTis time in years.
Day-count basis, specified as an integer with a value 0 through 13 or
a N-by-1 vector of integers
with values 0 through 13.
0 = actual/actual (default)
1 = 30/360 (SIA)
2 = actual/360
3 = actual/365
4 = 30/360 (BMA)
5 = 30/360 (ISDA)
6 = 30/360 (European)
7 = actual/365 (Japanese)
8 = actual/actual (ICMA)
9 = actual/360 (ICMA)
10 = actual/365 (ICMA)
11 = 30/360E (ICMA)
12 = actual/365 (ISDA)
13 = BUS/252
For more information, see Basis.
Data Types: single | double
End-of-month rule flag for month having 30 or fewer days, specified
as scalar nonnegative integer [0, 1]
or a using a N-by-1 vector of
values. This rule applies only when Maturity is
an end-of-month date for a month having 30 or fewer days.
0= Ignore rule, meaning that a payment date is always the same numerical day of the month.1= Set rule on, meaning that a payment date is always the last actual day of the month.
Data Types: logical
Output Arguments
More About
The difference between yearfrac and date2time is
that date2time counts full periods as a whole
integer, even if the number of actual days in the periods are different. yearfrac does
not count full periods.
For example,
yearfrac('1/1/2000', '1/1/2001', 9)
ans =
1.0167yearfrac for Basis 9 (ACT/360
ICMA) calculates 366/360 = 1.0167. So, even if the dates have the
same month and date, with a difference of 1 in the year, the returned
value may not be exactly 1. On the other hand, date2time calculates
one full year period:
date2time('1/1/2000', '1/1/2001', 1, 9)
ans =
1Version History
Introduced before R2006aAlthough date2time supports serial date numbers,
datetime values are recommended instead. The
datetime data type provides flexible date and time
formats, storage out to nanosecond precision, and properties to account for time
zones and daylight saving time.
To convert serial date numbers or text to datetime values, use the datetime function. For example:
t = datetime(738427.656845093,"ConvertFrom","datenum"); y = year(t)
y =
2021
There are no plans to remove support for serial date number inputs.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)