{"id":19129983,"url":"https://github.com/mathworks/managing_asset_allocation_with_experiment_manager","last_synced_at":"2025-07-31T05:07:33.615Z","repository":{"id":194858242,"uuid":"691732698","full_name":"mathworks/managing_asset_allocation_with_experiment_manager","owner":"mathworks","description":"​​MATLAB example on how to utilize the Experiment Manager app to fine tune portfolio optimization parameters​ ","archived":false,"fork":false,"pushed_at":"2024-02-16T20:47:12.000Z","size":667,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-22T16:56:52.796Z","etag":null,"topics":["asset-management","experiment-management","matlab","matlab-finance","portfolio-optimization"],"latest_commit_sha":null,"homepage":"","language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathworks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-09-14T19:16:08.000Z","updated_at":"2024-08-29T08:52:19.000Z","dependencies_parsed_at":"2023-12-01T22:38:23.080Z","dependency_job_id":null,"html_url":"https://github.com/mathworks/managing_asset_allocation_with_experiment_manager","commit_stats":null,"previous_names":["mathworks/managing_asset_allocation_with_experiment_manager"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mathworks/managing_asset_allocation_with_experiment_manager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks%2Fmanaging_asset_allocation_with_experiment_manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks%2Fmanaging_asset_allocation_with_experiment_manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks%2Fmanaging_asset_allocation_with_experiment_manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks%2Fmanaging_asset_allocation_with_experiment_manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathworks","download_url":"https://codeload.github.com/mathworks/managing_asset_allocation_with_experiment_manager/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks%2Fmanaging_asset_allocation_with_experiment_manager/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267988945,"owners_count":24177016,"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","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"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":["asset-management","experiment-management","matlab","matlab-finance","portfolio-optimization"],"created_at":"2024-11-09T06:09:12.723Z","updated_at":"2025-07-31T05:07:33.595Z","avatar_url":"https://github.com/mathworks.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Managing Asset Allocation with the Experiment Manager\r\n\r\n![intro](images/intro.png)\r\n\r\n## Overview\r\nFor the workflow of portfolio optimization, it can be challenging to meet the portfolio optimization criteria when several objectives exist. Using the Experiment Manager, a portfolio manager or quant can easily assess the experiments and outcomes and select the best scenario that meets their criteria.\r\n\r\nThe Experiment Manager is a MATLAB® app that allows the user to sweep through several combinations\r\nof hyperparameters, or scenarios, for deep learning experiments. It has since been expanded to \r\naccomodate what are known as custom training experiments, which allow the user to execute experiments\r\nthat do not include deep learning functionality. For a custom training experiment, the user also\r\nhas the ability to specify outputs that the app monitors with each iteration of the experiment. This\r\ndemonstration is intended to give you a starting point while developing your own workflow.\r\n\r\nOften times, users will try to develop their own program to execute experiments and store the results.\r\nAnother approach might be to run each experiment individually and manually record the results and\r\ncorresponding parameters into a spreadsheet or notepad. However, approaches such as these can easily\r\nlead to confusion about which tests were run, how scenarios were defined and experiments/results\r\nwere recorded, and other concerns. The Experiment Manager provides a user interface to easily\r\nset up and execute experiments, while recording and reporting the corresponding results in one place.\r\n\r\nIn this example, a custom training experiment was developed to fine tune portfolio optimization parameters.\r\nTwo hyperparameters are varied, which are the penalty parameter, or lambda, and the objective function, or\r\nTechnique. Three outputs are then monitored to assess the performance of each iteration, including Returns,\r\nVolatility, and Turnover. Upon running the example, the app outputs the table shown below.\r\n\r\n![table](images/table.png)\r\n\r\n## Getting Started\r\nDownload or clone this repository to your machine and open it in MATLAB.\r\n\r\n## Setup\r\nTo run:\r\n1. Open CustomPortfolio_Expr.prj\r\n2. Open the Experiment Manager app by typing experimentManager into the Command Window\r\n3. If prompted to open the current project by the Experiment Manager app, select Yes.\r\n4. Double click on Asset_Allocation under the Experiment Browser\r\n5. Press the \"Run\" button on the top tool strip\r\n\r\nRequires:\r\n* Deep Learning Toolbox™ if using MATLAB 2020a, 2020b, 2021a, 2021b, 2022a, 2022b, 2023a\r\n\t* Note: Deep Learning Toolbox is not required if using MATLAB 2023b or later versions\r\n* Financial Toolbox™\r\n\r\n## Portfolio Optimization and Backtesting\r\nFundamental knowledge of portfolio theory and backtesting is assumed. If you need a refresher,\r\nplease see the following links for more information:\r\n\r\n[Portfolio theory](https://corporatefinanceinstitute.com/resources/capital-markets/modern-portfolio-theory-mpt/)\r\n[Portfolio backtesting](https://www.refinitiv.com/en/asset-management-solutions/portfolio-management/backtest-your-portfolio-performance)\r\n\r\nThis demo specifically uses MATLAB's Portfolio object in conjunction with user-defined custom objectives.\r\n\r\nIn this example, we specifically investigate equally weighted, most-diversified portfolio, and equal\r\nrisk contribution objectives, each with a penalty parameter. More information about each of the objective\r\nfunctions can be found at [this link](https://www.mathworks.com/help/finance/diversify-portfolio-using-custom-objective-function.html#DiversiPortfoliosUseEstimateCustomObjectivePortfolioExample-3)\r\n\r\n## Experiment Manager for Asset Allocation\r\nPortfolio optimization can be used in conjunction with the Experiment Manager by first defining a training function and\r\nhyperparameters to the app. The two hyperparameters for this example, lambda (the penalty parameter) and Technique\r\n(the objective function), are specified under the \"Hyperparameters\" section in the image below.\r\n\r\n![exprmgr](images/exprmgr.png)\r\n\r\nAdditionally, the user must specify a training function for a custom experiment like this one under the \"Training Function\" section.\r\nThis function serves as the blueprint for setting up the experiments. A snippet of the training function for this example is shown\r\nbelow.\r\n\r\n![setup](images/setup.png)\r\n\r\nThe training function in this demonstration, in addition to loading the portfolio data and initializing the portfolio\r\nobject, defines the custom metrics that we want the app to record while executing each experiment in line 2. The user\r\nspecifies the hyperparameters, and ergo scenarios, through the \"params\" variable. This variable is then called and \r\nused to define scenarios in the image below.\r\n\r\n![fnx](images/fnx.png)\r\n\r\nThe hyperparameters in the function are specified in lines 11 and line 18.\r\n\r\n## Case Study\r\nThe data used in this study was simulated using geometric Brownian motion and consists of 39 simulated stocks. This\r\nstudy cycles through the three diversification techniques described above, in addition to four different penalty\r\nparameter values. The Experiment Manager app drawsup the results in a table, which can be exported directly to the\r\nMATLAB workspace. The user can then generate plots and draw inferences on the effects of the various permutations\r\nof the metrics upon the following outputted parameters: returns, volatility, and turnover.\r\n\r\n## Results\r\nThree bar plots below were created to compare the results of each diversification strategy and penalty parameter combination. \r\n\r\nReturns vs. Penalty Parameter\r\n\r\n![returns](images/returns.png)\r\n\r\nVolatility vs. Penalty Parameter\r\n\r\n![volatility](images/volatility.png)\r\n\r\nTurnover vs. Penalty Parameter\r\n\r\n![turnover](images/turnover.png)\r\n\r\nWe can see that each monitored parameter responded differently, dramatically so in some instances, when the penalty\r\nparameter was changed. When evaluating the first plot, we recognize that the returns increase with an increase in the\r\npenalty parameter. Volatility also increases with the penalty parameter value, while the Turnover is overall reduced.\r\nThe most diversified portfolio objective technique is an interesting scenario, where returns demonstrate a dramatic\r\nincrease with the penalty parameter without reducing the turnover as dramatically as the other two objectives under\r\ninvestigation.\r\n\r\nThe question of which Technique and lambda combination to select for your portfolio can vary in this instance, depending\r\non how much risk the PM is willing to take on for the returns. Personally, I would steer clear of the most diversified\r\nportfolio, as the turnover and volatility are both high with the penalty parameter. If the PM is willing to take on\r\nslightly more risk for higher returns, the equal risk contribution objective is recommended when the penalty parameters is\r\neither 3e-6 or 0.01. Conversely, if the PM is comfortable with slightly lower returns in exchange for reduced risk, the\r\nequally weighted scheme when the penalty parameter is 3e-6 or 0.01 is recommended.\r\n\r\n## Conclusion\r\nThe goal of this example was to show:\r\n* What the Experiment Manager App is\r\n* How the App can be applied to explore the impact of portfolio optimization parameters\r\n* Build a foundation for finance professionals to explore their own portfolio or other financial experiments\r\n\r\nFeel free to contact me if you are interested in updates.\r\n\r\n## License\r\nThe license is available in the License.txt file in this GitHub repository.\r\n\r\n## Contact\r\nSara Galante at sgalante@mathworks.com\r\n\r\nCopyright 2024 The MathWorks, Inc.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathworks%2Fmanaging_asset_allocation_with_experiment_manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathworks%2Fmanaging_asset_allocation_with_experiment_manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathworks%2Fmanaging_asset_allocation_with_experiment_manager/lists"}