Exemplo n.º 1
0
    def plot(self,
             ucrp=False,
             bah=False,
             residual=False,
             assets=False,
             **kwargs):
        """ Plot strategy equity.
        :param ucrp: Add uniform CRP as a benchmark.
        :param bah: Add Buy-And-Hold portfolio as a benchmark.
        :param residual: Add portfolio minus UCRP as a benchmark.
        :param assets: Add asset prices.
        :param kwargs: Additional arguments for pd.DataFrame.plot
        """
        # NOTE: order of plotting is important because of coloring
        # plot portfolio
        d = self.to_dataframe()
        D = d.copy()

        # add individual assets
        if isinstance(assets, bool):
            if assets:
                assets = self[0].asset_equity.columns
            else:
                assets = []

        if list(assets):
            D = D.join(self[0].asset_equity)

        ax = D.plot(color=_colors_hash(D.columns), **kwargs)
        kwargs['ax'] = ax

        ax.set_ylabel('Total wealth')

        # plot residual strategy
        if residual:
            d['RESIDUAL'] = self[0].residual_r.cumprod()
            d[['RESIDUAL']].plot(**kwargs)

        # plot uniform constant rebalanced portfolio
        if ucrp:
            from .algos import CRP
            crp_algo = CRP().run(self[0].X.cumprod())
            crp_algo.fee = self[0].fee
            d['UCRP'] = crp_algo.equity
            d[['UCRP']].plot(**kwargs)

        # add bah
        if bah:
            from .algos import BAH
            bah_algo = BAH().run(self[0].X.cumprod())
            bah_algo.fee = self[0].fee
            d['BAH'] = bah_algo.equity
            d[['BAH']].plot(**kwargs)

        return ax
Exemplo n.º 2
0
    def plot(self, ucrp=False, bah=False, assets=False, **kwargs):
        """ Plot strategy equity.
        :param ucrp: Add uniform CRP as a benchmark.
        :param bah: Add Buy-And-Hold portfolio as a benchmark.
        :param assets: Add asset prices.
        :param kwargs: Additional arguments for pd.DataFrame.plot
        """
        # NOTE: order of plotting is important because of coloring
        # plot portfolio
        d = self.to_dataframe()
        portfolio = d.copy()
        ax = portfolio.plot(linewidth=3., legend=False, **kwargs)
        kwargs['ax'] = ax

        ax.set_ylabel('Total wealth')

        # plot uniform constant rebalanced portfolio
        if ucrp:
            from universal.algos import CRP
            crp_algo = CRP().run(self[0].X.cumprod())
            crp_algo.fee = self[0].fee
            d['UCRP'] = crp_algo.equity
            d[['UCRP']].plot(**kwargs)

        # add bah
        if bah:
            from universal.algos import BAH
            bah_algo = BAH().run(self[0].X.cumprod())
            bah_algo.fee = self[0].fee
            d['BAH'] = bah_algo.equity
            d[['BAH']].plot(**kwargs)

        # add individual assets
        if isinstance(assets, bool):
            if assets:
                assets = self[0].asset_equity.columns
            else:
                assets = []

        if list(assets):
            self[0].asset_equity.sort_index(axis=1).plot(
                color=_colors(len(assets) + 1), **kwargs)

        # plot portfolio again to highlight it
        kwargs['color'] = 'blue'
        portfolio.plot(linewidth=3., **kwargs)

        return ax
Exemplo n.º 3
0
    def plot(self, ucrp=False, bah=False, assets=False, **kwargs):
        """ Plot strategy equity.
        :param ucrp: Add uniform CRP as a benchmark.
        :param bah: Add Buy-And-Hold portfolio as a benchmark.
        :param assets: Add asset prices.
        :param kwargs: Additional arguments for pd.DataFrame.plot
        """
        # NOTE: order of plotting is important because of coloring
        # plot portfolio
        d = self.to_dataframe()
        portfolio = d.copy()
        ax = portfolio.plot(linewidth=3., legend=False, **kwargs)
        kwargs['ax'] = ax

        ax.set_ylabel('Total wealth')

        # plot uniform constant rebalanced portfolio
        if ucrp:
            from algos import CRP
            crp_algo = CRP().run(self[0].X.cumprod())
            crp_algo.fee = self[0].fee
            d['UCRP'] = crp_algo.equity
            d[['UCRP']].plot(**kwargs)

        # add bah
        if bah:
            from algos import BAH
            bah_algo = BAH().run(self[0].X.cumprod())
            bah_algo.fee = self[0].fee
            d['BAH'] = bah_algo.equity
            d[['BAH']].plot(**kwargs)

        # add individual assets
        if isinstance(assets, bool):
            if assets:
                assets = self[0].asset_equity.columns
            else:
                assets = []

        if list(assets):
            self[0].asset_equity.sort_index(axis=1).plot(color=_colors(len(assets) + 1), **kwargs)

        # plot portfolio again to highlight it
        kwargs['color'] = 'blue'
        portfolio.plot(linewidth=3., **kwargs)

        return ax