Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1008995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:51:29+00:00 2026-05-16T08:51:29+00:00

I am looking for a standardized method for arranging data in relative time. Applications

  • 0

I am looking for a standardized method for arranging data in relative time. Applications include accounting data such as FY1,FY2,etc… and economic data such as the term structure of interest rates using the 1 year, 2 year, 3 year, etc…

I would like to be able to compare a set of time series data that is current and several historic time series sets that represent similar situations or historic norms. I was looking at xts but it looks like I need to use an absolute time reference.

I would eventually like to use Quantmod’s charting functions or graphs with equivalent capability to visualize the data. Since chartSeries requires a time series object, does anyone know how to do this? Even a point in the right direction would be helpful. Thanks.

require(quantmod)
symbols=c("DGS1","DGS2","DGS3","DGS5","DGS7","DGS10","DGS20")
getSymbols(symbols,src="FRED")
one.h=mean(na.omit(DGS1));two.h=mean(na.omit(DGS2));three.h=mean(na.omit(DGS3));five.h=mean(na.omit(DGS5));seven.h=mean(na.omit(DGS7));ten.h=mean(na.omit(DGS10));twenty.h=mean(na.omit(DGS20))
historic=c(one.h,two.h,three.h,five.h,seven.h,ten.h,twenty.h)
current=c(last(DGS1),last(DGS2),last(DGS3),last(DGS5),last(DGS7),last(DGS10),last(DGS20))
years=c(1,2,3,5,7,10,20)
plot(years,current,type="o",pch=20,ann=FALSE)
lines(years,historic,type="o",pch=20,col="red",lty=3)
title(main="Term Structure of Interest Rates",col.main="red", font.main=4)
title(xlab="Years to Maturity",ylab="Interest Rate",col.lab=rgb(0,0.5,0))
legend(3, c("Current","Historic"),cex=0.8,col=c("black","red"),pch=20)

Problem:
I would like to be able to select a time period such as September of 2007 and grab each daily yield curve to plot against the current yield curve. I’m sure I could use several pages of first and last functions but that would be more work than building it in Excel.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:51:29+00:00Added an answer on May 16, 2026 at 8:51 am

    xts requires an explicit time index but it’s based on zoo, which has no such requirement. So zoo will allow you to do something like this, as long as the index is ordered:

    > x <- zoo(rnorm(5),sprintf("FY%02d",1:5))
    > y <- zoo(rnorm(5),sprintf("FY%02d",1:5))
    > merge(x,y)
                   x           y
    FY01  0.32707886 -1.81414982
    FY02 -0.95177700  0.37772862
    FY03 -0.03052571 -1.13047719
    FY04  1.19139973  0.96962871
    FY05 -0.76484142 -0.08187144
    

    The downside is that you won’t be able to use those objects with quantmod::chartSeries because it requires an xts object. I doubt this answers your question, but I hope it gives you some ideas.

    EDIT to incorporate OP’s example:

    library(quantmod)
    symbols=c("DGS1","DGS2","DGS3","DGS5","DGS7","DGS10","DGS20")
    getSymbols(symbols,src="FRED")
    all <- na.omit(merge(DGS1,DGS2,DGS3,DGS5,DGS7,DGS10,DGS20))
    
    years <- c(1,2,3,5,7,10,20)
    # use xts indexing, since getSymbols returns xts
    histDate <- "2007-09-01/2007-09-10"
    # create zoo objects for non-time-based indexing
    hist <- zoo(t(all[histDate]), order.by=years)
    curr <- zoo(t(last(all)), order.by=years)
    
    currHist <- merge(curr,hist)
    plotCol <- rainbow(NCOL(currHist))
    plot(currHist, screens=1, col=plotCol, pch=20, type="o", ann=FALSE)
    title(main="Term Structure of Interest Rates",col.main="red", font.main=4)
    title(xlab="Years to Maturity",ylab="Interest Rate",col.lab=rgb(0,0.5,0))
    legend(15,1.5,colnames(currHist),cex=0.8,col=plotCol,pch=20)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when looking into metadata of images I was wondering how standardized this data actually
Looking for a control that allows to select one text value at a time
I was looking for a way to standardize my applications layout to boost my
I'm looking for a simple solution to replace my standardized junk way of validating
I'm looking at adding some basic search and filtering functionality in a generic/standardized way
Looking at some assembly code for x86_64 on my Mac, I see the following
Looking to do a bit of refactoring... Using NHibernate I have this query currently
Looking for a perl one-liner what will find all words with the next pattern:
Looking at the Slickgrid examples and using Google Chrome, I'm setting a breakpoint on
Looking at the Ehcahce implementation of net.sf.cache.JS107, I am trying to achieve the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.