{"id":13741156,"url":"https://github.com/joshuaulrich/xts","last_synced_at":"2025-05-14T12:07:15.180Z","repository":{"id":27854619,"uuid":"31345163","full_name":"joshuaulrich/xts","owner":"joshuaulrich","description":"Extensible time series class that provides uniform handling of many R time series classes by extending zoo.","archived":false,"fork":false,"pushed_at":"2025-03-13T17:23:20.000Z","size":10613,"stargazers_count":220,"open_issues_count":67,"forks_count":70,"subscribers_count":21,"default_branch":"main","last_synced_at":"2025-03-27T21:04:51.757Z","etag":null,"topics":["c","r","time-series"],"latest_commit_sha":null,"homepage":"http://joshuaulrich.github.io/xts/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joshuaulrich.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["joshuaulrich"],"tidelift":"cran/xts"}},"created_at":"2015-02-26T01:36:22.000Z","updated_at":"2025-03-25T14:04:31.000Z","dependencies_parsed_at":"2023-12-21T01:11:45.539Z","dependency_job_id":"14ae0667-71b7-4bbe-bd38-a575dc161bdb","html_url":"https://github.com/joshuaulrich/xts","commit_stats":{"total_commits":1380,"total_committers":27,"mean_commits":"51.111111111111114","dds":0.5065217391304349,"last_synced_commit":"ae39d2b644b0e18281b5606630cecf15ad93eaeb"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuaulrich%2Fxts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuaulrich%2Fxts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuaulrich%2Fxts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuaulrich%2Fxts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshuaulrich","download_url":"https://codeload.github.com/joshuaulrich/xts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247086019,"owners_count":20881159,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","r","time-series"],"created_at":"2024-08-03T04:00:56.114Z","updated_at":"2025-04-03T22:04:40.151Z","avatar_url":"https://github.com/joshuaulrich.png","language":"R","funding_links":["https://github.com/sponsors/joshuaulrich","https://tidelift.com/funding/github/cran/xts","https://tidelift.com/?utm_source=cran-xts\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo"],"categories":["R","Table of Contents"],"sub_categories":["Numerical Libraries \u0026 Data Structures","数值库与数据结构","Time series"],"readme":"### About\n\nxts is an [R](https://www.r-project.org) package that provides an extension of\nthe [zoo](https://CRAN.R-project.org/package=zoo) class.  zoo's strength comes\nfrom its simplicity of use (it's very similar to base R functions), and its\noverall flexibility (you can use *anything* as an index).  The xts extension\nwas motivated by the ability to improve performance by imposing reasonable\nconstraints, while providing a truly time-based structure.\n\n### xts for enterprise\n\nAvailable as part of the Tidelift Subscription.\n\nThe maintainers of `xts` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/?utm_source=cran-xts\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo)\n\n### Supporting xts development\n\nIf you are interested in supporting the ongoing development and maintenance of xts, please consider [becoming a sponsor](https://github.com/sponsors/joshuaulrich).\n\n### Installation\n\nThe current release is available on [CRAN](https://CRAN.R-project.org/package=xts),\nwhich you can install via:\n\n```r\ninstall.packages(\"xts\")\n```\n\nTo install the development version, you need to clone the repository and build\nfrom source, or run one of:\n\n```r\n# lightweight\nremotes::install_github(\"joshuaulrich/xts\")\n# or\ndevtools::install_github(\"joshuaulrich/xts\")\n```\n\nYou will need tools to compile C, C++, and Fortran code. See the relevant\nappendix in the [R Installation and Administration manual](https://cran.r-project.org/doc/manuals/r-release/R-admin.html)\nfor your operating system:\n\n- [Windows](https://cran.r-project.org/doc/manuals/r-release/R-admin.html#The-Windows-toolset)\n- [MacOS](https://cran.r-project.org/doc/manuals/r-release/R-admin.html#macOS) (the [R for Mac OS X Developer's Page](https://mac.r-project.org/) might also be helpful)\n- [Unix-alike](https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Essential-and-useful-other-programs-under-a-Unix_002dalike)\n\n### Getting Started\n\nYou can create xts objects using `xts()` and `as.xts()`.\n\nNote that `as.xts()` currently expects the date/times to be in the row names\nfor matrix and data.frame objects, or in the names for vector. You can also\nuse the `dateFormat` argument to control whether the names should be converted\nto `Date` or `POSIXct`. See `help(as.xts.methods)` for details.\n\n```r\nn \u003c- 10\nseries \u003c- rnorm(n)\n\n# POSIXct (date/time) index\ndatetimes \u003c- seq(as.POSIXct(\"2017-03-27\"), length.out = n, by = \"days\")\nlibrary(xts)\nx \u003c- xts(series, datetimes)\n```\n\nIn addition to the usual ways you can subset matrix and zoo objects, you can\nalso subset xts objects using character strings that adhere to the\n[ISO-8601 standard](https://en.wikipedia.org/wiki/ISO_8601), which is the\ninternationally recognized and accepted way to represent dates and times.\nUsing the data from the prior code block, here are some examples:\n\n```r\n# March, 2017\nx[\"2017-03\"]\n#                   [,1]\n# 2017-03-27  0.25155453\n# 2017-03-28 -0.09379529\n# 2017-03-29  0.44600926\n# 2017-03-30  0.18095782\n# 2017-03-31 -1.45539421\n\n# March 30th through April 2nd\nx[\"2017-03-30/2017-04-02\"]\n#                  [,1]\n# 2017-03-30  0.1809578\n# 2017-03-31 -1.4553942\n# 2017-04-01 -0.4012951\n# 2017-04-02 -0.5331497\n\n# Beginning of the series to April 1st\nx[\"/2017-04-01\"]\n#                   [,1]\n# 2017-03-27  0.25155453\n# 2017-03-28 -0.09379529\n# 2017-03-29  0.44600926\n# 2017-03-30  0.18095782\n# 2017-03-31 -1.45539421\n# 2017-04-01 -0.40129513\n```\n\nYou can aggregate a univariate series, or open-high-low-close (OHLC) data, into\na lower frequency OHLC series with the `to.period()` function. There are also\nconvenience functions for some frequencies (e.g. `to.minutes()`, `to.daily()`,\n`to.yearly()`, etc).\n\n```r\ndata(sample_matrix)\nx \u003c- as.xts(sample_matrix)\nto.period(x, \"months\")\n#              x.Open   x.High    x.Low  x.Close\n# 2007-01-31 50.03978 50.77336 49.76308 50.22578\n# 2007-02-28 50.22448 51.32342 50.19101 50.77091\n# 2007-03-31 50.81620 50.81620 48.23648 48.97490\n# 2007-04-30 48.94407 50.33781 48.80962 49.33974\n# 2007-05-31 49.34572 49.69097 47.51796 47.73780\n# 2007-06-30 47.74432 47.94127 47.09144 47.76719\n\nto.monthly(x)  # result has a 'yearmon' index\n#           x.Open   x.High    x.Low  x.Close\n# Jan 2007 50.03978 50.77336 49.76308 50.22578\n# Feb 2007 50.22448 51.32342 50.19101 50.77091\n# Mar 2007 50.81620 50.81620 48.23648 48.97490\n# Apr 2007 48.94407 50.33781 48.80962 49.33974\n# May 2007 49.34572 49.69097 47.51796 47.73780\n# Jun 2007 47.74432 47.94127 47.09144 47.76719\n```\n\nThe `period.apply()` function allows you apply a custom function to non-\noverlapping intervals. You specify the intervals using a vector similar to the\noutput of `endpoints()`. Like `to.period()` there are convenience functions,\nlike `apply.daily()`, `apply.quarterly()`, etc.\n\n```r\n# Average monthly value for each column\nperiod.apply(x, endpoints(x, \"months\"), colMeans)\n#                Open     High      Low    Close\n# 2007-01-31 50.21140 50.31528 50.12072 50.22791\n# 2007-02-28 50.78427 50.88091 50.69639 50.79533\n# 2007-03-31 49.53185 49.61232 49.40435 49.48246\n# 2007-04-30 49.62687 49.71287 49.53189 49.62978\n# 2007-05-31 48.31942 48.41694 48.18960 48.26699\n# 2007-06-30 47.47717 47.57592 47.38255 47.46899\n\n#                Open     High      Low    Close\n# 2007-01-31 50.21140 50.31528 50.12072 50.22791\n# 2007-02-28 50.78427 50.88091 50.69639 50.79533\n# 2007-03-31 49.53185 49.61232 49.40435 49.48246\n# 2007-04-30 49.62687 49.71287 49.53189 49.62978\n# 2007-05-31 48.31942 48.41694 48.18960 48.26699\n# 2007-06-30 47.47717 47.57592 47.38255 47.46899\n```\n\n###### Have a question?\n\nAsk your question on [Stack Overflow](https://stackoverflow.com/questions/tagged/r)\nor the [R-SIG-Finance](https://stat.ethz.ch/mailman/listinfo/r-sig-finance)\nmailing list (you must subscribe to post).\n\n###### Want hands-on experience?\n\n- [DataCamp course on importing and managing financial data](https://www.datacamp.com/courses/importing-and-managing-financial-data-in-r)\n- [DataCamp course on manipulating time series with xts \u0026 zoo](https://www.datacamp.com/courses/manipulating-time-series-data-in-r)\n\n### Contributing\n\nPlease see the [Contributing Guide](https://github.com/joshuaulrich/xts/wiki/Contributing-Guide).\n\n### See Also\n\n- [quantmod](https://CRAN.R-project.org/package=quantmod): quantitative financial modeling framework\n- [TTR](https://CRAN.R-project.org/package=TTR): functions for technical trading\nrules\n- [zoo](https://CRAN.R-project.org/package=zoo): class for regular and irregular time series\n\n### Author\n\nJeffrey Ryan, [Joshua Ulrich](https://about.me/joshuaulrich)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshuaulrich%2Fxts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshuaulrich%2Fxts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshuaulrich%2Fxts/lists"}