I need to implement a recursive formula in my code block which is
bayesian_prices = []
for i in range(10):
q = dayqvalue(i, grid, fullData)
w = compute_dayweights(q)
option_data, index_prices, initial_date = get_samedated_opt(fullData, i, 1)
callput, tmt, ex, mkt = orderdata(option_data)
baypr = compute_bayesian_prices(w, grid, callput, tmt, ex, index_prices)
bayesian_prices.append(baypr)
What I need to do regards the computation of "q". Everytime I need to compute the q as sum of the old value and the new value obtained from the function "dayqvalue". In other words, when i=0 the first list of q values is computed. Then with i=1 I should have a list which is the sum of q computed at 0 and q computed at 1 and so on. The last time that the for loop runs, I should have a list of q which is the sum of all the precedeing lists plus the new one. Is there a simple way to implement it? The list q contains about a thousand elements.
EDIT
q
is a list of 1000 elements. Everytime I should add entry by entry a new list of 1000 elements to the previous one. For instance, assume to have q
computed when i=0
and when i=1
. I would obtain newq = [q_0[0] + q_1[0] , q_0[1] + q_1[1]]
in the first 2 entry. The list newq
should be of the same lenght of q_0
and q_1
. It should contain the sum of their values entry by entry.