[R] R-project: plot 2 zoo objects (price series) that have some date mis-matches

From: algotr8der <algotr8der_at_gmail.com>
Date: Sun, 03 Apr 2011 12:57:49 -0500 (CDT)


I have 2 zoo objects -

  1. Interest rate spread between 10-YR-US-Treasury and 2-YR-US-Treasury (object name = sprd)
  2. S&P 500 index (object name = spy)

> str(spy)

‘zoo’ series from 1976-06-01 to 2011-03-31   Data: num [1:8791] 99.8 100.2 100.1 99.2 98.6 ...   Index: Class 'Date' num [1:8791] 2343 2344 2345 2346 2349 ...

> str(sprd)

‘zoo’ series from 1976-06-01 to 2011-03-31   Data: num [1:9088] 0.68 0.71 0.7 0.77 0.79 0.79 0.82 0.86 0.83 0.83 ...   Index: Class 'Date' num [1:9088] 2343 2344 2345 2346 2349 ...

Since there are NA data points in object 'sprd' I created another object that omits "NA". The name of that object is 'sprdtmp'.

> str(sprdtmp)

‘zoo’ series from 1976-06-01 to 2011-03-31   Data: atomic [1:8704] 0.68 0.71 0.7 0.77 0.79 0.79 0.82 0.86 0.83 0.83 ...

I want to plot both time series on the same plot with time/date on the x-axis and the axis label quarterly (or monthly). One problem is that the sprdtmp and spy objects do not have the same number of data points as there are times when the equity markets are closed while the interest rate markets are open. For the most part the dates overlap. Would this matter if I try to plot both on the same plot? And how would I go about plotting these objects in one plot.

The second part of the plot requires that both are on different scales. I guess I could take a log of the s&p and plot that along with the rate spread. But it would be nice for future reference how I could plot 2 series in one plot with 2 difference scales.

I spent all night yesterday and this morning trying various options but I cant seem to get this to work. I have read through the ?plot, ?plot.zoo and ?axis documentation without any success. I would greatly appreciate if anyone can point me in the right direction. Thank you kindly.

--
View this message in context: http://r.789695.n4.nabble.com/R-project-plot-2-zoo-objects-price-series-that-have-some-date-mis-matches-tp3423899p3423899.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 03 Apr 2011 - 20:37:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 03 Apr 2011 - 22:50:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive