0
$\begingroup$

Compute Aggregated Statistics for a Time Series

The article linked to above provides a sample of aggregating time series data.

ts = FinancialData["NYSE:GS", "Price", {{2012, 1, 1}, {2013, 1, 1}}];
total = TimeSeriesAggregate[data, "Quarter", Total];

Interrogating total returns the following absolute time format for the aggregated date field.

{3538468800, 6738.89}

Is it possible to reformat the absolute time back into a mmm-yy format, which is representative of the month or quarter that the date relates to?

$\endgroup$
2
$\begingroup$
ts = FinancialData["NYSE:GS", "Price", {{2012, 1, 1}, {2013, 1, 1}}];

total = TimeSeriesAggregate[ts, "Quarter", Total]; 

Note that you need ts rather than data in definition of total

(total2 = 
   MapAt[DateString[#, {"MonthNameShort", "-", "YearShort"}] &@*
     DateList, total, {All, 1}]) // Grid

enter image description here

| improve this answer | |
$\endgroup$
1
$\begingroup$

You can reformat the absolute very easily and you have almost any format that you want. Look at DateString for the large range of date and time element formats available.

Here is a function that will handle your data.

toDateString[{arg1_, arg2_}, fmt_] := {DateString[arg1, fmt], arg2}

Examples

With[{
    item = {3538468800, 6738.89},
    fmt = {"MonthNameShort", "-", "YearShort"}}, 
  toDateString[item, fmt]]

{"Feb-12", 6738.89}

ts = FinancialData["NYSE:GS", "Price", {{2012, 1, 1}, {2013, 1, 1}}];
total = TimeSeriesAggregate[ts, "Quarter", Total];
With[{fmt = {"QuarterNameShort", "-", "Year"}},
  toDateString[#, fmt] & /@ total]

{{"Q1-2012", 6738.89}, {"Q2-2012", 6141.51}, {"Q3-2012", 6392.01}, {"Q4-2012", 6893.01}}

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.