the weights look like this around the esu expiryin [ ]weights get_roll_weights(''expiryprices columnsin [ ]weights ix['':''out[ ]esu esz finallythe rolled future returns are just weighted sum of the contract returnsin [ ]rolled_returns (prices pct_change(weightssum( rolling correlation and linear regression dynamic models play an important role in financial modeling as they can be used to simulate trading decisions over historical period moving window and exponentiallyweighted time series functions are an example of tools that are used for dynamic models correlation is one way to look at the co-movement between the changes in two asset time series pandas' rolling_corr function can be called with two return series to compute the moving window correlation firsti load some price series from yahoofinance and compute daily returnsaapl web get_data_yahoo('aapl''')['adj close'msft web get_data_yahoo('msft''')['adj close'aapl_rets aapl pct_change(msft_rets msft pct_change(theni compute and plot the one-year moving correlation (see figure - )in [ ]pd rolling_corr(aapl_retsmsft_rets plot(one issue with correlation between two assets is that it does not capture differences in volatility least-squares regression provides another means for modeling the dynamic relationship between variable and one or more other predictor variables in [ ]model pd ols( =aapl_retsx={'msft'msft_rets}window= in [ ]model beta out[ ]datetimeindex entries : : to : : data columns financial and economic data applications www it-ebooks info