PyZipline/pyzipline/utils.py

25 lines
685 B
Python
Raw Permalink Normal View History

2023-12-21 08:49:31 -05:00
"""This is a list of various utility functions used in PyZipline."""
2023-12-22 13:56:50 -05:00
from datetime import datetime as dtime
2023-12-19 05:36:18 -05:00
2023-12-22 13:56:50 -05:00
def convert_str_to_datetime(date_string: str) -> dtime:
"""Converts a Zipline date string to a datetime object
2023-12-19 05:36:18 -05:00
Args:
2023-12-21 08:49:31 -05:00
date_string: String to convert
Returns:
2023-12-21 08:49:31 -05:00
datetime: Datetime object
2023-12-19 05:36:18 -05:00
"""
2023-12-22 13:56:50 -05:00
return dtime.strptime(date_string, '%Y-%m-%dT%H:%M:%S.%fZ')
2023-12-22 13:56:50 -05:00
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')