I'm fairly new at this so bear with me here...
I have a pipeline that is calculating the 5 day moving average sentiment in a universe of stocks (the universe is QTradableStocksUS). I would like to calculate the average sentiment score for all of the stocks in this universe (I've used a CustomFactor for this which is pasted below.
I keep running into issues and may not be approaching this correctly. Any advice / suggestions / examples? I've been spinning my wheels on this for quite some time so really appreciate any help!
----Pipeline----
def make_pipeline(context):
my_universe = QTradableStocksUS()
mean_sentiment_5day = SimpleMovingAverage(inputs=[sentiment.sentiment_signal], window_length=5)
my_pipe = Pipeline(
columns={
'mean_sentiment_5day': mean_sentiment_5day
},
screen=my_universe,
)
----Custom Factor to Calculate Mean Sentiment Score for the Universe----
class Sentiment_Mean(CustomFactor):
window_length = 1
def compute(self, today, assets, out, data):
out[:] = np.nanmean(data)