{"id":34890969,"url":"https://github.com/amanda-ucc/market-tracker","last_synced_at":"2026-04-11T06:42:33.961Z","repository":{"id":329846512,"uuid":"1120793390","full_name":"amanda-ucc/market-tracker","owner":"amanda-ucc","description":"Automated portfolio creator that generates a portoflio which mimics a bench mark index by minimizing the tracking error.","archived":false,"fork":false,"pushed_at":"2025-12-22T02:37:36.000Z","size":379,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-11T06:42:23.552Z","etag":null,"topics":["beta","covariance","numpy","pandas","scipy","sharpe-ratio","tracking-error","variance","yfinance"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amanda-ucc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-22T00:23:33.000Z","updated_at":"2025-12-22T02:37:40.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/amanda-ucc/market-tracker","commit_stats":null,"previous_names":["amanda-ucc/market-tracker"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/amanda-ucc/market-tracker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amanda-ucc%2Fmarket-tracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amanda-ucc%2Fmarket-tracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amanda-ucc%2Fmarket-tracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amanda-ucc%2Fmarket-tracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amanda-ucc","download_url":"https://codeload.github.com/amanda-ucc/market-tracker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amanda-ucc%2Fmarket-tracker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31671629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T17:19:37.612Z","status":"online","status_checked_at":"2026-04-11T02:00:05.776Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["beta","covariance","numpy","pandas","scipy","sharpe-ratio","tracking-error","variance","yfinance"],"created_at":"2025-12-26T05:28:25.571Z","updated_at":"2026-04-11T06:42:33.951Z","avatar_url":"https://github.com/amanda-ucc.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Portfolio creation that tracks an index\n\n`market-tracker` creates a portfolio of 10 to 25 stocks, from a larger pool, that is intended to mimic a benchmark index.\u003cbr\u003e\n\nApproach taken is to use the previous years data and run a greedy algorithm that minimize the tracking error with respect to the porfolio weights using SciPy optimize. \n\nThe tracking error is measured as follows: \u003cbr\u003e\n\n$$\nTE = \\sqrt{\\mathrm{Var}(R_p - R_{\\text{index}})}\n$$\n\n$$\nTE = \\sqrt{\\frac{1}{T} \\sum_{t=1}^{T} (R_{p,t} - R_{\\text{index},t})^{2}}\n$$\n\n\nThe greedy algorithm functions as follows:\n\nTwo are included due to constrainsts so we start with those two and determine the next stock to add by minimizing a 3 stock portfolio with respect to the weights for each of the availble candidate stocks. The stock that makes the 3 stock portfolio have the lowest tracking error is included and then we add a 4th stock and so one which produces the lowest tracking error. The algorithm is greedy in that it assumes the path take to get to an optiminal k will be to determine optimal n in order.\n\n```python\n\ndef eval_best_among_candidates(\n    X_all: pd.DataFrame,\n    y: np.ndarray,\n    current_selected: list[str],\n    candidate_pool: list[str],\n    K: int,\n\n    verbose: bool = False,\n):\n    '''Evalutate the best stock from a candidate pool to add to the current selected list.'''\n\n    best_te = np.inf\n    best_ticker = None\n    best_weights = None\n\n    for ticker in candidate_pool:\n        tickers_sub = current_selected + [ticker]\n        X = X_all[tickers_sub].to_numpy()\n\n\n\n        ok, w_opt, te = minimize_te_best_weights(X, y, K, None, None) # find the optimal weights for \n\n        # if optimization failed skip this ticker\n        if not ok:\n            if verbose:\n                print(f\"  Skipping {ticker}: TE optimizer failed.\")\n            continue\n\n        # if it the best tracking error than keep it otherwise do not keep it    \n        if te \u003c best_te:\n            best_te = te\n            best_ticker = ticker\n            best_weights = w_opt\n\n        if verbose:\n            print(f\" Tested {ticker}: TE={te:.6f}\")\n\n    return best_ticker, best_weights, best_te\n\n```\n\nAfter each of the best 10, 11, 12 ... 25 stock portfolio is determined, it is just a matter of choosing which of those 15 is best.\n\n\nThis approach is determined to be better than calculating a portfolio beta closest to 1 as follows. \n\n$$\n\\min_{\\mathbf{w}} \n\\left| \n\\sum_{i=1}^{N} w_i \\beta_i - 1\n\\right|\n$$\n\n\nThe reasons which involve diversification, compand and industry risk are outlined in the following academic papers.\n\nAcademic References:\u003cbr\u003e\nhttps://www.sciencedirect.com/science/article/abs/pii/S1062976914000763\u003cbr\u003e\nhttps://link.springer.com/article/10.1007/s10957-022-02116-w\u003cbr\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famanda-ucc%2Fmarket-tracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famanda-ucc%2Fmarket-tracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famanda-ucc%2Fmarket-tracker/lists"}