faninsar.Pair#

class faninsar.Pair(pair: Sequence[datetime, datetime])[source]#

Bases: object

Pair class for one pair.

__init__(pair: Sequence[datetime, datetime]) None[source]#

Initialize the Pair class.

Parameters:

pair (Sequence[datetime, datetime]) – Sequence object of two dates. Each date is a datetime object. For example, (date1, date2).

Methods

__init__(pair)

Initialize the Pair class.

from_name(name[, parse_function, date_args])

Initialize the pair class from a pair name.

primary_string([date_format])

Return the primary dates of all pairs in string format.

secondary_string([date_format])

Return the secondary dates of all pairs in string format.

to_numpy([dtype])

Return the pair as a numpy array.

Attributes

days

The time span of the pair in days.

name

String of the pair with format of '%Y%m%d_%Y%m%d'.

primary

The primary dates of all pairs.

secondary

The secondary dates of all pairs.

values

The values of the pair with format of datetime.

classmethod from_name(name: str, parse_function: Callable | None = None, date_args: dict | None = None) Pair[source]#

Initialize the pair class from a pair name.

Parameters:
  • name (str) – Pair name.

  • parse_function (Callable, optional) – Function to parse the date strings from the pair name. If None, the pair name will be split by ‘_’ and the last 2 items will be used. Default is None.

  • date_args (dict, optional) – Keyword arguments for pd.to_datetime() to convert the date strings to datetime objects. For example, {‘format’: ‘%Y%m%d’}. Default is {}.

Returns:

pair – Pair class.

Return type:

Pair

primary_string(date_format: str = '%Y%m%d') str[source]#

Return the primary dates of all pairs in string format.

Parameters:

date_format (str) – Format of the date string. Default is ‘%Y%m%d’. See more at strftime Format Codes.

secondary_string(date_format: str = '%Y%m%d') str[source]#

Return the secondary dates of all pairs in string format.

Parameters:

date_format (str) –

Format of the date string. Default is ‘%Y%m%d’. See more at strftime Format Codes.

to_numpy(dtype: DTypeLike = None) NDArray[np.datetime64][source]#

Return the pair as a numpy array.

property days: int#

The time span of the pair in days.

property name: str#

String of the pair with format of ‘%Y%m%d_%Y%m%d’.

property primary: Timestamp#

The primary dates of all pairs.

property secondary: Timestamp#

The secondary dates of all pairs.

property values: NDArray[np.datetime64]#

The values of the pair with format of datetime.