13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

491

It should be well remembered that large unexpected upward moves are just as dangerous as

large downward moves since they reflect unanticipated behaviour of the strategy. For instance,

a large upward performance jump could imply a new regulatory regime that has benefited the

strategy. This must now be taken into account in any subsequent strategy development in order

to maintain consistency of performance.

32.2 Python QSTrader Implementation

The implementation of the annualised rolling Sharpe ratio is now part of the QSTrader codebase

and is originally due to @nwillemse.

The addition of the annualised rolling Sharpe ratio necessitated an update to the minimum

required version of the Pandas library used by QSTrader, which is now 0.18.0. Hence if you wish

to use this feature you may need to update your Pandas version to 0.18.0 or greater.

The annualised rolling Sharpe feature is provided as a chart that sits underneath the equity

curve in the tearsheet visual output. It is optional and can be activated by setting rolling_sharpe=True

in the instantiation of the TearsheetStatistics class in the backtest. In the class itself it can

be seen that it is simply implemented as a member flag:

class TearsheetStatistics(AbstractStatistics):

def __init__(

self, config, portfolio_handler,

title=None, benchmark=None, periods=252,

rolling_sharpe=False

):

..

..

self.rolling_sharpe = rolling_sharpe

..

..

To calculate the annualised rolling Sharpe it is necessary to obtain the rolling object by

using the rolling method on the strategy returns series, with a lookback window equal to the

number of trading periods (self.periods).

The calculation simply multiplies the square root of trading periods by the ratio of the rolling

mean to the rolling standard deviation. Note that there is no risk-free rate included here. Zero

returns are considered the risk-free alternative. The same is carried out for the benchmark. All

of this occurs in the get_results method of the TearsheetStatistics class:

def get_results(self):

# Equity

equity_s = pd.Series(self.equity).sort_index()

# Returns

returns_s = equity_s.pct_change().fillna(0.0)

# Rolling Annualised Sharpe

rolling = returns_s.rolling(window=self.periods)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!