I have the following complex nested iteration situation.

I begin with a list, data
, that comprises 16 TemporalData objects

Each TemporalData object contains 2 paths. Let’s call them v
and r
. They have a common date index, so the date paths in each path are both the same length.

I partition each of the paths in the TemporalData objects in data
into 20 day periods, offset by 1 / overlapping by 19.
partitionedSets = Partition(#, 20, 1) & /@ data((#))("DatePaths") & /@ Range@Length@data;
partitionedSets
now contains 16 lists of 2 lists (representing v
and r
) that vary in length as follows. vLengths
and rLengths
will always return the same values
vLengths = Length@partitionedSets((#, 1)) & /@ Range@16
(*{216, 216, 215, 214, 213, 212, 212, 212, 211, 210, 209, 208, 207,
207, 207, 206}*)

The output of the first list of partitionedSets
looks like this:
partitionedSets((1, All, 1))
 Now, for each of the 16 lists of
v
and r
series, I want to create a Date indexed set of “zipped together” ordered pairs of v
and r
. This is easy enough to do manually. For example, to get the first set of orderedPairs
from the first partitionedSet
of the first TemporalData object in data
:
orderedPairs = MapThread(List, {partitionedSets((1, 1, 1, All, 1)),
Thread({partitionedSets((1, 1, 1, All, 2)),
partitionedSets((1, 2, 1, All, 2))})})
The problem I have is when I attempt to gather all combinations of 16x2xn lists into lists of ordered pairs. This is because the value of n
depends on the Length of the combination of v
or r
and the partitionedSet
I am currently iterating through. I know the solution is to use Outer
— and I can get it to work if I arbitrarily limit n
in this case to 200.
dumb = Outer(MapThread(List,
{partitionedSets((#1, 1, #2, All, 1)),
Thread(
{partitionedSets((#1, 1, #2, All, 2)),
partitionedSets((#1, 2, #2, All, 2))})}) &, Range@16,Range@200);
But what I am really trying to achieve is to make this same code work where the value for the second slot #2
in Outer
is dynamic / recursive (really should be something like Range@vlengths((#))&/@Range@Length@vLengths
– but this fails.)
So, my question is:
How can I functionally create 16*n lists of orderedPairs
where n is dynamic / nested /recursive?