2
$\begingroup$

apologies in advance if this is obvious, but I'm very new to mathematica and couldn't find the answer in the documentation nor in the forum here...

I've got a 2 year time series ts with daily percentage returns of a particular stock and want to create a table showing monthly total returns.

MonthlyAvReturns = Table[Mean[TimeSeriesWindow[ts, {{y, m, 1}, {y, m, 31}}]],{y,2015, 2016}, {m, 1, 12}]

The above gives me the average value of the data for each month. To get monthly returns, I'd need to multiply those values instead of adding them with Total[].

I'm sure there is a better way to do this than doing this manually via

JanReturns = TimeSeriesWindow[ts,{{2015, 1, 1}, {2015, 1, 31}}];
Times@@(JanReturns["Values"]+1)

Any pointers would be extremely welcome. Thanks in advance!

Also - this is a custom return series, so nothing that can be downloaded through FinancialData["ticker","CumulativeFractionalChange","dates"].

$\endgroup$
  • $\begingroup$ What's wrong with replacing Mean with your Times@@(1+Values[...])? $\endgroup$ – swish Oct 13 '17 at 18:23
  • $\begingroup$ If I do that, I get the error message: "Times@@" cannot be followed by "[TimeSeriesWindow[ts,{{y,m,1},{y,m,31}}]]". $\endgroup$ – flux Oct 16 '17 at 7:38

Your Answer

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

Browse other questions tagged or ask your own question.