Message Boards Message Boards

Determining common dates for several financial series

Posted 2 years ago

Hello! I'm trying to extract simultaneous observation from 11 financial series

Clear["Global`*"];
port = {"Thermo Fisher Scientific", "KLA-Tencor", "Air Liquide", 
   "Schneider Electric", "Silicon Motion", 
   "Compagnie de Saint-Gobain", "Groupe Fnac", "Pfizer", 
   "Schlumberger", "ArcelorMittal", "Valneva SE"};
Mois = 6;
Durée = 30 Mois;
début = DatePlus[DateList[], -Durée];

during 6 months.

ret = FinancialData[#, "Return", {début, Date[]}, "DateValue"] & /@ 
   port;

These data were differently recorded: 122, 123 or 124 measures. Thus, in tried to resample them using common dates:

Map[#["PathLengths"] &, ret]
commonDates = 
  Intersection[Table[Flatten[ret[[i]]["Dates"]], {i, Length@ret}]] // 
   Flatten;
Length@%
Retours = 
  ParallelTable[
   Select[ret[[i]]["DatePath"], MemberQ[commonDates, First@#] &], {i, 
    Length@ret}];
Retours = 
  ParallelTable[
   Map[QuantityMagnitude@#[[2]] &, Retours[[i]]], {i, Length@Retours}];
Map[Length, Retours]

It does not work, since the length of "CommonDates" is 369 (=122+123+124). Nevertheless, I can see a lot of duplicates in this list, such as

DateObject[{2021, 8, 5, 0, 0, 0.}, "Instant", "Gregorian", 1.]

So, what is the problem? THanks a lot!

Claude

POSTED BY: Claude Mante

Have you tried the following:

Commonest[Flatten[Map[DayRound, Map[#["Dates"] & , ret], {2}]]]

Also, I would redefine how you calculate 6 months from a given date (for example, Today)

ret = FinancialData[#, "Return", {DatePlus[{-6, "Month"}], Date[]}, 
    "DateValue"] & /@ {"Thermo Fisher Scientific", "KLA-Tencor", 
   "Air Liquide", "Schneider Electric", "Silicon Motion", 
   "Compagnie de Saint-Gobain", "Groupe Fnac", "Pfizer", 
   "Schlumberger", "ArcelorMittal", "Valneva SE"}

And for logical testing of missing dates use the complement.

Map[Complement[ 
   Map[DayRound, 
    Select[DateRange[DatePlus[{-6, "Month"}], 
      Today], (BusinessDayQ[#] == True) &]], #] &, 
 Map[DayRound, Map[#["Dates"] & , ret], {2}]]

Good Luck Hans

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

Group Abstract Group Abstract