Message Boards Message Boards


Remove one element within a nested list or create lists of equal length

Posted 14 days ago
6 Replies
1 Total Likes
port = {"^GSPC", "GLD", "VCSH"};
ret1 = QuantityMagnitude[
FinancialData[#, "Return", {2021}]["Values"]] & /@ port;
In[120]:= Length[#] & /@ {ret1[[1]], ret1[[2]], ret1[[3]]}

Out[120]= {169, 168, 168}

I have three sub-lists of unequal length. How could I remove, say the first element in the first list?? I have tried Drop without success. Better yet, how would I create the three lists of equal length in the first place???

Thanks much for the help.

6 Replies
Posted 14 days ago



which returns

Posted 14 days ago

Excellent job Bill

I had manually removed the first element from the first list because it was the easiest. I did a correlation test between the first list and the next two lists. My method resulted in a correlation near zero for list 1 related to lists 2 & 3. The data is time stamped, I just removed the time stamp for easier computations. I then used your method that basically removes the last element in the list. I was quite surprised to find a correlation of 30% between list 1 with both lists 2 & 3. There are 168 elements in each of the three lists, it was quite surprising to find such a difference between either removing the first versus removing the last element.

Thanks so much for your help.

Posted 13 days ago

"Surprising" and "such a difference from such a small change" always makes me think "I've made a mistake in this somehow."

Perhaps the time stamps might be too important to discard. Is there any way you could do a ListPlot with the time stamps and another without the time stamps and see if the reason for the large change becomes obvious? If that explains things then would interpolating the {value,time} points to construct value=function[time] still make your computations easy

Posted 13 days ago

Hi Bill The correlations between no deletion and 1 day deletion enter image description here

I plotted the graphs, but Return is the % change in price from the day before, so the charts just looks like noise.
enter image description here

I did average the Return, which did reduce the error caused by the one day deletion. enter image description here

Below is the Notebook

Posted 13 days ago

I peeked at one of the three using

port = {"^GSPC", "GLD", "VCSH"};
ret1 = FinancialData[#, "Return", {2021}] & /@ port;

and that gives some functions that can be looked up in the help system.

It appears that the data might already be the result of interpolation and there don't seem to be any time stamps associated with individual data values. If that is the case then I don't understand how it is possible that you are getting different numbers of data points sometimes or why dropping extra items would make such a difference.

At this point I'm guessing to go back to the source of this data or the source of the processing and ask for an explanation.

Posted 13 days ago

Take a look at the documentation for Rest and Most. FinancialData returns a TimeSeries. There are many functions available for time-series processing. For time-series correlation, take a look at this post on MSE and this one on this site.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract