compute portfolio weights freq '%dbhold port calc_mom(priceslblag= daily_rets prices pct_change(compute portfolio returns port port shift( resample(freqhow='first'returns daily_rets resample(freqhow=compoundport_rets (port returnssum(axis= return daily_sr(port_retsnp sqrt( holdfigure - cumulative returns for each of the stocks when called with the prices and parameter combinationthis function returns scalar valuein [ ]strat_sr(px out[ ] from thereyou can evaluate the strat_sr function over grid of parametersstoring them as you go in defaultdict and finally putting the results in dataframefrom collections import defaultdict lookbacks range( holdings range( dd defaultdict(dictfor lb in lookbacksfor hold in holdingsdd[lb][holdstrat_sr(pxlbhold financial and economic data applications www it-ebooks info