How to create a complex variable from dated list values

Can anyone help me to construct a variable "PI" from values of variable x. Variable x represents a group of two time series rj and ri on equal dates(joined two dated lists with states).Variable x have about 2000 observations. Example of variable x:

f1 = FinancialData["PA:ACA", "Return", {{2007, 1, 1}, {2014, 10, 20}}];

cac40 = FinancialData["^FCHI","Return", {{2007, 1, 1}, {2014, 10, 20}}];

x=Select[GatherBy[Join[f1,cac40], First], Length@# == 2 &];

Form of variable x: {{{{2014,10,1},0.01},{{2014,10,1},0.05}}}, {{{2014,10,2},0.02},{{2014,10,2},0.06}}}}. Time series-variable rj in the above fromula represents the first dated list with states 0.01 and 0.02, and time series ri represents second dated list with states 0.05,0.06. In the case of the above example rj refer to values of f1 and ri refer to values of cac40. If for example rj had state-value of 0 on 1st October, variable r_(ј,t,τ), on 2nd October should be equal to r_(ј,t,τ)=(1+0.05)-1. If for example rj have 2 consecutive values of 0, on 1st and 2nd October, PI for 3rd October should capture the impact of first and second date as r_(ј,t,τ)=((1+0.05)*(1+0.06))-1.

Delta is a dummy variable that takes value 1 if the value of variable rj on current date or date before have value 0. If rj is different from 0, delta should be 0, such that the numerator of PI takes value 0. Variable w represents a weight and have a form of list of equal values for all x dates. For example 0.5 for all 2000 observations. It could be treated as a constant, say 1, or thrown from PI formula.

Summation of numerator and denominator of PI variable should be done for one business week-5 days(Mo,Tu,We,Th,Fr). Variables rj and ri are already paired values on equal business-trading day, so PI should represent a measure that would refer to one week.

• Do you have any code of your own that you've tried to calculate PI with? It would be easier to help if we could see what part of the formula you are having problems with. – Edmund Oct 27 '14 at 18:31
• Not, yet. I calculate it in MS Excel. Most of work is concentrate on calculating rjtτ. In Excel, I form 3 additional columns that counts the consecutive „runs“ where of rjtτ have value 0. First column returns 1 if rjt is 0. Second column counts consecutive runs form first column. (Example: if in 1st column {0,1,0,1,1,1,0}, second column have values {0,1,0,1,2,3,0}. In third column I calculate rjtτ using "if" function with reference on second column and new (4th) column that returns (1+ ri) if rj=0, and value 0 if rjtτ is different from zero.Summation is done by SQL query in Access. – Branimir Oct 28 '14 at 9:04
• Try defining your delta function using Piecewise and your r function using Piecewise and FoldList. You can give FoldList a vector of the required length or the whole vector then something like this FoldList[#1 (1+#2)&, 1, r[[1 ;; \[tau] -1]]]-1 will get you what you need for the product part. – Edmund Oct 28 '14 at 19:04
• That should be \[Tau] not \[tau] – Edmund Oct 29 '14 at 1:11