{"id":19838659,"url":"https://github.com/brayvid/efficient-portfolio","last_synced_at":"2026-05-11T13:01:43.742Z","repository":{"id":231398713,"uuid":"319056061","full_name":"brayvid/efficient-portfolio","owner":"brayvid","description":"The allocation algorithm in \"An Analytic Derivation of the Efficient Portfolio Frontier\" by Robert C. Merton, 1972.","archived":false,"fork":false,"pushed_at":"2024-06-16T22:24:31.000Z","size":1002,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-11T11:18:25.018Z","etag":null,"topics":["algorithm","asset-allocation","finance","investing","minimum-variance","optimization"],"latest_commit_sha":null,"homepage":"https://colab.research.google.com/github/brayvid/efficient-portfolio/blob/main/EfficientPortfolio.ipynb","language":"Jupyter Notebook","has_issues":false,"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/brayvid.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}},"created_at":"2020-12-06T14:44:23.000Z","updated_at":"2024-09-03T09:40:39.000Z","dependencies_parsed_at":"2024-06-16T23:27:01.170Z","dependency_job_id":"246b8309-be18-4c91-bb0a-e3309b79f1ca","html_url":"https://github.com/brayvid/efficient-portfolio","commit_stats":null,"previous_names":["brayvid/efficientportfolio","brayvid/efficient-portfolio"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brayvid%2Fefficient-portfolio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brayvid%2Fefficient-portfolio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brayvid%2Fefficient-portfolio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brayvid%2Fefficient-portfolio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brayvid","download_url":"https://codeload.github.com/brayvid/efficient-portfolio/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241209528,"owners_count":19927734,"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":["algorithm","asset-allocation","finance","investing","minimum-variance","optimization"],"created_at":"2024-11-12T12:18:34.834Z","updated_at":"2026-05-11T13:01:38.710Z","avatar_url":"https://github.com/brayvid.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Efficient Portfolio Construction\n\n\u003ca href=\"https://colab.research.google.com/github/brayvid/efficient-portfolio/blob/main/EfficientPortfolio.ipynb\" rel=\"Open in Colab\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\" /\u003e\u003c/a\u003e\n\n**This is not  advice to buy or sell any security.**\n\nThis is an implementation of Robert C. Merton's efficient portfolio algorithm from the paper [*An Analytic Derivation of the Efficient Portfolio Frontier*](http://www.stat.ucla.edu/~nchristo/statistics_c183_c283/analytic_derivation_frontier.pdf) (1972) in Google Colab.\n\nBuilding on the work of Harry Markowitz, Merton describes a way to assign weights to a list of securities to make a portfolio that has the lowest variance in returns for a given level of expected returns, based on historical returns data. Each weight may be positive or negative corresponding to long and short positions, or zero when no position should be taken. They will sum to 100%.\n\nThe notebook above finds such a portfolio using all S\u0026P 100 companies. You specify the level of expected returns at which to perform the allocation. If the entire S\u0026P 100 is used as input with data from 1/1/2011 to 12/31/2019, this is the resulting minimum-variance allocation at the 25% expected return level:\n\n| Long   |            | Less than 1% |            | Short  |            |\n|--------|------------|--------------|------------|--------|------------|\n| Symbol | Allocation | Symbol       | Allocation | Symbol | Allocation |\n| MRK    | 39.7%      | BKNG         | 0.85%      | COST   | -35.3%     |\n| AMT    | 37.8%      | TXN          | 0.52%      | AXP    | -19.6%     |\n| VZ     | 32.0%      | GOOGL        | 0.42%      | DIS    | -16.6%     |\n| MO     | 17.7%      | QCOM         | 0.04%      | CAT    | -13.9%     |\n| BRK-B  | 17.5%      | SLB          | 0.01%      | XOM    | -13.3%     |\n| DHR    | 17.2%      | PFE          | -0.53%     | COP    | -13.3%     |\n| MCD    | 17.0%      | LMT          | -0.85%     | IBM    | -12.2%     |\n| SBUX   | 14.5%      | AIG          | -0.91%     | PG     | -11.5%     |\n| BMY    | 14.5%      | BK           | -0.91%     | CL     | -11.1%     |\n| ALL    | 12.6%      | GE           | -0.98%     | PEP    | -10.6%     |\n| T      | 12.4%      |              |            | CSCO   | -10.5%     |\n| UNH    | 11.9%      |              |            | ACN    | -8.6%      |\n| AAPL   | 11.6%      |              |            | MET    | -8.0%      |\n| BA     | 10.7%      |              |            | MDT    | -7.2%      |\n| HD     | 8.7%       |              |            | MDLZ   | -7.2%      |\n| WBA    | 7.8%       |              |            | GD     | -7.2%      |\n| ORCL   | 7.6%       |              |            | WMT    | -6.6%      |\n| C      | 6.6%       |              |            | JPM    | -6.4%      |\n| BLK    | 6.5%       |              |            | LLY    | -5.8%      |\n| EMR    | 6.4%       |              |            | BIIB   | -5.0%      |\n| MA     | 6.0%       |              |            | NVDA   | -4.2%      |\n| KO     | 5.3%       |              |            | UNP    | -4.1%      |\n| JNJ    | 5.1%       |              |            | CHTR   | -3.9%      |\n| BAC    | 5.0%       |              |            | GM     | -3.5%      |\n| SO     | 4.6%       |              |            | MSFT   | -3.5%      |\n| EXC    | 4.3%       |              |            | TGT    | -3.4%      |\n| COF    | 4.0%       |              |            | TMO    | -3.3%      |\n| ABT    | 3.9%       |              |            | GS     | -3.1%      |\n| UPS    | 3.8%       |              |            | USB    | -3.0%      |\n| V      | 3.8%       |              |            | MMM    | -2.9%      |\n| DUK    | 3.8%       |              |            | AMZN   | -2.7%      |\n| LOW    | 2.9%       |              |            | NKE    | -2.5%      |\n| DD     | 2.8%       |              |            | SPG    | -2.5%      |\n| FDX    | 2.7%       |              |            | F      | -2.4%      |\n| NFLX   | 2.4%       |              |            | GILD   | -2.4%      |\n| RTX    | 2.2%       |              |            | CVS    | -2.1%      |\n| AMGN   | 2.2%       |              |            | NEE    | -1.9%      |\n| CVX    | 2.1%       |              |            | HON    | -1.7%      |\n| CRM    | 2.0%       |              |            | INTC   | -1.2%      |\n| GOOG   | 1.7%       |              |            | CMCSA  | -1.0%      |\n| MS     | 1.6%       |              |            |        |            |\n| PM     | 1.4%       |              |            |        |            |\n| ADBE   | 1.3%       |              |            |        |            |\n| WFC    | 1.2%       |              |            |        |            |\n| OXY    | 1.1%       |              |            |        |            |\n| Long   | 390%       | Total        | 100%       | Short  | -290%      |\n\nIf $10,000 had been distributed according to the above table on January 1, 2011 and rebalanced monthly, the portfolio would have had the following returns profile 9 years later on January 1, 2020:\n\u003c/br\u003e\n\u003cimg src=\"example/portfolio_growth.png\" alt=\"growth\" width=\"100%\"/\u003e\n\u003c/br\u003e\nThe Merton-allocated portfolio had an annualized inflation-adjusted growth rate of 19.8%, compared to 14.1% for an equal-weight allocation:\n\u003c/br\u003e\n\u003cimg src=\"example/summary_table.png\" alt=\"summary\" width=\"100%\"/\u003e\n\u003c/br\u003e\nIt saw an alpha of over 20% and a beta of 0.07, handily surpassing the equal weight portfolio with 3.5% and 0.97 respectively:\n\u003c/br\u003e\n\u003cimg src=\"example/metrics_table.png\" alt=\"metrics\" width=\"100%\"/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrayvid%2Fefficient-portfolio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrayvid%2Fefficient-portfolio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrayvid%2Fefficient-portfolio/lists"}