return rets mean(rets std(np sqrt(annnowdividing vol into quartiles with qcut and aggregating with sharpe we obtainin [ ]trade_rets groupby(pd qcut(vol )agg(sharpeout[ ][ ( ( - ( these results show that the strategy performed the best during the period when the volatility was the highest more example applications here is small set of additional examples signal frontier analysis in this sectioni'll describe simplified cross-sectional momentum portfolio and show how you might explore grid of model parameterizations firsti'll load historical prices for portfolio of financial and technology stocksnames ['aapl''goog''msft''dell''gs''ms''bac'' 'def get_px(stockstartend)return web get_data_yahoo(stockstartend)['adj close'px dataframe({nget_px( ''''for in names}we can easily plot the cumulative returns of each stock (see figure - )in [ ]px px asfreq(' 'fillna(method='pad'in [ ]rets px pct_change(in [ ](( retscumprod( plot(for the portfolio constructionwe'll compute momentum over certain lookbackthen rank in descending order and standardizedef calc_mom(pricelookbacklag)mom_ret price shift(lagpct_change(lookbackranks mom_ret rank(axis= ascending=falsedemeaned ranks ranks mean(axis= return demeaned demeaned std(axis= with this transform function in handwe can set up strategy backtesting function that computes portfolio for particular lookback and holding period (days between trading)returning the overall sharpe ratiocompound lambda ( xprod( daily_sr lambda xx mean( std(more example applications www it-ebooks info