Example #1
0
def plot_rolling_sharpe(returns, nperiods, rfrate, window, ax=None):
    """
    Plot rolling Sharpe ratio
        returns = series of returns
        nperiods = number of returns in a year
        rfrate = risk free rate
        window = number of months in sliding window
    """
    if ax is None:
        ax = plt.gca()

    overall_sharpe = timeseries.sharpe_ratio(returns, nperiods, rfrate)
    rolling_sharpe = timeseries.rolling_sharpe(returns, nperiods,
                                               rfrate, 21*window)

    ax.plot(rolling_sharpe, color='orangered', lw=2, 
            label='Rolling Sharpe')
    
    ax.axhline(overall_sharpe, 
               color='steelblue', linestyle='--', lw=3,
               label='Overall Sharpe')

    ax.axhline(0, color='black', linestyle='-', lw=2)

    style_default(ax, 
                  title='Rolling Sharpe ratio ({} months)'.format(window),
                  ylabel='Sharpe ratio')
Example #2
0
def plot_rolling_sharpe(returns, nperiods, rfrate, window, ax=None):
    """
    Plot rolling Sharpe ratio
        returns = series of returns
        nperiods = number of returns in a year
        rfrate = risk free rate
        window = number of months in sliding window
    """
    if ax is None:
        ax = plt.gca()

    overall_sharpe = timeseries.sharpe_ratio(returns, nperiods, rfrate)
    rolling_sharpe = timeseries.rolling_sharpe(returns, nperiods, rfrate,
                                               21 * window)

    ax.plot(rolling_sharpe, color='orangered', lw=2, label='Rolling Sharpe')

    ax.axhline(overall_sharpe,
               color='steelblue',
               linestyle='--',
               lw=3,
               label='Overall Sharpe')

    ax.axhline(0, color='black', linestyle='-', lw=2)

    style_default(ax,
                  title='Rolling Sharpe ratio ({} months)'.format(window),
                  ylabel='Sharpe ratio')
Example #3
0
 def sharpe_ratio(self):
     self.sharpe = timeseries.sharpe_ratio(
                       self.returns, self.frequency, self.rfrate)
     self.results['Sharpe ratio'] = format_string(self.sharpe, '.2f')
Example #4
0
 def sharpe_ratio(self):
     self.sharpe = timeseries.sharpe_ratio(
                       self.returns, self.frequency, self.rfrate)
     self.results['Sharpe ratio'] = format_string(self.sharpe, '.2f')