Skip to content

Imports

We provide several helpers when importing data from csv files.

qcs.import_assets_from_csv(filepath_or_buffer, sep=',', date_format='%Y-%m-%d')

Import assets from a csv file and create Asset objects.

Parameters:

Name Type Description Default
filepath_or_buffer

The csv file path or data buffer. This will be passed to pd.read_csv Header row is required.

required
sep str

The delimiter used in the csv file.

','
date_format str

The format of the dates uses for date and maturity fields. Use python strftime syntax.

'%Y-%m-%d'

Returns:

Type Description
list[Asset]

A list of Asset objects created from the csv data.

Examples:

>>> assets = import_assets_from_csv("assets.csv", sep=";")

qcs.import_histories_from_csv(filepath_or_buffer, sep=',', date_format='%Y-%m-%d')

Import historical data from a csv file, process meta and data fields, and construct History objects.

csv format: - first column contains meta fields and dates in the format date_format - other columns contain data, 1 history per column - Example csv

>>> CODE;EQUITY1
>>> LABEL;Equity 1
>>> CUR;USD
>>> 2020-01-01;100
>>> 2020-01-02;105

Parameters:

Name Type Description Default
filepath_or_buffer

The csv file path or data buffer. This will be passed to pd.read_csv Header row is required.

required
sep str

The delimiter used in the csv file.

','
date_format str

The format of the dates in the csv file. Use python strftime syntax.

'%Y-%m-%d'

Returns:

Type Description
list[History]

A list of History objects created from the csv data.

Examples:

>>> histories = import_histories_from_csv(
...     "histories.csv", sep=";", date_format="%d/%m/%Y"
... )

qcs.import_snapshot_from_csv(filepath_or_buffer, code, sep=',')

Import portfolio AllocationSnapshot from a csv file.

Required columns: CODE, CURRENCY, TICKER, POSITION.

Optional columns: BENCHMARK.

Date column is ignored. If there are multiple row with the same code and ticker, the last one is used.

Parameters:

Name Type Description Default
filepath_or_buffer str

The csv file path or data buffer. This will be passed to pd.read_csv Header row is required.

required
code str

The portfolio code to be read from.

required
sep str

The separator used in the csv file, .

","

Returns:

Type Description
AllocationSnapshot

Examples:

>>> portfolios = import_snapshot_from_csv(
...     "portfolios.csv",
...     code="PORT_1",
...     sep=",",
...     date="2023-01-01",
...     date_format="%Y-%m-%d"
... )