Source code for

.. Copyright (c) 2016 Marshall Farrier

Data - compare (:mod:``)

.. currentmodule::

import numpy as np
import pandas as pd

[docs]def compare(eq_dfs, columns=None, selection='Adj Close'): """ Get the relative performance of multiple equities. .. versionadded:: 0.5.0 Parameters ---------- eq_dfs : list or tuple of DataFrame Performance data for multiple equities over a consistent time frame. columns : iterable of str, default None Labels to use for the columns of the output DataFrame. The labels, if provided, should normally be the names of the equities whose performance is being compared. selection : str, default 'Adj Close' Column containing prices to be compared. Defaults to 'Adj Close'. Returns ------- rel_perf : DataFrame A DataFrame whose columns contain normalized data for each equity represented in `eq_dfs`. The initial price for each equity will be normalized to 1.0. Examples -------- .. code-block:: python import pynance as pn eqs = ('FSLR', 'SCTY', 'SPWR') eq_dfs = [] for eq in eqs: eq_dfs.append(, '2016')) rel_perf =, eqs) Notes ----- Each set of data passed in `eq_dfs` is assumed to have the same start and end dates as the other data sets. """ content = np.empty((eq_dfs[0].shape[0], len(eq_dfs)), dtype=np.float64) rel_perf = pd.DataFrame(content, eq_dfs[0].index, columns, dtype=np.float64) for i in range(len(eq_dfs)): rel_perf.iloc[:, i] = eq_dfs[i].loc[:, selection] / eq_dfs[i].iloc[0].loc[selection] return rel_perf