4
$\begingroup$

I have downloaded some data:

mydata = FinancialData["SP500", {{2014, 10, 23}, {2016, 10, 22}}]

How can I set the values between two specified dates to zero?

Currently I only found how to do it for one date at the time:

TimeSeriesInsert[mydata, {{2014, 10, 23}, 0}]
$\endgroup$

1 Answer 1

2
$\begingroup$

Create a time series using the dates from the existing time series paired with the new values (zero in your case).

It seems to be important that the dates be pulled out of the original series. It didn't seem to work right when I just created a date range from scratch.

ts0 = Thread[{TimeSeriesWindow[mydata, {{2014, 11, 7}, {2014, 11, 21}}]["Dates"], 0}]

enter image description here

Insert into existing time series:

mydata2 = TimeSeriesInsert[mydata, ts0]

Confirm:

DateListPlot@TimeSeriesWindow[{mydata, mydata2}, {{2014, 11, 1}, {2014, 12, 1}}]

enter image description here
Notice original time series is not changed by TimneSeriesInsert.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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