Portfolio

class pyfolio_performance.Portfolio(filename)[source]

The main class to parse and access different aspects of a portfolio stored in a XML file.

Uses the XML file created by portfolio performance.

Parameters:

filename (str) – The path of the XML file to parse.

evaluateCluster(clusters, fn_filter, fn_getClusterId, fn_aggregation)[source]

Evaluates all transactions of the portfolio as follows. Every transaction that is successfully filtered by fn_filter, gets put in a cluster through fn_getClusterId. The objects in the cluster are aggregated through the fn_aggregation function.

Parameters:
  • clusters (dict(object) / {k->v}) – The overall clusters.

  • fn_filter (function(transaction) -> bool) – Filter function. An entry needs to pass the filter with True to be considered.

  • fn_getClusterId (function({k->v}, Transaction) -> k) – Given the cluster and the transaction, this method gives the key to the cluster the transaction belongs to.

  • fn_aggregation (function(v, Transaction) -> v) – The aggregation function that combines cluster values. This updates the cluster itself at the position cluster-id for every considered transaction.

Returns:

Nothing is returned.

Type:

None

getAccounts()[source]

Returns the list of Account objects in the portfolio.

Returns:

The extracted Account list.

Type:

list(Account)

getDepots()[source]

Returns the list of Depot objects in the portfolio.

Returns:

The extracted Depot list.

Type:

list(Depot)

getInvestmentInto(security, before=None)[source]

Computes how much is invested into a specific security before a given date. If no date is given, the total investment is calculated.

Returns:

value in cents of investement

Type:

int

getSecurities()[source]

Returns the list of all unique securities in any depot. :return: The list. :type: list(Security)

getShares(theSecurity)[source]

Returns the number of shares that the given security objects has in the portfolio overall.

Parameters:

theSecurity (Security) – The security queried.

Returns:

The number of shares in all depots summed up.

Type:

float

getTotalTransactions()[source]

Returns the list of all transactions in the portfolio across all depots and accounts.

Returns:

The extracted transaction list.

Type:

list(Transaction)