LSEG Data Library for Python

count_periods

The count_periods function gets the quantity of time periods based on the provided start date, end date, and period type (such as working day, non-working day, and so on).

Module

lseg.data

Syntax

count_periods(start_date, end_date, period_type, calendars, currencies, day_count_basis)

Parameters

Value Description Data type Optional Default value
start_date Calculation start date. str, date, datetime, timedelta Yes None
end_date Calculation end date. str, date, datetime, timedelta Yes None
period_type Date periods counting method. str, PeriodType Yes None
calendars Calendars to determine the working days and national holidays for particular countries. List[str] Yes None
currencies Currencies to use for calculation of the date for the working day or weekend. List[str] Yes None
day_count_basis Predefined values for day count basis. str, DayCountBasis Yes None

Returned value

CounterPeriods object with the following structure:

Name Date type Description
count float Time periods quantity.
tenor str Period type (possible valued described in PeriodType.

Usage

The following example demonstrates how to get the number of working days between 3-11 days from today:

import datetime

import lseg.data as ld
from lseg.data import dates_and_calendars


# open session
ld.open_session()

counted_period = ld.dates_and_calendars.count_periods(
    start_date=datetime.timedelta(-11),
    end_date=datetime.timedelta(-3),
    period_type=dates_and_calendars.PeriodType.WORKING_DAY,
    currencies=["EUR"],
)

print(counted_period)

# close session
ld.close_session()

This example produces the following output:

CountedPeriods(count=6.0, tenor='WD')

PeriodType

DayCountBasis

163 words (0:51 mins)