Ejemplo n.º 1
0
def r_bar_port(port, index_port):
    """Barplot portfolio returns vs. index in OP style."""
    port1_s = port.total_value.resample('M', how='last')
    rets1 = returns(port1_s.values)
    port2_s = index_port.total_value.resample('M', how='last')
    rets2 = returns(port2_s.values)
    if len(index_port.prices.columns) == 1:
        index_name = index_port.prices.columns[0]
    else:
        index_name = 'Index'
    ax = _bar_arrays(rets1[-12:], rets2[-12:], ['Portfolio', index_name])
    ax.set_ylabel('Return')
    ax.set_xticklabels([dt.strftime('%b') for dt in port1_s.index[-12:]])
    plt.show()
Ejemplo n.º 2
0
def r_heat_port(port):
    """Plot a heatmap for portfolio symbols, for last 12 months."""
    port_s = port.prices.resample('M', how='last')
    ret_arr = zeros((len(port_s.columns), 12))
    for ind in arange(len(port_s.columns)):
        ret_arr[ind] = returns(port_s.ix[:, ind].values[-13:])
    months = [dt.strftime('%b') for dt in port_s.index[-12:]]

    ax = _heat_array(ret_arr)
    ax.set_yticklabels(port.prices.columns, minor=False)
    ax.set_xticklabels(months, minor=False)
    year1 = port_s.index[-12].strftime('%b %Y')
    year2 = port_s.index[-1].strftime('%b %Y')
    plt.suptitle('Percentage returns ({} - {})'.format(year1, year2),
                 fontsize=18)
    plt.tick_params(axis='x', which='both', bottom='off', top='off',
                    labeltop='on')
    plt.tick_params(axis='y', which='both', left='off', right='off',
                    labelleft='on')
    plt.show()
Ejemplo n.º 3
0
 def returns(self):
     """Percentage returns."""
     return returns(self.cprices)