Group Abstract Group Abstract

Message Boards Message Boards

1
|
4.1K Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How do I select nested lists?

POSTED BY: Jay Gourley
5 Replies

For this operation on a TimeSeries we can use the dedicated TimeSeriesWindow:

dataTS = 
 FinancialData["GE", "Dividend", {{2020, 1, 1}, {2021, 12, 31}}]
TimeSeriesWindow[dataTS, {{2020, 12, 1}, {2021, 9, 1}}]
POSTED BY: Gianluca Gorni
Posted 2 years ago

With

dataTS = FinancialData["GE", "Dividend", {{2020, 1, 1}, {2021, 12, 31}}]

you could do this

Select[Normal[dataTS], Between[#[[1]], {DateObject[{2020, 12, 1, 0, 0, 0}], DateObject[{2021, 9, 1, 0, 0, 0}]}] &]

With the legacy behavior, you could convert to DateObject in your selector:

dataLeg = FinancialData["GE", "Dividend", {{2020, 1, 1}, {2021, 12, 31}}, Method -> "Legacy"];
Select[dataLeg, Between[DateObject[#[[1]]], {DateObject[{2020, 12, 1, 0, 0, 0}], DateObject[{2021, 9, 1, 0, 0, 0}]}] &]
POSTED BY: Eric Rimbey

Perfect. Better than I expected. Thanks. If you would,... What does the "&" do after Between[]? And what does Normal[] do to a TimeSeries? I read documentation on & and Normal but still don't see how they apply here.

POSTED BY: Jay Gourley
Posted 2 years ago
POSTED BY: Phil Earnhardt
Posted 2 years ago

Normal is a sort of helper function that turns specialized structures into more simple representations, typically a List. TimeSeries is one of these special forms, but I wanted to use Select, and Select needs a List or at least something List-ish. Normal got me what I wanted. TimeSeries also has properties, so instead of Normal[dataTS] I could have used dataTS["DatePath"], and that's actually probably more natural.

For your other question, there is special syntax for Function. You can write an expression for the body of a function where arguments are represented by Slot expressions (which are typically just written as #) and & is added in post-fix position. So, Function[x, x^2] could be written as #^2&. In your case, I wanted to use Select with Between as the filtering predicate. Select expects the second argument to be a function (either a literal Function or a symbol/expression that can be applied to the individual elements). So, I needed to construct a function with a Between expression.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard