{"id":13700128,"url":"https://github.com/dppalomar/sparseIndexTracking","last_synced_at":"2025-05-04T18:34:27.912Z","repository":{"id":38325307,"uuid":"112272512","full_name":"dppalomar/sparseIndexTracking","owner":"dppalomar","description":"Design of Portfolio of Stocks to Track an Index","archived":false,"fork":false,"pushed_at":"2023-05-28T05:24:19.000Z","size":74897,"stargazers_count":52,"open_issues_count":3,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T11:18:55.849Z","etag":null,"topics":["financial-markets","index","portfolio","tracking"],"latest_commit_sha":null,"homepage":"https://CRAN.R-project.org/package=sparseIndexTracking","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dppalomar.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2017-11-28T02:01:44.000Z","updated_at":"2024-12-24T20:25:00.000Z","dependencies_parsed_at":"2024-01-25T05:09:16.720Z","dependency_job_id":"9f8c7d6b-e5ee-4134-a2d5-28fcf2e164c4","html_url":"https://github.com/dppalomar/sparseIndexTracking","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dppalomar%2FsparseIndexTracking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dppalomar%2FsparseIndexTracking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dppalomar%2FsparseIndexTracking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dppalomar%2FsparseIndexTracking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dppalomar","download_url":"https://codeload.github.com/dppalomar/sparseIndexTracking/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252383003,"owners_count":21739257,"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":["financial-markets","index","portfolio","tracking"],"created_at":"2024-08-02T20:00:48.868Z","updated_at":"2025-05-04T18:34:22.890Z","avatar_url":"https://github.com/dppalomar.png","language":"HTML","funding_links":[],"categories":["R"],"sub_categories":["Financial Instruments and Pricing"],"readme":"---\noutput:\n  md_document:\n    variant: markdown_github\n  html_document:\n    variant: markdown_github\n    keep_md: true\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo = FALSE}\nlibrary(knitr)\nopts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  fig.align = \"center\",\n  fig.retina = 2,\n  out.width = \"75%\",\n  dpi = 96\n)\nknit_hooks$set(pngquant = hook_pngquant)\n```\n\n# sparseIndexTracking\n\n[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/sparseIndexTracking)](https://CRAN.R-project.org/package=sparseIndexTracking)\n[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/sparseIndexTracking)](https://CRAN.R-project.org/package=sparseIndexTracking)\n![CRAN Downloads Total](https://cranlogs.r-pkg.org/badges/grand-total/sparseIndexTracking?color=brightgreen)\n\nComputation of sparse portfolios for financial index tracking, i.e., joint \nselection of a subset of the assets that compose the index and computation \nof their relative weights (capital allocation). The level of sparsity of the \nportfolios, i.e., the number of selected assets, is controlled through a \nregularization parameter. Different tracking measures are available, namely, \nthe empirical tracking error (ETE), downside risk (DR), Huber empirical \ntracking error (HETE), and Huber downside risk (HDR). See vignette for a \ndetailed documentation and comparison, with several illustrative examples.\n\nThe package is based on the paper:\n\nK. Benidis, Y. Feng, and D. P. Palomar, \"Sparse Portfolios for High-Dimensional \nFinancial Index Tracking,\" _IEEE Trans. on Signal Processing_, vol. 66, no. 1, \npp. 155-170, Jan. 2018. (\u003chttps://doi.org/10.1109/TSP.2017.2762286\u003e)\n\n\nThe latest stable version of **sparseIndexTracking** is available at \nhttps://CRAN.R-project.org/package=sparseIndexTracking.\n\nThe latest development version of **sparseIndexTracking** is available at \nhttps://github.com/dppalomar/sparseIndexTracking.\n\n\n## Installation\nTo install the latest stable version of **sparseIndexTracking** from CRAN, run the following commands in R:\n```{r, eval = FALSE}\ninstall.packages(\"sparseIndexTracking\")\n```\n\nTo install the development version of **sparseIndexTracking** from GitHub, run the following commands in R:\n```{r, eval = FALSE}\ninstall.packages(\"devtools\")\ndevtools::install_github(\"dppalomar/sparseIndexTracking\")\n```\n\nTo get help:\n```{r, eval = FALSE}\nlibrary(sparseIndexTracking)\nhelp(package = \"sparseIndexTracking\")\npackage?sparseIndexTracking\n?spIndexTrack\n```\n\nPlease cite **sparseIndexTracking** in publications:\n```{r, eval = FALSE}\ncitation(\"sparseIndexTracking\")\n```\n\n\n## Documentation\nFor more detailed information, please check the vignette: \n[CRAN vignette](https://CRAN.R-project.org/package=sparseIndexTracking/vignettes/SparseIndexTracking.html) and\n[GitHub vignette](https://raw.githack.com/dppalomar/sparseIndexTracking/master/vignettes/SparseIndexTracking.html).\n\n\n## Usage of `spIndexTrack()`\nWe start by loading the package and real data of the index S\u0026P 500 and its underlying assets:\n```{r, message = FALSE}\nlibrary(sparseIndexTracking)\nlibrary(xts)\ndata(INDEX_2010)\n```\nThe data `INDEX_2010` contains a list with two xts objects:\n\n\u003e 1. `X`: A $T\\times N$ xts with the daily linear returns of the $N$ assets that were in the index during the year   2010 (total $T$ trading days)\n  2. `SP500`: A $T\\times 1$ xts with the daily linear returns of the index S\\\u0026P 500 during the same period.\n\nNote that we use xts objects just for illustration purposes. The function `spIndexTracking()` can also be invoked passing simple data arrays or dataframes.\n\nBased on the above quantities we create a training window, which we will use to create our portfolios, and a testing window, which will be used to assess the performance of the designed portfolios. For simplicity, here we consider the first six (trading) months of the dataset (~126 days) as the training window, and the subsequent six months as the testing window:\n```{r}\nX_train \u003c- INDEX_2010$X[1:126]\nX_test \u003c- INDEX_2010$X[127:252]\nr_train \u003c- INDEX_2010$SP500[1:126]\nr_test \u003c- INDEX_2010$SP500[127:252]\n```\n\nNow, we use the four modes (four available tracking errors) of the `spIndexTracking()` algorithm to design our portfolios:\n```{r, cache = TRUE}\n# ETE\nw_ete \u003c- spIndexTrack(X_train, r_train, lambda = 1e-7, u = 0.5, measure = 'ete')\ncat('Number of assets used:', sum(w_ete \u003e 1e-6))\n\n# DR\nw_dr \u003c- spIndexTrack(X_train, r_train, lambda = 2e-8, u = 0.5, measure = 'dr')\ncat('Number of assets used:', sum(w_dr \u003e 1e-6))\n\n# HETE\nw_hete \u003c- spIndexTrack(X_train, r_train, lambda = 8e-8, u = 0.5, measure = 'hete', hub = 0.05)\ncat('Number of assets used:', sum(w_hete \u003e 1e-6))\n\n# HDR\nw_hdr \u003c- spIndexTrack(X_train, r_train, lambda = 2e-8, u = 0.5, measure = 'hdr', hub = 0.05)\ncat('Number of assets used:', sum(w_hdr \u003e 1e-6))\n```\n\nFinally, we plot the actual value of the index in the testing window in comparison with the values of the designed portfolios:\n```{r, pngquant = \"--speed=1\"}\nplot(cbind(\"PortfolioETE\" = cumprod(1 + X_test %*% w_ete), cumprod(1 + r_test)), \n     legend.loc = \"topleft\", main = \"Cumulative P\u0026L\")\nplot(cbind(\"PortfolioDR\" = cumprod(1 + X_test %*% w_dr), cumprod(1 + r_test)),\n     legend.loc = \"topleft\", main = \"Cumulative P\u0026L\")\nplot(cbind(\"PortfolioHETE\" = cumprod(1 + X_test %*% w_hete), cumprod(1 + r_test)),\n     legend.loc = \"topleft\", main = \"Cumulative P\u0026L\")\nplot(cbind(\"PortfolioHDR\" = cumprod(1 + X_test %*% w_hdr), cumprod(1 + r_test)),\n     legend.loc = \"topleft\", main = \"Cumulative P\u0026L\")\n```\n\n\n\n## Links\nPackage: [CRAN](https://CRAN.R-project.org/package=sparseIndexTracking) and [GitHub](https://github.com/dppalomar/sparseIndexTracking).\n\nREADME file: [CRAN-readme](https://CRAN.R-project.org/package=sparseIndexTracking/readme/README.html) and [GitHub-readme](https://github.com/dppalomar/sparseIndexTracking/blob/master/README.md).\n\nVignette: [CRAN-html-vignette](https://CRAN.R-project.org/package=sparseIndexTracking/vignettes/SparseIndexTracking.html),\n[CRAN-pdf-vignette](https://CRAN.R-project.org/package=sparseIndexTracking/vignettes/SparseIndexTracking-pdf.pdf),\n[GitHub-html-vignette](https://raw.githack.com/dppalomar/sparseIndexTracking/master/vignettes/SparseIndexTracking.html), and\n[GitHub-pdf-vignette](https://docs.google.com/viewer?url=https://github.com/dppalomar/sparseIndexTracking/raw/master/vignettes/SparseIndexTracking-pdf.pdf).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdppalomar%2FsparseIndexTracking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdppalomar%2FsparseIndexTracking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdppalomar%2FsparseIndexTracking/lists"}