Thanks for the response Chris! That worked perfectly did not know about the masking function until now!
Another question? So in my factor I am trying to get the std of the stocks projection price but it keeps taking the std of the row which is useless to me. My output is an array that looks something like this
A B C A B C
[[121.431, 153.65, 34.65], [120.54, 160.63, 35.76] where those are three different stocks so how would i get the std of A and B ext.???
class Last_Close_30(CustomFactor):
"""
Gets the latest prices for each asset
"""
inputs = [USEquityPricing.close]
window_length = 30
outputs = ['yesterday','projection','difference','standard']
def compute(self, today, assets, out, close):
a = -0
b = -1
look_back = 0
sample = []
# gets log return from last 30 close prices and puts in array
for look_back in range(0,30):
logs = np.log(close[a]/close[b])
sample.append(logs)
a = a-1
b = b-1
# project 10 time steps ahead and make projected price 10 days out
# that process done 1000 times (monte carlo)
monte_carlo = []
for num in range(0,1000):
tomorrow_projection = close[-1]
for count in range(0, 10):
random_number = random.choice(sample)
tomorrow_projection = tomorrow_projection * np.exp(random_number)
monte_carlo.append(tomorrow_projection)
# average close prices for each stock
average = (sum(monte_carlo))/1000
# difference from average
difference = average - close[-1]
std_mc = np.nanstd(monte_carlo) # NOT WORKING
# output (yesterdays price, average projection of tomorrows price, difference of yesterdays and average, standard deviation)
out.yesterday[:] = close[-1]
out.projection[:] = average
out.difference[:] = difference
out.standard[:] = std_mc