Skip to content

Utilities

This is a list of various utility functions used in PyZipline.

Functions:

Name Description
convert_datetime_to_str

Converts a datetime object to a Zipline (ISO 8601) date string

convert_str_to_datetime

Converts a Zipline date string to a datetime object

convert_datetime_to_str(datetime)

Converts a datetime object to a Zipline (ISO 8601) date string

Parameters:

Name Type Description Default
datetime datetime

Datetime to convert

required

Returns:

Name Type Description
str str

Converted date string

Source code in pyzipline/utils.py
def convert_datetime_to_str(datetime: dtime) -> str:
    """Converts a datetime object to a Zipline (`ISO 8601`) date string

    Args:
        datetime: Datetime to convert

    Returns:
        str: Converted date string
    """
    return datetime.strftime('%Y-%m-%dT%H:%M:%S.%f+00:00')

convert_str_to_datetime(date_string)

Converts a Zipline date string to a datetime object

Parameters:

Name Type Description Default
date_string str

String to convert

required

Returns:

Name Type Description
datetime datetime

Datetime object

Source code in pyzipline/utils.py
def convert_str_to_datetime(date_string: str) -> dtime:
    """Converts a Zipline date string to a datetime object

    Args:
        date_string: String to convert

    Returns:
        datetime: Datetime object
    """
    return dtime.strptime(date_string, '%Y-%m-%dT%H:%M:%S.%fZ')