Skip to content

Tradable Product Module

A collection of functions related to tradable products. For example, the ability to calculate when a quarter ahead product start delivering.

Changelog

Version Description
3.1.0 added a function convert_granularity_to_id().
1.6.3 Module tradable_product added.

Documentation

add_month_year(date, years=0, months=0)

Add time-delta of months/years to a datetime:

Parameters:

Name Type Description Default
date datetime

date which should be shifted with days or months.

required
years int

with how many years to shift the date.

0
months int

with how many months to shift the date.

0

Returns:

Type Description
tuple

tuple containing:

  • (int): year_shift
  • (int): month_shift
Note
  • These can be used to build a new datetime.

  • It is not clear how days/hours in a month should be shifted in this case. Thus, no shifted day/hour is reported.

delivery_period_id_from_name(delivery_period_name)

Working with id's can make the code more robust. For example when you want to get daily simulations, should you provide as delivery_period: daily, Daily, Day, twenty-four hours. This function converts common delivery period names to integers

Currently supported:

    monthly -> 5

    daily -> 3

    hourly -> 2

    halfhourly -> 1

    quarterhourly -> 14

Parameters:

Name Type Description Default
delivery_period_name str

granularity in string format, such as monthly or daily

required

Returns:

Type Description
int

granularity_id (int) : KYOS platfrom's delivery type id

get_start_end(trading_date, delivery_period, maturity, roll_days=None, trading_calendar=None, use_gas_rules=False)

Calculate the start/end dates of a tradable product(s). - Implementation is only for baseload (this should be extended in the future).

Parameters:

Name Type Description Default
trading_date datetime

trading date

required
delivery_period numpy array or list

products' delivery period, e.g. 5 = month, etc. * Currently, only the platform assumed delivery type integers are implemented. [nProducts x 1]

required
maturity numpy array or list containing integers =>0

products' maturity id. [nProducts x 1]

required
roll_days numpy array

roll dates before the end of the calendar product, when maturity rolls forward * A value of 0 means the product is traded up to the start of the new period. * 1 means on last day of the running period, the next period is not traded anymore. Etc. * A trading calendar can be used. In which case the "1" will be interpreted as the rolling happening on the last tradable day within the current product, e.g month. [nProducts x 1]

None
trading_calendar numpy array

List of exchange holiday dates * holidays may influence start and end date of tradable products, such as BOM, week ahead. [nHolidays x 1]

None
use_gas_rules bool

should the European gas market rules be used to calculate the delivery period of tradable produts. They affect how day-ahead, BOW, BOM are calculated.

False

Returns:

Type Description
list of datetimes): all_start_dates / all_end_dates (nProducts x 1

Start/End dates of each tradable product * if a product is not traded on the given trading date, then output NaN as start and end.

shift_business_date(date, shift, trading_calendar=None)

Given a date "start_date", find the business day "lag_days" before it.

Parameters:

Name Type Description Default
date datetime

a date, can be any date (business and non-business).

required
shift int) != 0

number of shifted business days relative to the "date". For example: * shift = 1, the first business day after the "date". * shift = 2, the second business day after the "date". * shift = -1, the first business day before the "date". * shift = -2, the business day before the business day prior to the "date".

required
trading_calendar numpy array

List of exchange holiday dates * holidays may influence start and end date of tradable products, such as BOM, week ahead. [(nHolidays x 1)]

None

Returns:

Type Description
datetime

prev_date