예제 #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')
예제 #2
0
파일: plotting.py 프로젝트: wklm/QuantCode
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')
예제 #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')
예제 #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')