Back to Community
How to get single stock price data in CustomFactor calculating

Hi, I want to create a custom factor whose calculation is based on SPY price data.
For example: Asset = USEquityPricing.close.latest # the close price of the whole universe
Underlying = USEquityPricing.close[sid(8554)] #this can not be achieved which is also my question
Px = Underlying/Asset

Now I am trying to use customfilter to calculate spy's price as a factor, but when I try to use this factor to calculate "Underlying/Asset" the error appears. I think it's because these two factors have different dimension. The Asset has whole stocks price but Underlying only contain spy's price so they can't be matched to calculate.

So I wonder if there is a way to get the single stocks' price data in pipeline just like "USEquityPricing.close[sid(8554)] "

Loading notebook preview...
Notebook previews are currently unavailable.
2 responses

"I wonder if there is a way to get the single stocks' price data in pipeline just like "USEquityPricing.close[sid(8554)]".

One can create a custom factor to do this. Something like...

import numpy as np
class SPY_Close_Price(CustomFactor): 
 One can use any inputs from any assets and set any factor outputs based upon them. 
 In this case, simply return the close price of SPY for every asset. 
 inputs = [USEquityPricing.close] 
 window_length = 1 
 def compute(self, today, assets, out, close):
 spy_index = np.where(assets == 8554) # 8554 is the SID of SPY 
 # index -1 gets the latest price row. spy_index gets the SPY column. 
 out[:] = close[-1, spy_index] 

Hi Dan Whitnable,

Great! Thanks so much for your help!

Last Articles

stop loss and trigger price cboe interest rate 10-year t-no 10 year us treasury bond rate what is stop loss trigger price the gdp deflator is the ratio of list of company stock symbols how to predict forex movement etrade minimum to open account option pricing calculator black scholes int object is not iterable python 3 factor model fama french how does trailing stop work interactive brokers minimum monthly fee