{"id":324638,"date":"2021-06-09T15:00:31","date_gmt":"2021-06-09T15:00:31","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=324638"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=324638","title":{"rendered":"\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python \u0438 PyPortfolioOpt"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h2>\u041f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0435\u043e\u0440\u0438\u044f \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430<\/h2>\n<p>\u041f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0435\u043e\u0440\u0438\u044f \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430(\u0434\u0430\u043b\u0435\u0435 \u041f\u0422\u041c) (Modern portfolio theory) \u2014 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u0430\u044f \u0413\u0430\u0440\u0440\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0438\u043a\u0430 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f, \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u043d\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0431\u043e\u0440 \u0430\u043a\u0442\u0438\u0432\u043e\u0432, \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0433\u043e \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c\/\u0440\u0438\u0441\u043a. \u0421\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u043c \u0432 1950-\u0445 \u0433\u043e\u0434\u0430\u0445 \u0438\u0434\u0435\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043e\u0441\u043d\u043e\u0432\u0443 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438 \u0431\u044b\u043b\u0438 \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0413\u0430\u0440\u0440\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u0438\u043c \u0434\u043e\u043a\u0442\u043e\u0440\u0441\u043a\u043e\u0439 \u0434\u0438\u0441\u0441\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0432 1950\u20141951 \u0433\u043e\u0434\u0430\u0445.<\/p>\n<p>\u0420\u043e\u0436\u0434\u0435\u043d\u0438\u0435\u043c \u0436\u0435 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432 \u00ab\u0424\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u043e\u043c \u0436\u0443\u0440\u043d\u0430\u043b\u0435\u00bb \u0432 1952 \u0433\u043e\u0434\u0443 \u0441\u0442\u0430\u0442\u044c\u044f \u00ab\u0412\u044b\u0431\u043e\u0440 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f\u00bb. \u0412 \u043d\u0435\u0439 \u043e\u043d \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0438 \u043f\u0440\u0438\u0432\u0451\u043b \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435\u0439 \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0441\u043b\u0443\u0433\u0430 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043b\u0430 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043d\u044f\u0442\u0438\u0439 \u00ab\u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c\u00bb \u0438 \u00ab\u0440\u0438\u0441\u043a\u00bb, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u044b\u0431\u043e\u0440\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043d\u0430 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a. \u041d\u0430\u0434\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u0433\u043e\u0434\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0435\u043e\u0440\u0438\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0432 RAND Corp., \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0438 \u043d\u0435\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 \u0414\u0436\u043e\u0440\u0434\u0436\u0435\u043c \u0414\u0430\u043d\u0446\u0438\u0433\u043e\u043c \u0438 \u0441\u0430\u043c \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0442\u0435\u043e\u0440\u0438\u044f, \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0445\u043e\u0440\u043e\u0448\u043e \u043b\u043e\u0436\u0438\u043b\u0430\u0441\u044c \u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0440\u0443\u0441\u043b\u043e.<\/p>\n<p>\u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0443\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0432\u043e\u0435\u0439 \u0442\u0435\u043e\u0440\u0438\u0438 \u0438 \u0432 1959 \u0433\u043e\u0434\u0443 \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u0443\u044e \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d\u043d\u0443\u044e \u0435\u0439 \u043c\u043e\u043d\u043e\u0433\u0440\u0430\u0444\u0438\u044e \u00ab\u0412\u044b\u0431\u043e\u0440 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f: \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0434\u0438\u0432\u0435\u0440\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u0439\u00bb.<\/p>\n<h2>\u041e\u0441\u043d\u043e\u0432\u0430 \u043c\u043e\u0434\u0435\u043b\u0438<\/h2>\n<p>1.&nbsp;<u>\u041e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f(Portfolio Expected Return)<\/u><\/p>\n<p>\u041e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0430\u043a\u0442\u0438\u0432\u043e\u0432, \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 \u043d\u0435\u0433\u043e. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0440\u0438\u0441\u043a \u0437\u0430 \u0441\u0447\u0435\u0442 \u0434\u0438\u0432\u0435\u0440\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0445\u043e\u0434 \u0438\u043d\u0432\u0435\u0441\u0442\u043e\u0440\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443\u0431\u044b\u0442\u043a\u0438 \u043f\u043e \u043e\u0434\u043d\u0438\u043c \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u044f\u043c \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043c\u043f\u0435\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u043e\u0445\u043e\u0434\u043e\u043c \u043f\u043e \u0434\u0440\u0443\u0433\u0438\u043c.<\/p>\n<p>\u041e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u0443\u044e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0443\u044e \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 \u043d\u0435\u0433\u043e \u0446\u0435\u043d\u043d\u044b\u0445 \u0431\u0443\u043c\u0430\u0433, \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u0443\u044e \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0438\u0445 \u0434\u043e\u043b\u0438 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"E(R_{p}) = \\sum_{i=1}^nw_{i}E(R_{i})\" alt=\"E(R_{p}) = \\sum_{i=1}^nw_{i}E(R_{i})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/980\/52f\/ccc\/98052fcccfec46d14813e1c6385f6568.svg\" width=\"162\" height=\"50\"><\/p>\n<p>2.<u>\u0414\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f (Portfolio Variance)<\/u><\/p>\n<p>\u0414\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0440\u0438\u0441\u043a\u0430 \u0438\u043b\u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u0441 \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435\u043c. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u044d\u0442\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0435\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u0438 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0435\u0439, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u0441 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0446\u0435\u043d\u043d\u044b\u0445 \u0431\u0443\u043c\u0430\u0433, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u043c \u0438\u043b\u0438 \u0447\u0430\u0441\u0442\u044c\u044e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u0430\u044f \u0446\u0435\u043d\u043d\u0430\u044f \u0431\u0443\u043c\u0430\u0433\u0430.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\sigma_{p}^{2} = \\sum_{i}^{}\\omega_{i}^{2}\\sigma_{i}^{2}+\\sum_{i}^{}\\sum_{j\\neq i}^{}\\omega_{i}^{}\\omega_{j}^{}\\sigma_{i}^{}\\sigma_{j}^{}\\rho_{ij}\" alt=\"\\sigma_{p}^{2} = \\sum_{i}^{}\\omega_{i}^{2}\\sigma_{i}^{2}+\\sum_{i}^{}\\sum_{j\\neq i}^{}\\omega_{i}^{}\\omega_{j}^{}\\sigma_{i}^{}\\sigma_{j}^{}\\rho_{ij}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/107\/06f\/234\/10706f2349a1469bb658d4afcd9ce77a.svg\" width=\"267\" height=\"48\"><\/p>\n<p>3.<u>\u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0428\u0430\u0440\u043f\u0430 (Sharpe Ratio)<\/u><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\frac{R_{p} - R_{f}}{\\sigma_{p}}\" alt=\"\\frac{R_{p} - R_{f}}{\\sigma_{p}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/df5\/b24\/908\/df5b24908249a881164d8e35e055648e.svg\" width=\"70\" height=\"45\"><\/p>\n<p>4.&nbsp;<u>\u042d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430 (The Efficient Frontier)<\/u><\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438 \u0440\u0438\u0441\u0443\u043d\u043e\u043a \u0438\u0437 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%93%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0_%D1%8D%D1%84%D1%84%D0%B5%D0%BA%D1%82%D0%B8%D0%B2%D0%BD%D0%BE%D1%81%D1%82%D0%B8\" rel=\"noopener noreferrer nofollow\">\u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438<\/a>:<\/p>\n<p>\u0413\u0440\u0430\u043d\u0438\u0446\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 (\u0430\u043d\u0433\u043b. Efficient frontier) \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430 \u2014 \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c, \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0440\u0438\u0441\u043a\u0430 \u0438 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438. \u0424\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0433\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435\u0439, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0442\u0430\u043a\u043e\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e, \u0447\u0442\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c\u044e, \u043d\u043e \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438. \u041f\u043e\u043d\u044f\u0442\u0438\u0435 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0431\u044b\u043b\u043e \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0413\u0430\u0440\u0440\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0435\u043c \u0432 1952 \u0433\u043e\u0434\u0443 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430.<\/p>\n<p>\u041f\u043e\u0440\u0442\u0444\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043a\u0430\u043a \u00ab\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439\u00bb, \u0435\u0441\u043b\u0438 \u043e\u043d \u0438\u043c\u0435\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0440\u0438\u0441\u043a\u0430 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f). \u0422\u0430\u043a, \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0440\u0438\u0441\u043a\u0430 \u0438 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043d\u0435\u0441\u0435\u043d\u0430 \u043b\u044e\u0431\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u0440\u0438\u0441\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0430\u043a\u0442\u0438\u0432\u043e\u0432, \u0438 \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0445 \u0442\u0430\u043a\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0440\u0435\u0433\u0438\u043e\u043d \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435. \u041f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435 \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u0442\u0438\u0432\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0435\u0440\u0445\u043d\u0435\u0439 (\u0432\u043e\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0439) \u0447\u0430\u0441\u0442\u044c\u044e \u0433\u0438\u043f\u0435\u0440\u0431\u043e\u043b\u044b, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0449\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u0430\u043a\u0442\u0438\u0432\u043e\u0432 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435.<\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0436\u0435, \u0435\u0441\u043b\u0438 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0451\u043d \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u044b\u0439 \u0430\u043a\u0442\u0438\u0432, \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0440\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0442\u0440\u0435\u0437\u043e\u043a \u043f\u0440\u044f\u043c\u043e\u0439 \u043b\u0438\u043d\u0438\u0438, \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u0442\u0438\u0432\u0430 \u043d\u0430 \u043e\u0441\u0438 \u043e\u0440\u0434\u0438\u043d\u0430\u0442 (\u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f) \u0438 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043f\u043e \u043a\u0430\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439. \u0412\u0441\u0435 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0438 \u043d\u0430 \u043e\u0442\u0440\u0435\u0437\u043a\u0435 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u044b\u043c \u0430\u043a\u0442\u0438\u0432\u043e\u043c \u0438 \u0442\u043e\u0447\u043a\u043e\u0439 \u043a\u0430\u0441\u0430\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u0442\u0438\u0432\u0430 \u0438 \u0440\u0438\u0441\u043a\u043e\u0432\u044b\u0445 \u0430\u043a\u0442\u0438\u0432\u043e\u0432, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432\u0441\u0435 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0438 \u043d\u0430 \u043b\u0438\u043d\u0438\u0438 \u0432\u044b\u0448\u0435 \u0438 \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u0442\u043e\u0447\u043a\u0438 \u043a\u0430\u0441\u0430\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0432 \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u043e\u043c \u0430\u043a\u0442\u0438\u0432\u0435 \u0438 \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432 \u0440\u0438\u0441\u043a\u043e\u0432\u044b\u0435 \u0430\u043a\u0442\u0438\u0432\u044b.<\/p>\n<figure class=\"float bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/195\/878\/ebe\/195878ebe0ce9d7f1b48e77c960f2759.png\" width=\"540\" height=\"302\"><figcaption><\/figcaption><\/figure>\n<h2>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043d\u0430 Python<\/h2>\n<p><u>\u0418\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a<\/u><\/p>\n<p>\u041a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code class=\"python\">import matplotlib.pyplot as plt import numpy as np import pandas as pd import pandas_datareader as web from matplotlib.ticker import FuncFormatter<\/code><\/pre>\n<p>\u041d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 PyPortfolioOpt. \u0422\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440, \u0442\u043e \u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c. <\/p>\n<pre><code class=\"python\">!pip install PyPortfolioOpt<\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code class=\"python\">from pypfopt.efficient_frontier import EfficientFrontier  from pypfopt import risk_models  from pypfopt import expected_returns from pypfopt.cla import CLA import pypfopt.plotting as pplt from matplotlib.ticker import FuncFormatter<\/code><\/pre>\n<p><u>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0430\u043a\u0446\u0438\u044f\u043c \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430<\/u><\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043e\u043f\u044f\u0442\u044c \u043f\u0430\u043a\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0430\u043a\u0446\u0438\u044f\u043c \u0441 \u0441\u0430\u0439\u0442\u0430 yahoo.<\/p>\n<p>\u0422\u0438\u043a\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 \u043b\u0438\u0434\u0435\u0440\u044b \u0432 \u0441\u0432\u043e\u0435\u043c \u0441\u0435\u043a\u0442\u043e\u0440\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9c8\/396\/9d4\/9c83969d45a7700b5925da351cc0267c.png\" width=\"975\" height=\"276\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">nullin_df = pd.DataFrame(df_stocks,columns=tickers) print(nullin_df.isnull().sum())<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/66c\/497\/f0d\/66c497f0d300a1f5b5a00649d4eec975.png\" width=\"130\" height=\"201\"><figcaption><\/figcaption><\/figure>\n<p><u>\u0420\u0430\u0441\u0447\u0435\u0442\u044b<\/u><\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0440\u0430\u0441\u0447\u0435\u0442\u0430\u043c \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0438 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u0438 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f. \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u0435\u0441\u043e\u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c \u0428\u0430\u0440\u043f\u0430 \u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0435\u0439.<\/p>\n<pre><code class=\"python\">#\u0413\u043e\u0434\u043e\u0432\u0430\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c mu = expected_returns.mean_historical_return(df_stocks)  #\u0414\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f Sigma = risk_models.sample_cov(df_stocks) #\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0428\u0430\u0440\u043f\u0430 ef = EfficientFrontier(mu, Sigma, weight_bounds=(0,1)) #weight bounds in negative allows shorting of stocks sharpe_pfolio=ef.max_sharpe() #May use add objective to ensure minimum zero weighting to individual stocks sharpe_pwt=ef.clean_weights() print(sharpe_pwt)  OrderedDict([('AFLT.ME', 0.0), ('DSKY.ME', 0.22606), ('GMKN.ME', 0.48796), ('IRAO.ME', 0.0), ('LKOH.ME', 0.0), ('MTSS.ME', 0.02953), ('NKNC.ME', 0.25645), ('SBER.ME', 0.0)])<\/code><\/pre>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c weight_bounds=(0,1) \u043d\u0430 weight_bounds=(-1,1), \u0442\u043e \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043f\u043e \u0430\u043a\u0446\u0438\u044f\u043c.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0431\u0449\u0438\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044e.<\/p>\n<pre><code class=\"python\">ef.portfolio_performance(verbose=True)  Expected annual return: 37.1% Annual volatility: 20.7% Sharpe Ratio: 1.70 (0.37123023494063007, 0.20717177784552962, 1.695357536597058)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c:<\/p>\n<pre><code class=\"python\">ef1 = EfficientFrontier(mu, Sigma, weight_bounds=(0,1))  minvol=ef1.min_volatility() minvol_pwt=ef1.clean_weights() print(minvol_pwt)  OrderedDict([('AFLT.ME', 0.02876), ('DSKY.ME', 0.24503), ('GMKN.ME', 0.10403), ('IRAO.ME', 0.0938), ('LKOH.ME', 0.01168), ('MTSS.ME', 0.41967), ('NKNC.ME', 0.09704), ('SBER.ME', 0.0)])  ef1.portfolio_performance(verbose=True, risk_free_rate = 0.27)  Expected annual return: 24.0% Annual volatility: 16.9% Sharpe Ratio: -0.18(0.239915644698749, 0.16885732511472468, -0.17816434839774456)<\/code><\/pre>\n<p><u>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0433\u0440\u0430\u043d\u0438\u0446<\/u><\/p>\n<p>\u0417\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0440\u0430\u0441\u0447\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u043e\u0432. <\/p>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043c \u0434\u043b\u044f \u0441\u0443\u043c\u043c\u044b \u0432 100 000 \u0440\u0443\u0431\u043b\u0435\u0439.<\/p>\n<pre><code class=\"python\">cl_obj = CLA(mu, Sigma) ax = pplt.plot_efficient_frontier(cl_obj, showfig = False) ax.xaxis.set_major_formatter(FuncFormatter(lambda x, _: '{:.0%}'.format(x))) ax.yaxis.set_major_formatter(FuncFormatter(lambda y, _: '{:.0%}'.format(y)))<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e:<\/p>\n<pre><code class=\"python\">latest_prices = get_latest_prices(df_stocks) allocation_minv, rem_minv = DiscreteAllocation(minvol_pwt, latest_prices, total_portfolio_value=100000).lp_portfolio()  print(allocation_minv) print(\"\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u0435\u043d\u0435\u0436\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e - {:.2f} \u0440\u0443\u0431\u043b\u0435\u0439\".format(rem_minv)) print()  {'AFLT.ME': 41, 'DSKY.ME': 181, 'IRAO.ME': 1765, 'LKOH.ME': 1, 'MTSS.ME': 127, 'NKNC.ME': 107} \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u0435\u043d\u0435\u0436\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e - 6152.03 \u0440\u0443\u0431\u043b\u0435\u0439<\/code><\/pre>\n<p>\u0412\u0442\u043e\u0440\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c \u0428\u0430\u0440\u043f\u0430:<\/p>\n<pre><code class=\"python\">latest_prices1 = get_latest_prices(df_stocks) allocation_shp, rem_shp = DiscreteAllocation(sharpe_pwt, latest_prices1, total_portfolio_value=100000).lp_portfolio()  print(allocation_shp) print(\"\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u0435\u043d\u0435\u0436\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c \u0428\u0430\u0440\u043f\u0430 {:.2f} \u0440\u0443\u0431\u043b\u0435\u0439\".format(rem_shp))  {'DSKY.ME': 167, 'GMKN.ME': 2, 'MTSS.ME': 9, 'NKNC.ME': 283}  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u0435\u043d\u0435\u0436\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c \u0428\u0430\u0440\u043f\u0430 1319.05 \u0440\u0443\u0431\u043b\u0435\u0439<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u043a\u0443\u043f\u0438\u0442\u044c \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f 167 \u0430\u043a\u0446\u0438\u0439 \u0414\u0435\u0442\u0441\u043a\u043e\u0433\u043e \u043c\u0438\u0440\u0430, 2 \u0430\u043a\u0446\u0438\u0438 \u041d\u043e\u0440\u0438\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043d\u0438\u043a\u0435\u043b\u044f, 9 \u0430\u043a\u0446\u0438\u0439 \u041c\u0422\u0421 \u0438 283 \u0430\u043a\u0446\u0438\u044e \u041d\u0438\u0436\u043d\u0435\u043a\u0430\u043c\u0441\u043a\u043d\u0435\u0444\u0442\u0435\u0445\u0438\u043c. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0449\u0435 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f 1319 \u0440\u0443\u0431\u043b\u0435\u0439.<\/p>\n<p>\u0415\u0449\u0435 \u0440\u0430\u0437 \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e, \u0447\u0442\u043e \u0432\u0441\u0435 \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0435\u0439, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0432\u043e\u0434\u043e\u043c \u043a \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u044e. <\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/561980\/\"> https:\/\/habr.com\/ru\/post\/561980\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h2>\u041f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0435\u043e\u0440\u0438\u044f \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430<\/h2>\n<p>\u041f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0435\u043e\u0440\u0438\u044f \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430(\u0434\u0430\u043b\u0435\u0435 \u041f\u0422\u041c) (Modern portfolio theory) \u2014 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u0430\u044f \u0413\u0430\u0440\u0440\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0438\u043a\u0430 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f, \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u043d\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0431\u043e\u0440 \u0430\u043a\u0442\u0438\u0432\u043e\u0432, \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0433\u043e \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c\/\u0440\u0438\u0441\u043a. \u0421\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u043c \u0432 1950-\u0445 \u0433\u043e\u0434\u0430\u0445 \u0438\u0434\u0435\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043e\u0441\u043d\u043e\u0432\u0443 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438 \u0431\u044b\u043b\u0438 \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0413\u0430\u0440\u0440\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u0438\u043c \u0434\u043e\u043a\u0442\u043e\u0440\u0441\u043a\u043e\u0439 \u0434\u0438\u0441\u0441\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0432 1950\u20141951 \u0433\u043e\u0434\u0430\u0445.<\/p>\n<p>\u0420\u043e\u0436\u0434\u0435\u043d\u0438\u0435\u043c \u0436\u0435 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432 \u00ab\u0424\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u043e\u043c \u0436\u0443\u0440\u043d\u0430\u043b\u0435\u00bb \u0432 1952 \u0433\u043e\u0434\u0443 \u0441\u0442\u0430\u0442\u044c\u044f \u00ab\u0412\u044b\u0431\u043e\u0440 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f\u00bb. \u0412 \u043d\u0435\u0439 \u043e\u043d \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0438 \u043f\u0440\u0438\u0432\u0451\u043b \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435\u0439 \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0441\u043b\u0443\u0433\u0430 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043b\u0430 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043d\u044f\u0442\u0438\u0439 \u00ab\u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c\u00bb \u0438 \u00ab\u0440\u0438\u0441\u043a\u00bb, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u044b\u0431\u043e\u0440\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043d\u0430 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a. \u041d\u0430\u0434\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u0433\u043e\u0434\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0435\u043e\u0440\u0438\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0432 RAND Corp., \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0438 \u043d\u0435\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 \u0414\u0436\u043e\u0440\u0434\u0436\u0435\u043c \u0414\u0430\u043d\u0446\u0438\u0433\u043e\u043c \u0438 \u0441\u0430\u043c \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0442\u0435\u043e\u0440\u0438\u044f, \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0445\u043e\u0440\u043e\u0448\u043e \u043b\u043e\u0436\u0438\u043b\u0430\u0441\u044c \u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0440\u0443\u0441\u043b\u043e.<\/p>\n<p>\u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0443\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0432\u043e\u0435\u0439 \u0442\u0435\u043e\u0440\u0438\u0438 \u0438 \u0432 1959 \u0433\u043e\u0434\u0443 \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u0443\u044e \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d\u043d\u0443\u044e \u0435\u0439 \u043c\u043e\u043d\u043e\u0433\u0440\u0430\u0444\u0438\u044e \u00ab\u0412\u044b\u0431\u043e\u0440 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f: \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0434\u0438\u0432\u0435\u0440\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u0439\u00bb.<\/p>\n<h2>\u041e\u0441\u043d\u043e\u0432\u0430 \u043c\u043e\u0434\u0435\u043b\u0438<\/h2>\n<p>1.&nbsp;<u>\u041e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f(Portfolio Expected Return)<\/u><\/p>\n<p>\u041e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0430\u043a\u0442\u0438\u0432\u043e\u0432, \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 \u043d\u0435\u0433\u043e. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0440\u0438\u0441\u043a \u0437\u0430 \u0441\u0447\u0435\u0442 \u0434\u0438\u0432\u0435\u0440\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0445\u043e\u0434 \u0438\u043d\u0432\u0435\u0441\u0442\u043e\u0440\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443\u0431\u044b\u0442\u043a\u0438 \u043f\u043e \u043e\u0434\u043d\u0438\u043c \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u044f\u043c \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043c\u043f\u0435\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u043e\u0445\u043e\u0434\u043e\u043c \u043f\u043e \u0434\u0440\u0443\u0433\u0438\u043c.<\/p>\n<p>\u041e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u0443\u044e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0443\u044e \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 \u043d\u0435\u0433\u043e \u0446\u0435\u043d\u043d\u044b\u0445 \u0431\u0443\u043c\u0430\u0433, \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u0443\u044e \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0438\u0445 \u0434\u043e\u043b\u0438 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435.<\/p>\n<p>2.<u>\u0414\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f (Portfolio Variance)<\/u><\/p>\n<p>\u0414\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0440\u0438\u0441\u043a\u0430 \u0438\u043b\u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u0441 \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435\u043c. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u044d\u0442\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0435\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u0438 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0435\u0439, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u0441 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0446\u0435\u043d\u043d\u044b\u0445 \u0431\u0443\u043c\u0430\u0433, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u043c \u0438\u043b\u0438 \u0447\u0430\u0441\u0442\u044c\u044e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u0430\u044f \u0446\u0435\u043d\u043d\u0430\u044f \u0431\u0443\u043c\u0430\u0433\u0430.<\/p>\n<p>3.<u>\u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0428\u0430\u0440\u043f\u0430 (Sharpe Ratio)<\/u><\/p>\n<p>4.&nbsp;<u>\u042d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430 (The Efficient Frontier)<\/u><\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438 \u0440\u0438\u0441\u0443\u043d\u043e\u043a \u0438\u0437 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%93%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0_%D1%8D%D1%84%D1%84%D0%B5%D0%BA%D1%82%D0%B8%D0%B2%D0%BD%D0%BE%D1%81%D1%82%D0%B8\" rel=\"noopener noreferrer nofollow\">\u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438<\/a>:<\/p>\n<p>\u0413\u0440\u0430\u043d\u0438\u0446\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 (\u0430\u043d\u0433\u043b. Efficient frontier) \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430 \u2014 \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c, \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0440\u0438\u0441\u043a\u0430 \u0438 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438. \u0424\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0433\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435\u0439, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0442\u0430\u043a\u043e\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e, \u0447\u0442\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c\u044e, \u043d\u043e \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438. \u041f\u043e\u043d\u044f\u0442\u0438\u0435 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0431\u044b\u043b\u043e \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0413\u0430\u0440\u0440\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0435\u043c \u0432 1952 \u0433\u043e\u0434\u0443 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u041c\u0430\u0440\u043a\u043e\u0432\u0438\u0446\u0430.<\/p>\n<p>\u041f\u043e\u0440\u0442\u0444\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043a\u0430\u043a \u00ab\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439\u00bb, \u0435\u0441\u043b\u0438 \u043e\u043d \u0438\u043c\u0435\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0440\u0438\u0441\u043a\u0430 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f). \u0422\u0430\u043a, \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0440\u0438\u0441\u043a\u0430 \u0438 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043d\u0435\u0441\u0435\u043d\u0430 \u043b\u044e\u0431\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u0440\u0438\u0441\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0430\u043a\u0442\u0438\u0432\u043e\u0432, \u0438 \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0445 \u0442\u0430\u043a\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0440\u0435\u0433\u0438\u043e\u043d \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435. \u041f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435 \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u0442\u0438\u0432\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0435\u0440\u0445\u043d\u0435\u0439 (\u0432\u043e\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0439) \u0447\u0430\u0441\u0442\u044c\u044e \u0433\u0438\u043f\u0435\u0440\u0431\u043e\u043b\u044b, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0449\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u0430\u043a\u0442\u0438\u0432\u043e\u0432 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435.<\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0436\u0435, \u0435\u0441\u043b\u0438 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0451\u043d \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u044b\u0439 \u0430\u043a\u0442\u0438\u0432, \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0440\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0442\u0440\u0435\u0437\u043e\u043a \u043f\u0440\u044f\u043c\u043e\u0439 \u043b\u0438\u043d\u0438\u0438, \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u0442\u0438\u0432\u0430 \u043d\u0430 \u043e\u0441\u0438 \u043e\u0440\u0434\u0438\u043d\u0430\u0442 (\u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f) \u0438 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043f\u043e \u043a\u0430\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439. \u0412\u0441\u0435 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0438 \u043d\u0430 \u043e\u0442\u0440\u0435\u0437\u043a\u0435 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u044b\u043c \u0430\u043a\u0442\u0438\u0432\u043e\u043c \u0438 \u0442\u043e\u0447\u043a\u043e\u0439 \u043a\u0430\u0441\u0430\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u0442\u0438\u0432\u0430 \u0438 \u0440\u0438\u0441\u043a\u043e\u0432\u044b\u0445 \u0430\u043a\u0442\u0438\u0432\u043e\u0432, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432\u0441\u0435 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0438 \u043d\u0430 \u043b\u0438\u043d\u0438\u0438 \u0432\u044b\u0448\u0435 \u0438 \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u0442\u043e\u0447\u043a\u0438 \u043a\u0430\u0441\u0430\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0432 \u0431\u0435\u0437\u0440\u0438\u0441\u043a\u043e\u0432\u043e\u043c \u0430\u043a\u0442\u0438\u0432\u0435 \u0438 \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432 \u0440\u0438\u0441\u043a\u043e\u0432\u044b\u0435 \u0430\u043a\u0442\u0438\u0432\u044b.<\/p>\n<figure class=\"float bordered full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043d\u0430 Python<\/h2>\n<p><u>\u0418\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a<\/u><\/p>\n<p>\u041a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code class=\"python\">import matplotlib.pyplot as plt import numpy as np import pandas as pd import pandas_datareader as web from matplotlib.ticker import FuncFormatter<\/code><\/pre>\n<p>\u041d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 PyPortfolioOpt. \u0422\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440, \u0442\u043e \u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c. <\/p>\n<pre><code class=\"python\">!pip install PyPortfolioOpt<\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code class=\"python\">from pypfopt.efficient_frontier import EfficientFrontier  from pypfopt import risk_models  from pypfopt import expected_returns from pypfopt.cla import CLA import pypfopt.plotting as pplt from matplotlib.ticker import FuncFormatter<\/code><\/pre>\n<p><u>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0430\u043a\u0446\u0438\u044f\u043c \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430<\/u><\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043e\u043f\u044f\u0442\u044c \u043f\u0430\u043a\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0430\u043a\u0446\u0438\u044f\u043c \u0441 \u0441\u0430\u0439\u0442\u0430 yahoo.<\/p>\n<p>\u0422\u0438\u043a\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 \u043b\u0438\u0434\u0435\u0440\u044b \u0432 \u0441\u0432\u043e\u0435\u043c \u0441\u0435\u043a\u0442\u043e\u0440\u0435.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">nullin_df = pd.DataFrame(df_stocks,columns=tickers) print(nullin_df.isnull().sum())<\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p><u>\u0420\u0430\u0441\u0447\u0435\u0442\u044b<\/u><\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0440\u0430\u0441\u0447\u0435\u0442\u0430\u043c \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0438 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 \u0438 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f. \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u0435\u0441\u043e\u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c \u0428\u0430\u0440\u043f\u0430 \u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0435\u0439.<\/p>\n<pre><code class=\"python\">#\u0413\u043e\u0434\u043e\u0432\u0430\u044f \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044c mu = expected_returns.mean_historical_return(df_stocks)  #\u0414\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f Sigma = risk_models.sample_cov(df_stocks) #\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0428\u0430\u0440\u043f\u0430 ef = EfficientFrontier(mu, Sigma, weight_bounds=(0,1)) #weight bounds in negative allows shorting of stocks sharpe_pfolio=ef.max_sharpe() #May use add objective to ensure minimum zero weighting to individual stocks sharpe_pwt=ef.clean_weights() print(sharpe_pwt)  OrderedDict([('AFLT.ME', 0.0), ('DSKY.ME', 0.22606), ('GMKN.ME', 0.48796), ('IRAO.ME', 0.0), ('LKOH.ME', 0.0), ('MTSS.ME', 0.02953), ('NKNC.ME', 0.25645), ('SBER.ME', 0.0)])<\/code><\/pre>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c weight_bounds=(0,1) \u043d\u0430 weight_bounds=(-1,1), \u0442\u043e \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043f\u043e \u0430\u043a\u0446\u0438\u044f\u043c.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0431\u0449\u0438\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044e.<\/p>\n<pre><code class=\"python\">ef.portfolio_performance(verbose=True)  Expected annual return: 37.1% Annual volatility: 20.7% Sharpe Ratio: 1.70 (0.37123023494063007, 0.20717177784552962, 1.695357536597058)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c:<\/p>\n<pre><code class=\"python\">ef1 = EfficientFrontier(mu, Sigma, weight_bounds=(0,1))  minvol=ef1.min_volatility() minvol_pwt=ef1.clean_weights() print(minvol_pwt)  OrderedDict([('AFLT.ME', 0.02876), ('DSKY.ME', 0.24503), ('GMKN.ME', 0.10403), ('IRAO.ME', 0.0938), ('LKOH.ME', 0.01168), ('MTSS.ME', 0.41967), ('NKNC.ME', 0.09704), ('SBER.ME', 0.0)])  ef1.portfolio_performance(verbose=True, risk_free_rate = 0.27)  Expected annual return: 24.0% Annual volatility: 16.9% Sharpe Ratio: -0.18(0.239915644698749, 0.16885732511472468, -0.17816434839774456)<\/code><\/pre>\n<p><u>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0433\u0440\u0430\u043d\u0438\u0446<\/u><\/p>\n<p>\u0417\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0440\u0430\u0441\u0447\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u043e\u0432. <\/p>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043c \u0434\u043b\u044f \u0441\u0443\u043c\u043c\u044b \u0432 100 000 \u0440\u0443\u0431\u043b\u0435\u0439.<\/p>\n<pre><code class=\"python\">cl_obj = CLA(mu, Sigma) ax = pplt.plot_efficient_frontier(cl_obj, showfig = False) ax.xaxis.set_major_formatter(FuncFormatter(lambda x, _: '{:.0%}'.format(x))) ax.yaxis.set_major_formatter(FuncFormatter(lambda y, _: '{:.0%}'.format(y)))<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e:<\/p>\n<pre><code class=\"python\">latest_prices = get_latest_prices(df_stocks) allocation_minv, rem_minv = DiscreteAllocation(minvol_pwt, latest_prices, total_portfolio_value=100000).lp_portfolio()  print(allocation_minv) print(\"\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u0435\u043d\u0435\u0436\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e - {:.2f} \u0440\u0443\u0431\u043b\u0435\u0439\".format(rem_minv)) print()  {'AFLT.ME': 41, 'DSKY.ME': 181, 'IRAO.ME': 1765, 'LKOH.ME': 1, 'MTSS.ME': 127, 'NKNC.ME': 107} \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u0435\u043d\u0435\u0436\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e - 6152.03 \u0440\u0443\u0431\u043b\u0435\u0439<\/code><\/pre>\n<p>\u0412\u0442\u043e\u0440\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c \u0428\u0430\u0440\u043f\u0430:<\/p>\n<pre><code class=\"python\">latest_prices1 = get_latest_prices(df_stocks) allocation_shp, rem_shp = DiscreteAllocation(sharpe_pwt, latest_prices1, total_portfolio_value=100000).lp_portfolio()  print(allocation_shp) print(\"\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u0435\u043d\u0435\u0436\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c \u0428\u0430\u0440\u043f\u0430 {:.2f} \u0440\u0443\u0431\u043b\u0435\u0439\".format(rem_shp))  {'DSKY.ME': 167, 'GMKN.ME': 2, 'MTSS.ME': 9, 'NKNC.ME': 283}  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u0435\u043d\u0435\u0436\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c \u0428\u0430\u0440\u043f\u0430 1319.05 \u0440\u0443\u0431\u043b\u0435\u0439<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u043a\u0443\u043f\u0438\u0442\u044c \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f 167 \u0430\u043a\u0446\u0438\u0439 \u0414\u0435\u0442\u0441\u043a\u043e\u0433\u043e \u043c\u0438\u0440\u0430, 2 \u0430\u043a\u0446\u0438\u0438 \u041d\u043e\u0440\u0438\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043d\u0438\u043a\u0435\u043b\u044f, 9 \u0430\u043a\u0446\u0438\u0439 \u041c\u0422\u0421 \u0438 283 \u0430\u043a\u0446\u0438\u044e \u041d\u0438\u0436\u043d\u0435\u043a\u0430\u043c\u0441\u043a\u043d\u0435\u0444\u0442\u0435\u0445\u0438\u043c. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0449\u0435 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f 1319 \u0440\u0443\u0431\u043b\u0435\u0439.<\/p>\n<p>\u0415\u0449\u0435 \u0440\u0430\u0437 \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e, \u0447\u0442\u043e \u0432\u0441\u0435 \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0435\u0439, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0432\u043e\u0434\u043e\u043c \u043a \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u044e. <\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/561980\/\"> https:\/\/habr.com\/ru\/post\/561980\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-324638","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=324638"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324638\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}