Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Problem with RollingPearsonOfReturns

Hello,

I am trying to calculate the correlation between a narrowed down list of stocks ("securities_to_trade") and SPY. When I use RollingPearsonOfReturns in Research I get the following error:

TypeError: 'Series' objects are mutable, thus they cannot be hashed

Could someone please help me debug? Thanks!

2 responses

Is there an example of how I can use RollingPearsonOfReturns() to find M out of N stocks that are least correlated with each other?

thanks
-kamal

Hello,

I created a custom factor to attach correlations to a pipeiline for a given screen of stocks (typically S&P500). Can someone tell me how to fix this code sot hat it doesn't yield runtime errors?

thanks

-kamal

class Correl(CustomFactor):
inputs = Q500US()
def compute(self, today, assets, out):
end = today
start = end - 3*252
benchmark = USEquityPricing('SPY', fields='price', start_date=start, end_date=end)
rolling_correlations = RollingPearsonOfReturns(
target= benchmark,
returns_length=3*252,
correlation_length=3*252,
mask=assets
)
out[:] = rolling_correlations