Appendix A. Dates and Times
As in the majority of scientific disciplines, dates and times play an important role in finance. This appendix introduces different aspects of this topic when it comes to Python programming. It cannot, of course, be exhaustive. However, it provides an introduction to the main areas of the Python ecosystem that support the modeling of date and time information.
Python
The datetime
module from the Python standard library allows for the implementation of the most important date and time–related tasks:
In
[
1
]
:
from
pylab
import
mpl
,
plt
plt
.
style
.
use
(
'
seaborn
'
)
mpl
.
rcParams
[
'
font.family
'
]
=
'
serif
'
%
matplotlib
inline
In
[
2
]
:
import
datetime
as
dt
In
[
3
]
:
dt
.
datetime
.
now
(
)
Out
[
3
]
:
datetime
.
datetime
(
2018
,
10
,
19
,
15
,
17
,
32
,
164295
)
In
[
4
]
:
to
=
dt
.
datetime
.
today
(
)
to
Out
[
4
]
:
datetime
.
datetime
(
2018
,
10
,
19
,
15
,
17
,
32
,
177092
)
In
[
5
]
:
type
(
to
)
Out
[
5
]
:
datetime
.
datetime
In
[
6
]
:
dt
.
datetime
.
today
(
)
.
weekday
(
)
Out
[
6
]
:
4
Of course, datetime
objects can be ...
Get Python for Finance, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.