{"id":374545,"date":"2024-05-21T06:02:57","date_gmt":"2024-05-21T06:02:57","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=374545"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=374545","title":{"rendered":"<span>\u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u0430 \u0432\u0430\u043b\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>\u041c\u0435\u0442\u043e\u0434 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e <\/strong>\u2014 \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u0445 \u043d\u0430\u0443\u043a\u0438 \u0438 \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0438\u0438. \u0412 \u0444\u0438\u043d\u0430\u043d\u0441\u0430\u0445, \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043a\u0443\u0440\u0441 \u0432\u0430\u043b\u044e\u0442 \u0438\u043b\u0438 \u0430\u043a\u0446\u0438\u0439. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u043e \u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0438\u0441\u0445\u043e\u0434\u043e\u0432, \u0447\u0442\u043e \u043a\u0440\u0430\u0439\u043d\u0435 \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0438\u0441\u043a\u0430\u043c\u0438 \u0438 \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u043c\u0435\u0442\u043e\u0434\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 (\u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0439), \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u0445 \u0438\u0437 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0443\u0440\u0441\u0430 \u0432\u0430\u043b\u044e\u0442, \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0438 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043b\u0435\u0431\u0430\u043d\u0438\u044f \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u0445 \u043f\u0430\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0439 \u0430\u0441\u043f\u0435\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e \u0432 \u0444\u0438\u043d\u0430\u043d\u0441\u0430\u0445 \u2014 \u044d\u0442\u043e \u0435\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0434\u0440\u0435\u0439\u0444 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442. \u0414\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u044c (Generalized Autoregressive Conditional Heteroskedasticity). \u0413\u0410\u0420\u0427 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0438 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u043c \u043f\u0440\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432. <\/p>\n<p>\u0418\u0434\u0435\u0439\u043d\u043e \u043a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f<u> \u0431\u0435\u0437 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043b\u0438\u0431<\/u>, \u0442\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0434\u043b\u044f \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0430\u043f\u043f\u0430\u0440\u0430\u0442\u043e\u043c.<\/p>\n<p><strong>\u041f\u0440\u043e\u0435\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b:<\/strong><\/p>\n<ul>\n<li>\n<p><code>yfinance<\/code>\u00a0\u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><code>numpy<\/code>\u00a0\u0438\u00a0<code>pandas<\/code>\u00a0\u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><code>matplotlib<\/code>\u00a0\u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><code>scipy<\/code>\u00a0\u0438\u00a0<code>arch<\/code>\u00a0\u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0418\u043c\u043f\u043e\u0440\u0442 \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>\u0414\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u043a\u0443\u0440\u0441\u0430 \u0432\u0430\u043b\u044e\u0442 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c USD\/RUB \u0438 EUR\/RUB, \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>yfinance<\/code>. \u042d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u043e\u0441\u043d\u043e\u0432\u0443 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 2013 \u0433\u043e\u0434\u0430 \u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044f \u0430\u043f\u0440\u0435\u043b\u0435\u043c 2023 \u0433\u043e\u0434\u0430. \u0421\u0435\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 &#171;\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e&#187; \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043a\u0443\u0440\u0441\u0430 \u0438 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u0430. <\/p>\n<p>\u042f \u0431\u0440\u0430\u043b \u043e\u0442\u0440\u0435\u0437\u043a\u0438 [2004;2023], [2008;2020], [2010;2023]\u0438 \u0442.\u0434, \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0441\u044f \u0441\u0445\u043e\u0436\u0438\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0440\u044f\u0434\u043e\u043c &#171;\u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0433\u043e&#187; \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u043b\u0430\u0440\u0430. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043b. \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c!<\/p>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0434\u043d\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u044b \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u043e \u0434\u0430\u043d\u043d\u044b\u0445<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u0430\u0445 data = yf.download(\"USDRUB=X EURRUB=X\", start=\"2013-01-01\", end=\"2023-04-13\")<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ed8\/fa8\/31d\/ed8fa831ddd420d49dde8be8a82c131f.png\" alt=\"\u0421\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0435\" title=\"\u0421\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0435\" width=\"1195\" height=\"469\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ed8\/fa8\/31d\/ed8fa831ddd420d49dde8be8a82c131f.png\"\/><\/figure>\n<p>\u0418\u0437 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u0443\u0440\u0441 \u043d\u0430 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 <\/p>\n<pre><code class=\"python\">usd_rates = data['Close']['USDRUB=X'].dropna() eur_rates = data['Close']['EURRUB=X'].dropna()<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p><em>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438<\/em><\/p>\n<h3>1. \u0424\u0443\u043d\u043a\u0446\u0438\u044f simulate_exchange_rates<\/h3>\n<p>\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b. \u041e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0431\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f (GBM), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u043e\u043c \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0446\u0435\u043d \u0438\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432.<\/p>\n<p><strong>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 GBM:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"S_t = S_0 \\exp\\left((\\mu - \\frac{\\sigma^2}{2})t + \\sigma W_t\\right)\" alt=\"S_t = S_0 \\exp\\left((\\mu - \\frac{\\sigma^2}{2})t + \\sigma W_t\\right)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c1d\/083\/e59\/c1d083e5921d3224595144413558ad6d.svg\" width=\"270\" height=\"51\"\/><\/p>\n<p>\u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p>( St ) \u2014 \u0446\u0435\u043d\u0430 \u0430\u043a\u0442\u0438\u0432\u0430 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 ( t ),<\/p>\n<\/li>\n<li>\n<p>( S0 ) \u2014 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0446\u0435\u043d\u0430 \u0430\u043a\u0442\u0438\u0432\u0430,<\/p>\n<\/li>\n<li>\n<p>( <em>\u03bc<\/em> ) \u2014 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0434\u0440\u0435\u0439\u0444 (\u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438),<\/p>\n<\/li>\n<li>\n<p>( <em>\u03c3<\/em>  ) \u2014 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 (\u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c),<\/p>\n<\/li>\n<li>\n<p>( Wt ) \u2014 \u0432\u0438\u043d\u0435\u0440\u043e\u0432\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 (\u0438\u043b\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0431\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0435 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435).<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u0414\u043d\u0435\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u044b \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a <\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"( \\exp\\left((\\mu - \\frac{\\sigma^2}{2}) \\frac{1}{\\text{days}} + \\sigma \\sqrt{\\frac{1}{\\text{days}}} Z\\right) )\" alt=\"( \\exp\\left((\\mu - \\frac{\\sigma^2}{2}) \\frac{1}{\\text{days}} + \\sigma \\sqrt{\\frac{1}{\\text{days}}} Z\\right) )\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cb6\/dc1\/525\/cb6dc152500f94d0721843bdfb62942f.svg\" width=\"310\" height=\"62\"\/><\/p>\n<p>\u0433\u0434\u0435 ( Z ) \u2014 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/p>\n<ul>\n<li>\n<p>\u042d\u0442\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u044b \u0437\u0430\u0442\u0435\u043c \u0443\u043c\u043d\u043e\u0436\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u0430 \u0432\u0430\u043b\u044e\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u043e\u0432 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0434\u043d\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def simulate_exchange_rates(historical_rates, days, simulations, drifts, volatilities):     dt = 1 \/ days     simulated_rates = {}     for currency, rates in historical_rates.items():         drift = drifts[currency]         volatility = volatilities[currency]         daily_returns = np.exp((drift - 0.5 * volatility**2) * dt +                                 volatility * np.random.normal(0, np.sqrt(dt), (days, simulations)))         simulation = rates.iloc[-1] * np.cumprod(daily_returns, axis=0)         simulated_rates[currency] = simulation     return simulated_rates<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>2. \u0424\u0443\u043d\u043a\u0446\u0438\u044f portfolio_value<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>portfolio_value<\/code> \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0432 \u0440\u0443\u0431\u043b\u044f\u0445, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u0443\u0440\u0441\u044b \u0432\u0430\u043b\u044e\u0442 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435. \u0421\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"V = \\sum_{i=1}^n x_i \\cdot S_i(T)\" alt=\"V = \\sum_{i=1}^n x_i \\cdot S_i(T)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7de\/499\/d5a\/7de499d5aa56f7a51a9e14e04b073ca6.svg\" width=\"150\" height=\"57\"\/><\/p>\n<p>\u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p>( xi ) \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0430\u043b\u044e\u0442\u044b ( i ) \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435,<\/p>\n<\/li>\n<li>\n<p>( Si(T) ) \u2014 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0443\u0440\u0441 \u0432\u0430\u043b\u044e\u0442\u044b ( i ) \u043d\u0430 \u043a\u043e\u043d\u0435\u0446 \u043f\u0435\u0440\u0438\u043e\u0434\u0430 ( T ),<\/p>\n<\/li>\n<li>\n<p>( n ) \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0430\u043b\u044e\u0442 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435.<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def portfolio_value(simulated_rates, portfolio):     simulations = next(iter(simulated_rates.values())).shape[1]     values = np.full(simulations, portfolio.get('RUB', 0), dtype=float)       for currency, amount in portfolio.items():         if currency != 'RUB':             values += amount * simulated_rates[currency][-1, :]     return values<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>3. \u0424\u0443\u043d\u043a\u0446\u0438\u0438 calculate_var \u0438 calculate_cvar<\/h3>\n<ul>\n<li>\n<p><strong>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <\/strong><code>calculate_var<\/code> \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u0442 Value at Risk (VaR) \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 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u043e\u0442\u0435\u0440\u044e \u0432 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0434\u043e\u0432\u0435\u0440\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 95%). VaR \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a:<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{VaR}_\\alpha = V_{(\\alpha)}\" alt=\"\\text{VaR}_\\alpha = V_{(\\alpha)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7c4\/b26\/380\/7c4b263803a5df80da5d7e71457d9b55.svg\" width=\"107\" height=\"24\"\/><\/p>\n<p>\u0433\u0434\u0435 V (\u03b1) \u2014 \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u03b1.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def calculate_var(portfolio_values, confidence_level=0.95):     sorted_values = np.sort(portfolio_values)     index = int((1 - confidence_level) * len(sorted_values))     return sorted_values[index]<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<ul>\n<li>\n<p><strong>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <\/strong><code>calculate_cvar<\/code> \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 Conditional Value at Risk (CVaR), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0440\u0435\u0434\u043d\u044e\u044e \u043f\u043e\u0442\u0435\u0440\u044e, \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u044e\u0449\u0443\u044e VaR:<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{CVaR}_\\alpha = \\frac{1}{1-\\alpha} \\int_\\alpha^1 V_u \\, du\" alt=\"\\text{CVaR}_\\alpha = \\frac{1}{1-\\alpha} \\int_\\alpha^1 V_u \\, du\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/856\/bd8\/8ca\/856bd88ca8644ce8c6a222c078c27eda.svg\" width=\"222\" height=\"51\"\/><\/p>\n<p>\u0433\u0434\u0435 ( V<em>u<\/em>) \u2014 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0432 \u0442\u043e\u0447\u043a\u0435 \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u044f (u).<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def calculate_cvar(portfolio_values, confidence_level=0.95):     var = calculate_var(portfolio_values, confidence_level)     cvar = portfolio_values[portfolio_values &lt;= var].mean()     return cvar<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>4. \u0424\u0443\u043d\u043a\u0446\u0438\u044f calculate_confidence_interval<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>calculate_confidence_interval<\/code> \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0434\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0434\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0432 \u043a\u0430\u043a\u043e\u043c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u043a\u043e\u043b\u0435\u0431\u0430\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p><strong>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/strong><\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0434\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u0435\u0439. \u041e\u043d \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0448\u0430\u0433\u0430\u0445:<\/p>\n<ul>\n<li>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u044f\u043c, \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0434\u043e\u0432\u0435\u0440\u0438\u044f ( \u03b1 ).<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\text{\u0414\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b} = \\left( \\text{\u041f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u044c}_{\\left(\\frac{1-\\alpha}{2}\\right) \\times 100}, \\text{\u041f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u044c}_{\\left(1-\\frac{1-\\alpha}{2}\\right) \\times 100} \\right)\" alt=\"\\text{\u0414\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b} = \\left( \\text{\u041f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u044c}_{\\left(\\frac{1-\\alpha}{2}\\right) \\times 100}, \\text{\u041f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u044c}_{\\left(1-\\frac{1-\\alpha}{2}\\right) \\times 100} \\right)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f25\/1ac\/66e\/f251ac66ee6744001f0d360a31278428.svg\" width=\"585\" height=\"49\"\/><\/p>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0446\u0435\u043d\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0435\u0440\u0445\u043d\u044e\u044e \u0438 \u043d\u0438\u0436\u043d\u044e\u044e \u0433\u0440\u0430\u043d\u0438\u0446\u0443 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u0443\u0440\u0441\u0430 \u0432\u0430\u043b\u044e\u0442\u044b \u0441 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e ( \u03b1 ).<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def calculate_confidence_interval(simulated_data, confidence_level=0.95):     lower_percentile = (1 - confidence_level) \/ 2 * 100     upper_percentile = (1 - (1 - confidence_level) \/ 2) * 100     lower_bound = np.percentile(simulated_data, lower_percentile)     upper_bound = np.percentile(simulated_data, upper_percentile)     return lower_bound, upper_bound<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>5. \u0424\u0443\u043d\u043a\u0446\u0438\u044f calculate_drift_volatility<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>calculate_drift_volatility<\/code> \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043a\u0443\u0440\u0441\u0430\u0445 \u0432\u0430\u043b\u044e\u0442. \u042d\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0446\u0435\u043d \u043f\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0431\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p><strong>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0441\u0447\u0435\u0442\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0418\u0437 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438:<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\" ( r_t = \\ln\\left(\\frac{S_t}{S_{t-1}}\\right) )\" alt=\" ( r_t = \\ln\\left(\\frac{S_t}{S_{t-1}}\\right) )\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c8d\/1fe\/46d\/c8d1fe46d1f50b8a545e63d9a89bf390.svg\" width=\"144\" height=\"49\"\/><\/p>\n<ul>\n<li>\n<p>\u0414\u0440\u0435\u0439\u0444 ( <em>\u03bc<\/em> ) \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c (<em>\u03c3<\/em>) \u2014 \u044d\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u044d\u0442\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0435\u0435 \u043e\u043a\u043d\u043e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 252 \u0434\u043d\u044f, \u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0442\u043e\u0440\u0433\u043e\u0432\u044b\u0445 \u0434\u043d\u0435\u0439 \u0432 \u0433\u043e\u0434\u0443), \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0440\u044b\u043d\u043a\u0435 \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u043e\u043b\u0435\u0435 \u0430\u0434\u0430\u043f\u0442\u0438\u0432\u043d\u043e\u0439 \u043a \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def calculate_drift_volatility(rates, lookback_period=252):     log_returns = np.log(rates \/ rates.shift(1)).dropna()     rolling_mean = log_returns.rolling(window=lookback_period).mean()     rolling_std = log_returns.rolling(window=lookback_period).std()     drift = rolling_mean.iloc[-1]     volatility = rolling_std.iloc[-1]     return drift, volatility<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>6. \u0424\u0443\u043d\u043a\u0446\u0438\u044f fit_garch_model<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>fit_garch_model<\/code> \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043e\u0446\u0435\u043d\u043a\u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u0438. \u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0434\u043b\u044f \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432, \u0433\u0434\u0435 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439, \u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c.<\/p>\n<p><strong>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0434\u0433\u043e\u043d\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u2014 \u044d\u0442\u043e \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0413\u0410\u0420\u0427 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 ( p ) \u0438 ( q ), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0440\u044f\u0434\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0438 \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0435\u0433\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0434\u0433\u043e\u043d\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043e\u0446\u0435\u043d\u043a\u0438 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u043e\u0439 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f, \u0447\u0442\u043e \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043a\u043e\u043b\u0435\u0431\u0430\u043d\u0438\u0439 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442.<\/p>\n<\/li>\n<\/ul>\n<p>\u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0440\u0438\u0441\u043a \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0445 \u0440\u044b\u043d\u043a\u043e\u0432.  <\/p>\n<h3>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e \u0434\u043b\u044f \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u043e\u0432<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0432\u0441\u0435\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 \u044d\u0442\u0430\u043f\u0443 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u2014 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e. \u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0448\u0430\u0433\u043e\u0432:<\/p>\n<h4>\u0420\u0430\u0441\u0447\u0435\u0442 \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h4>\n<ol>\n<li>\n<p><strong>\u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0435\u0439<\/strong>: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0443\u0440\u0441\u043e\u0432 USD \u0438 EUR, \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438. \u042d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0439.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"r_t = \\ln\\left(\\frac{S_t}{S_{t-1}}\\right)\" alt=\"r_t = \\ln\\left(\\frac{S_t}{S_{t-1}}\\right)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f22\/610\/11d\/f2261011d1b87d1f45eac5a1e30fa589.svg\" width=\"129\" height=\"49\"\/><\/li>\n<li>\n<p><strong>\u0420\u0430\u0441\u0447\u0435\u0442 \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u0445 \u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0439<\/strong>: \u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0435\u0433\u043e \u043e\u043a\u043d\u0430 \u0432 252 \u0434\u043d\u044f (\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0440\u0433\u043e\u0432\u044b\u0445 \u0434\u043d\u0435\u0439 \u0432 \u0433\u043e\u0434\u0443) \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u0435 \u0441\u0440\u0435\u0434\u043d\u0438\u0435 \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u044f. \u042d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0440\u0435\u0439\u0444 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u0421\u0435\u043a\u0440\u0435\u0442\u0438\u043a<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0412\u043e\u043e\u0431\u0449\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u044f calculate_confidence_interval \u0431\u044b\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043c\u043d\u043e\u044e \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044f \u0443\u0437\u043d\u0430\u043b \u043f\u0440\u043e GARCH, \u0442\u0430\u043a \u0447\u0442\u043e \u044f \u0438\u0437 \u0434\u043e\u0441\u0430\u0434\u044b \u0440\u0435\u0448\u0438\u043b \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438<\/p>\n<\/div>\n<\/details>\n<h4>\u041f\u043e\u0434\u0433\u043e\u043d\u043a\u0430 \u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u0438<\/h4>\n<ol start=\"3\">\n<li>\n<p><strong>\u041f\u043e\u0434\u0433\u043e\u043d\u043a\u0430 \u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u0438<\/strong>: \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b \u043f\u043e\u0434\u0433\u043e\u043d\u044f\u0435\u0442\u0441\u044f \u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u044c \u043a \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u044f\u043c. \u041c\u043e\u0434\u0435\u043b\u044c \u0413\u0410\u0420\u0427 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u0443\u044e \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0435 \u0441\u0440\u0435\u0434\u043d\u0435\u0435, \u0447\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<h4>\u0421\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u043e\u0432<\/h4>\n<ol start=\"4\">\n<li>\n<p><strong>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0439<\/strong>: \u0421 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u043d\u0435\u0439 (252 \u0434\u043d\u044f \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435) \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0439 (1,000,000 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435). \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0431\u0443\u0434\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u0430 \u0432\u0430\u043b\u044e\u0442\u044b. <\/p>\n<ul>\n<li>\n<p>\u0421\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0431\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h4>\u0412\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c<\/h4>\n<ol start=\"5\">\n<li>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/strong>: \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0443\u0431\u043b\u0435\u0439, \u0434\u043e\u043b\u043b\u0430\u0440\u043e\u0432 \u0438 \u0435\u0432\u0440\u043e \u0432 \u0435\u0433\u043e \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435. \u042d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u0412\u0435\u0441\u044c \u043a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">historical_rates = {'USD': usd_rates, 'EUR': eur_rates} days = 252 simulations = 1000000 # \u0420\u0430\u0441\u0447\u0435\u0442 \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f  # \u0447\u0435\u0440\u0435\u0437 calculate_drift_volatility drifts = {} volatilities = {} for currency, rates in historical_rates.items():     drifts[currency], volatilities[currency] = calculate_drift_volatility(rates)  # \u0420\u0430\u0441\u0447\u0435\u0442 \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f via garch usd_log_returns = np.log(usd_rates \/ usd_rates.shift(1)).dropna() eur_log_returns = np.log(eur_rates \/ eur_rates.shift(1)).dropna()  usd_drift_garch, usd_volatility_garch = fit_garch_model(usd_log_returns) eur_drift_garch, eur_volatility_garch = fit_garch_model(eur_log_returns)  # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0434\u0440\u0435\u0439\u0444\u043e\u0432 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e drifts['USD'] = usd_drift_garch drifts['EUR'] = eur_drift_garch volatilities['USD'] = usd_volatility_garch volatilities['EUR'] = eur_volatility_garch  # \u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442 simulated_rates = simulate_exchange_rates(historical_rates, days, simulations, drifts, volatilities)  # \u0412\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c rub_amount = float(input(\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0443\u0431\u043b\u0435\u0439: \")) usd_amount = float(input(\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043b\u043b\u0430\u0440\u043e\u0432: \")) eur_amount = float(input(\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0435\u0432\u0440\u043e: \"))  # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f portfolio = {'RUB': rub_amount, 'USD': usd_amount, 'EUR': eur_amount} # \u0420\u0430\u0441\u0447\u0435\u0442 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f portfolio_values = portfolio_value(simulated_rates, portfolio)<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0447\u0435\u0440\u0435\u0437 input \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0439 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c \u0432 RUB, EUR, USD <\/p>\n<\/p>\n<p>\u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c \u0438\u0437 1 \u0434\u043e\u043b\u043b\u0430\u0440\u0430 \u0432\u044b\u0431\u0440\u0430\u043b \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 var \u0438 cvar \u0434\u0430\u043b\u044c\u0448\u0435<\/p>\n<\/div>\n<\/details>\n<h4>\u0420\u0430\u0441\u0447\u0435\u0442 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0438 \u0440\u0438\u0441\u043a\u043e\u0432<\/h4>\n<ol start=\"6\">\n<li>\n<p><strong>\u0420\u0430\u0441\u0447\u0435\u0442 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0438 \u0440\u0438\u0441\u043a\u043e\u0432<\/strong>: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u0443\u0440\u0441\u044b \u0432\u0430\u043b\u044e\u0442 \u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0430\u043b\u044e\u0442 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0440\u0438\u0441\u043a\u0430 (VaR \u0438 CVaR).<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">cvar = calculate_cvar(portfolio_values) print(f\"\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0438\u0441\u043a \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f (95% \u0434\u043e\u0432\u0435\u0440): {cvar}\")<\/code><\/pre>\n<p>\u041e\u0442\u0432\u0435\u0442:<\/p>\n<\/p>\n<\/div>\n<\/details>\n<h4>\u0410\u043d\u0430\u043b\u0438\u0437 \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432<\/h4>\n<ol start=\"7\">\n<li>\n<p><strong>\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong>: \u041f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u041a\u043e\u043b\u043c\u043e\u0433\u043e\u0440\u043e\u0432\u0430-\u0421\u043c\u0438\u0440\u043d\u043e\u0432\u0430 \u0442\u0435\u0441\u0442 \u0438 t-\u0442\u0435\u0441\u0442 \u0434\u043b\u044f \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u0432\u044b\u0431\u043e\u0440\u043e\u043a. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0438 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u0443\u0440\u0441\u0430\u043c \u0432\u0430\u043b\u044e\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u044b\u0432\u043e\u0434\u044b \u0438 \u0434\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b<\/strong>: \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0434\u043b\u044f \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442 \u043d\u0430 \u043a\u043e\u043d\u0435\u0446 \u043f\u0435\u0440\u0438\u043e\u0434\u0430 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0439, \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043a\u043e\u043b\u0435\u0431\u0430\u043d\u0438\u044f\u0445 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0433\u043e\u0434<\/p>\n<pre><code class=\"python\">data_recent = yf.download(\"USDRUB=X EURRUB=X\", start=\"2023-04-12\", end=\"2024-04-13\")['Close'].dropna() data_recent_usd = data_recent['USDRUB=X'].dropna() data_recent_eur = data_recent['EURRUB=X'].dropna()<\/code><\/pre>\n<pre><code class=\"python\">real_data_last_year = data_recent_usd[-days:] simulated_data_first_path = simulated_rates['USD'][:, 0]  ks_stat, p_value_ks = ks_2samp(real_data_last_year, simulated_data_first_path) t_stat, p_value_t = ttest_ind(real_data_last_year, simulated_data_first_path, equal_var=False)  print(f\"KS Statistic: {ks_stat}, P-value (KS-test): {p_value_ks}\") print(f\"T-statistic: {t_stat}, P-value (T-test): {p_value_t}\")<\/code><\/pre>\n<p>\u041e\u0442\u0432\u0435\u0442: <\/p>\n<\/p>\n<p>\u041e\u0431\u0430 \u0442\u0435\u0441\u0442\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0435 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u041d\u041e&#8230;<\/p>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u043b\u044f \u0434\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">usd_confidence_interval = calculate_confidence_interval(simulated_rates['USD'][-1, :]) eur_confidence_interval = calculate_confidence_interval(simulated_rates['EUR'][-1, :])  print(f\"\u0414\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b 95% \u0434\u043b\u044f \u043a\u0443\u0440\u0441\u0430 \u0434\u043e\u043b\u043b\u0430\u0440\u0430: {usd_confidence_interval}\") print(f\"\u0414\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b 95% \u0434\u043b\u044f \u043a\u0443\u0440\u0441\u0430 \u0435\u0432\u0440\u043e: {eur_confidence_interval}\")<\/code><\/pre>\n<p>\u041e\u0442\u0432\u0435\u0442:<\/p>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 plt.figure(figsize=(14, 7)) plt.plot(usd_rates.index, usd_rates,           label='\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435(2013-01-01 - 2023-04-12)') plt.plot(data_recent_usd.index, data_recent_usd,           label='\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (2023-04-13 - 2024-04-13)', color='green', alpha=0.7) plt.plot(pd.date_range(start=usd_rates.index[-1], periods=days, freq='B'),          simulated_rates['USD'][:, 0], label='\u0421\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435', color='orange', alpha=0.7) plt.legend() plt.title('\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0435 vs \u0421\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 USD\/RUB \u043a\u0443\u0440\u0441\u044b') plt.xlabel('\u0414\u0430\u0442\u0430') plt.ylabel('\u041a\u0443\u0440\u0441') plt.savefig('RUBUSD.png') plt.show()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/317\/40c\/efc\/31740cefc6e3d887f8dbdf940761cf3e.png\" width=\"1400\" height=\"700\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/317\/40c\/efc\/31740cefc6e3d887f8dbdf940761cf3e.png\"\/><\/figure>\n<pre><code class=\"python\"># \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 plt.figure(figsize=(14, 7)) plt.plot(eur_rates.index, eur_rates,           label='\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435(2013-01-01 - 2023-04-12)') plt.plot(data_recent_eur.index, data_recent_eur,           label='\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (2023-04-13 - 2023-04-13)', color='green', alpha=0.7) plt.plot(pd.date_range(start=eur_rates.index[-1], periods=days, freq='B'),          simulated_rates['EUR'][:, 0], label='\u0421\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435', color='orange', alpha=0.7) plt.legend() plt.title('\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0435 vs \u0421\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 EUR\/RUB \u043a\u0443\u0440\u0441\u044b') plt.xlabel('\u0414\u0430\u0442\u0430') plt.ylabel('\u041a\u0443\u0440\u0441') plt.savefig('RUBEUR.png') plt.show()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d4c\/955\/cfd\/d4c955cfd9a417caba93ddb187124dc7.png\" width=\"1400\" height=\"700\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d4c\/955\/cfd\/d4c955cfd9a417caba93ddb187124dc7.png\"\/><\/figure>\n<pre><code class=\"python\">plt.figure(figsize=(10, 6)) for i in range(15):     plt.plot(simulated_rates['USD'][:, i], linewidth=1, alpha=0.8) plt.title('\u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0440\u0430\u0435\u043a\u0442\u043e\u0440\u0438\u0439 \u043e\u0431\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u0434\u043e\u043b\u043b\u0430\u0440\u0430 \u043a \u0440\u0443\u0431\u043b\u044e') plt.xlabel('\u0414\u043d\u0438') plt.ylabel('\u041a\u0443\u0440\u0441') plt.show()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7f5\/d56\/f89\/7f5d56f89f7fc024729ec94578a4d2a9.png\" width=\"1053\" height=\"683\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7f5\/d56\/f89\/7f5d56f89f7fc024729ec94578a4d2a9.png\"\/><\/figure>\n<pre><code class=\"python\">plt.figure(figsize=(10, 6)) for i in range(15):     plt.plot(simulated_rates['EUR'][:, i], linewidth=1, alpha=0.8) plt.title('\u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0440\u0430\u0435\u043a\u0442\u043e\u0440\u0438\u0439 \u043e\u0431\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u0435\u0432\u0440\u043e \u043a \u0440\u0443\u0431\u043b\u044e') plt.xlabel('\u0414\u043d\u0438') plt.ylabel('\u041a\u0443\u0440\u0441') plt.show()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1f2\/c4b\/d11\/1f2c4bd119c41c6941fd2188de3301bb.png\" width=\"1053\" height=\"678\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1f2\/c4b\/d11\/1f2c4bd119c41c6941fd2188de3301bb.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p><strong>\u0411\u043e\u043d\u0443\u0441<\/strong><\/p>\n<p>\u0421\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u043b\u0430\u0440\u0430 \u043d\u0430 \u0433\u043e\u0434 \u0432\u043f\u0435\u0440\u0435\u0434 (04.2024 &#8212; 04.2025]<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u043e\u0433\u043d\u043e\u0437 \u043d\u0430 \u0433\u043e\u0434 \u0432\u043f\u0435\u0440\u0435\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">historical_rates_pred = {'USD': data_recent_usd, 'EUR': data_recent_eur} days_pred= 252 simulations_pred = 1000000 # \u0420\u0430\u0441\u0447\u0435\u0442 \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f drifts_pred = {} volatilities_pred = {} for currency_pred, rates_pred in historical_rates_pred.items():     drifts_pred[currency_pred], volatilities_pred[currency_pred] = calculate_drift_volatility(rates_pred) usd_log_returns_pred = np.log(usd_rates \/ usd_rates.shift(1)).dropna() eur_log_returns_pred = np.log(eur_rates \/ eur_rates.shift(1)).dropna()  usd_drift_garch_pred, usd_volatility_garch_pred = fit_garch_model(usd_log_returns_pred) eur_drift_garch_pred, eur_volatility_garch_pred = fit_garch_model(eur_log_returns_pred)  # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0434\u0440\u0435\u0439\u0444\u043e\u0432 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e drifts_pred['USD'] = usd_drift_garch_pred drifts_pred['EUR'] = eur_drift_garch_pred volatilities_pred['USD'] = usd_volatility_garch_pred volatilities_pred['EUR'] = eur_volatility_garch_pred # \u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442 simulated_rates_pred = simulate_exchange_rates(historical_rates_pred, days_pred, simulations_pred, drifts_pred, volatilities_pred)  # \u0412\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c rub_amount_pred = float(input(\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0443\u0431\u043b\u0435\u0439: \")) usd_amount_pred = float(input(\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043b\u043b\u0430\u0440\u043e\u0432: \")) eur_amount_pred = float(input(\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0435\u0432\u0440\u043e: \"))  # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f portfolio_pred = {'RUB': rub_amount_pred, 'USD': usd_amount_pred, 'EUR': eur_amount_pred} # \u0420\u0430\u0441\u0447\u0435\u0442 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f portfolio_values_pred = portfolio_value(simulated_rates_pred, portfolio_pred)<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044c \u0441 1000 USD<\/p>\n<pre><code class=\"python\">cvar_pred = calculate_cvar(portfolio_values_pred) print(f\"\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0438\u0441\u043a \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f (95% \u0434\u043e\u0432\u0435\u0440): {cvar_pred}\")<\/code><\/pre>\n<p>\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0438\u0441\u043a \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f (95% \u0434\u043e\u0432\u0435\u0440): 71827.22023513853<\/p>\n<pre><code class=\"python\">usd_confidence_interval_pred = calculate_confidence_interval(simulated_rates_pred['USD'][-1, :]) eur_confidence_interval_pred = calculate_confidence_interval(simulated_rates_pred['EUR'][-1, :]) print(f\"\u0414\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b 95% \u0434\u043b\u044f \u043a\u0443\u0440\u0441\u0430 \u0434\u043e\u043b\u043b\u0430\u0440\u0430: {usd_confidence_interval_pred }\") print(f\"\u0414\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b 95% \u0434\u043b\u044f \u043a\u0443\u0440\u0441\u0430 \u0435\u0432\u0440\u043e: {eur_confidence_interval_pred }\")<\/code><\/pre>\n<p>\u0414\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b 95% \u0434\u043b\u044f \u043a\u0443\u0440\u0441\u0430 \u0434\u043e\u043b\u043b\u0430\u0440\u0430: (72.63404780533205, 116.80234915827717) <\/p>\n<p>\u0414\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b 95% \u0434\u043b\u044f \u043a\u0443\u0440\u0441\u0430 \u0435\u0432\u0440\u043e: (94.25965585147713, 104.5288904591821)<\/p>\n<pre><code class=\"python\">plt.figure(figsize=(14, 7)) plt.plot(pd.date_range(start=data_recent_usd.index[-1], periods=days, freq='B'),          simulated_rates_pred['USD'][:, 0], label='\u0421\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435', color='blue', alpha=0.7) plt.legend() plt.title('\u0421\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 USD\/RUB \u043a\u0443\u0440\u0441 \u043d\u0430 \u0433\u043e\u0434') plt.xlabel('\u0414\u0430\u0442\u0430') plt.ylabel('\u041a\u0443\u0440\u0441') plt.grid() plt.savefig('RUBUSD_pred.png') plt.show()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e39\/5e4\/552\/e395e4552a136c47d070c648f9f52f85.png\" width=\"1124\" height=\"590\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e39\/5e4\/552\/e395e4552a136c47d070c648f9f52f85.png\"\/><\/figure>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e \u0438 \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0449\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f. \u041e\u043d \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0438 \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432, \u043f\u043e\u0434\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u043e\u043c \u0438 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.  <\/p>\n<\/div>\n<\/details>\n<p><strong>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/strong><\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u043b\u0438 \u043e\u0431\u0448\u0438\u0440\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0430 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e, \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u0413\u0410\u0420\u0427 \u0434\u043b\u044f \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0414\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u043a\u0443\u0440\u0441\u043e\u0432 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 &#8212; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e, \u043e\u0431 \u044d\u0442\u043e\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a-\u0441 \u0438 t \u0442\u0435\u0441\u0442\u043e\u0432, \u043d\u043e \u0432\u0441\u0451 \u0436\u0435 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u0432 \u0432\u044b\u0448\u043b\u043e \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e.<\/p>\n<p>\u042d\u0442\u043e \u043b\u0438\u0448\u044c \u043f\u0440\u0438\u043c\u0435\u0440 &#171;\u043d\u0430 \u043f\u0430\u043b\u044c\u0446\u0430\u0445&#187;  \u0441 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u043a\u043e\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0436\u0435\u0447\u044c \u0437\u0430\u0442\u0435\u0439\u043b\u0438\u0432\u044b\u0435 \u0443\u043c\u044b \u043a \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044e \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043d\u0443 \u0438 \u043f\u043e\u0445\u0430\u0440\u0434\u043a\u043e\u0434\u0438\u0442\u044c \u0442\u043e\u0436\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u044f\u0442\u043d\u043e. <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/810037\/\"> https:\/\/habr.com\/ru\/articles\/810037\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>\u041c\u0435\u0442\u043e\u0434 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e <\/strong>\u2014 \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u0445 \u043d\u0430\u0443\u043a\u0438 \u0438 \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0438\u0438. \u0412 \u0444\u0438\u043d\u0430\u043d\u0441\u0430\u0445, \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043a\u0443\u0440\u0441 \u0432\u0430\u043b\u044e\u0442 \u0438\u043b\u0438 \u0430\u043a\u0446\u0438\u0439. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u043e \u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0438\u0441\u0445\u043e\u0434\u043e\u0432, \u0447\u0442\u043e \u043a\u0440\u0430\u0439\u043d\u0435 \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0438\u0441\u043a\u0430\u043c\u0438 \u0438 \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u043c\u0435\u0442\u043e\u0434\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 (\u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0439), \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u0445 \u0438\u0437 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0443\u0440\u0441\u0430 \u0432\u0430\u043b\u044e\u0442, \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0438 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043b\u0435\u0431\u0430\u043d\u0438\u044f \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u0445 \u043f\u0430\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0439 \u0430\u0441\u043f\u0435\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e \u0432 \u0444\u0438\u043d\u0430\u043d\u0441\u0430\u0445 \u2014 \u044d\u0442\u043e \u0435\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0434\u0440\u0435\u0439\u0444 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442. \u0414\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u044c (Generalized Autoregressive Conditional Heteroskedasticity). \u0413\u0410\u0420\u0427 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0438 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u043c \u043f\u0440\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432. <\/p>\n<p>\u0418\u0434\u0435\u0439\u043d\u043e \u043a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f<u> \u0431\u0435\u0437 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043b\u0438\u0431<\/u>, \u0442\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0434\u043b\u044f \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0430\u043f\u043f\u0430\u0440\u0430\u0442\u043e\u043c.<\/p>\n<p><strong>\u041f\u0440\u043e\u0435\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b:<\/strong><\/p>\n<ul>\n<li>\n<p><code>yfinance<\/code>\u00a0\u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><code>numpy<\/code>\u00a0\u0438\u00a0<code>pandas<\/code>\u00a0\u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><code>matplotlib<\/code>\u00a0\u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><code>scipy<\/code>\u00a0\u0438\u00a0<code>arch<\/code>\u00a0\u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0418\u043c\u043f\u043e\u0440\u0442 \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>\u0414\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u043a\u0443\u0440\u0441\u0430 \u0432\u0430\u043b\u044e\u0442 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c USD\/RUB \u0438 EUR\/RUB, \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>yfinance<\/code>. \u042d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u043e\u0441\u043d\u043e\u0432\u0443 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 2013 \u0433\u043e\u0434\u0430 \u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044f \u0430\u043f\u0440\u0435\u043b\u0435\u043c 2023 \u0433\u043e\u0434\u0430. \u0421\u0435\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 &#171;\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e&#187; \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043a\u0443\u0440\u0441\u0430 \u0438 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u0430. <\/p>\n<p>\u042f \u0431\u0440\u0430\u043b \u043e\u0442\u0440\u0435\u0437\u043a\u0438 [2004;2023], [2008;2020], [2010;2023]\u0438 \u0442.\u0434, \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0441\u044f \u0441\u0445\u043e\u0436\u0438\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0440\u044f\u0434\u043e\u043c &#171;\u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0433\u043e&#187; \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u043b\u0430\u0440\u0430. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043b. \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c!<\/p>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0434\u043d\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u044b \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u043e \u0434\u0430\u043d\u043d\u044b\u0445<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u0430\u0445 data = yf.download(\"USDRUB=X EURRUB=X\", start=\"2013-01-01\", end=\"2023-04-13\")<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p>\u0418\u0437 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u0443\u0440\u0441 \u043d\u0430 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 <\/p>\n<pre><code class=\"python\">usd_rates = data['Close']['USDRUB=X'].dropna() eur_rates = data['Close']['EURRUB=X'].dropna()<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p><em>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438<\/em><\/p>\n<h3>1. \u0424\u0443\u043d\u043a\u0446\u0438\u044f simulate_exchange_rates<\/h3>\n<p>\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b. \u041e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0431\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f (GBM), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u043e\u043c \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0446\u0435\u043d \u0438\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432.<\/p>\n<p><strong>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 GBM:<\/strong><\/p>\n<p>\u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p>( St ) \u2014 \u0446\u0435\u043d\u0430 \u0430\u043a\u0442\u0438\u0432\u0430 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 ( t ),<\/p>\n<\/li>\n<li>\n<p>( S0 ) \u2014 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0446\u0435\u043d\u0430 \u0430\u043a\u0442\u0438\u0432\u0430,<\/p>\n<\/li>\n<li>\n<p>( <em>\u03bc<\/em> ) \u2014 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0434\u0440\u0435\u0439\u0444 (\u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438),<\/p>\n<\/li>\n<li>\n<p>( <em>\u03c3<\/em>  ) \u2014 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438 (\u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c),<\/p>\n<\/li>\n<li>\n<p>( Wt ) \u2014 \u0432\u0438\u043d\u0435\u0440\u043e\u0432\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 (\u0438\u043b\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0431\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0435 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435).<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u0414\u043d\u0435\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u044b \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a <\/p>\n<\/li>\n<\/ul>\n<p>\u0433\u0434\u0435 ( Z ) \u2014 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/p>\n<ul>\n<li>\n<p>\u042d\u0442\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u044b \u0437\u0430\u0442\u0435\u043c \u0443\u043c\u043d\u043e\u0436\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u0430 \u0432\u0430\u043b\u044e\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u043e\u0432 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0434\u043d\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def simulate_exchange_rates(historical_rates, days, simulations, drifts, volatilities):     dt = 1 \/ days     simulated_rates = {}     for currency, rates in historical_rates.items():         drift = drifts[currency]         volatility = volatilities[currency]         daily_returns = np.exp((drift - 0.5 * volatility**2) * dt +                                 volatility * np.random.normal(0, np.sqrt(dt), (days, simulations)))         simulation = rates.iloc[-1] * np.cumprod(daily_returns, axis=0)         simulated_rates[currency] = simulation     return simulated_rates<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>2. \u0424\u0443\u043d\u043a\u0446\u0438\u044f portfolio_value<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>portfolio_value<\/code> \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0432 \u0440\u0443\u0431\u043b\u044f\u0445, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u0443\u0440\u0441\u044b \u0432\u0430\u043b\u044e\u0442 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435. \u0421\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a:<\/p>\n<p>\u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p>( xi ) \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0430\u043b\u044e\u0442\u044b ( i ) \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435,<\/p>\n<\/li>\n<li>\n<p>( Si(T) ) \u2014 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0443\u0440\u0441 \u0432\u0430\u043b\u044e\u0442\u044b ( i ) \u043d\u0430 \u043a\u043e\u043d\u0435\u0446 \u043f\u0435\u0440\u0438\u043e\u0434\u0430 ( T ),<\/p>\n<\/li>\n<li>\n<p>( n ) \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0430\u043b\u044e\u0442 \u0432 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u0435.<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def portfolio_value(simulated_rates, portfolio):     simulations = next(iter(simulated_rates.values())).shape[1]     values = np.full(simulations, portfolio.get('RUB', 0), dtype=float)       for currency, amount in portfolio.items():         if currency != 'RUB':             values += amount * simulated_rates[currency][-1, :]     return values<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>3. \u0424\u0443\u043d\u043a\u0446\u0438\u0438 calculate_var \u0438 calculate_cvar<\/h3>\n<ul>\n<li>\n<p><strong>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <\/strong><code>calculate_var<\/code> \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u0442 Value at Risk (VaR) \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 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u043e\u0442\u0435\u0440\u044e \u0432 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0434\u043e\u0432\u0435\u0440\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 95%). VaR \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a:<\/p>\n<\/li>\n<\/ul>\n<p>\u0433\u0434\u0435 V (\u03b1) \u2014 \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u03b1.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def calculate_var(portfolio_values, confidence_level=0.95):     sorted_values = np.sort(portfolio_values)     index = int((1 - confidence_level) * len(sorted_values))     return sorted_values[index]<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<ul>\n<li>\n<p><strong>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <\/strong><code>calculate_cvar<\/code> \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 Conditional Value at Risk (CVaR), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0440\u0435\u0434\u043d\u044e\u044e \u043f\u043e\u0442\u0435\u0440\u044e, \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u044e\u0449\u0443\u044e VaR:<\/p>\n<\/li>\n<\/ul>\n<p>\u0433\u0434\u0435 ( V<em>u<\/em>) \u2014 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u0442\u0444\u0435\u043b\u044f \u0432 \u0442\u043e\u0447\u043a\u0435 \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u044f (u).<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def calculate_cvar(portfolio_values, confidence_level=0.95):     var = calculate_var(portfolio_values, confidence_level)     cvar = portfolio_values[portfolio_values &lt;= var].mean()     return cvar<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>4. \u0424\u0443\u043d\u043a\u0446\u0438\u044f calculate_confidence_interval<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>calculate_confidence_interval<\/code> \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0434\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0434\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0432 \u043a\u0430\u043a\u043e\u043c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u043a\u043e\u043b\u0435\u0431\u0430\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p><strong>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/strong><\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0434\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u0435\u0439. \u041e\u043d \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0448\u0430\u0433\u0430\u0445:<\/p>\n<ul>\n<li>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u044f\u043c, \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0434\u043e\u0432\u0435\u0440\u0438\u044f ( \u03b1 ).<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0446\u0435\u043d\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0435\u0440\u0445\u043d\u044e\u044e \u0438 \u043d\u0438\u0436\u043d\u044e\u044e \u0433\u0440\u0430\u043d\u0438\u0446\u0443 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u0443\u0440\u0441\u0430 \u0432\u0430\u043b\u044e\u0442\u044b \u0441 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e ( \u03b1 ).<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def calculate_confidence_interval(simulated_data, confidence_level=0.95):     lower_percentile = (1 - confidence_level) \/ 2 * 100     upper_percentile = (1 - (1 - confidence_level) \/ 2) * 100     lower_bound = np.percentile(simulated_data, lower_percentile)     upper_bound = np.percentile(simulated_data, upper_percentile)     return lower_bound, upper_bound<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>5. \u0424\u0443\u043d\u043a\u0446\u0438\u044f calculate_drift_volatility<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>calculate_drift_volatility<\/code> \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043a\u0443\u0440\u0441\u0430\u0445 \u0432\u0430\u043b\u044e\u0442. \u042d\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0446\u0435\u043d \u043f\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0431\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p><strong>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0441\u0447\u0435\u0442\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0418\u0437 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438:<\/p>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u0414\u0440\u0435\u0439\u0444 ( <em>\u03bc<\/em> ) \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c (<em>\u03c3<\/em>) \u2014 \u044d\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u044d\u0442\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0435\u0435 \u043e\u043a\u043d\u043e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 252 \u0434\u043d\u044f, \u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0442\u043e\u0440\u0433\u043e\u0432\u044b\u0445 \u0434\u043d\u0435\u0439 \u0432 \u0433\u043e\u0434\u0443), \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0440\u044b\u043d\u043a\u0435 \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u043e\u043b\u0435\u0435 \u0430\u0434\u0430\u043f\u0442\u0438\u0432\u043d\u043e\u0439 \u043a \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def calculate_drift_volatility(rates, lookback_period=252):     log_returns = np.log(rates \/ rates.shift(1)).dropna()     rolling_mean = log_returns.rolling(window=lookback_period).mean()     rolling_std = log_returns.rolling(window=lookback_period).std()     drift = rolling_mean.iloc[-1]     volatility = rolling_std.iloc[-1]     return drift, volatility<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>6. \u0424\u0443\u043d\u043a\u0446\u0438\u044f fit_garch_model<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>fit_garch_model<\/code> \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043e\u0446\u0435\u043d\u043a\u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u0438. \u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0434\u043b\u044f \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432, \u0433\u0434\u0435 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439, \u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c.<\/p>\n<p><strong>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0434\u0433\u043e\u043d\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u2014 \u044d\u0442\u043e \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0413\u0410\u0420\u0427 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 ( p ) \u0438 ( q ), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0440\u044f\u0434\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0438 \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0435\u0433\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0434\u0433\u043e\u043d\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043e\u0446\u0435\u043d\u043a\u0438 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u043e\u0439 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f, \u0447\u0442\u043e \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043a\u043e\u043b\u0435\u0431\u0430\u043d\u0438\u0439 \u043a\u0443\u0440\u0441\u043e\u0432 \u0432\u0430\u043b\u044e\u0442.<\/p>\n<\/li>\n<\/ul>\n<p>\u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0440\u0438\u0441\u043a \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0445 \u0440\u044b\u043d\u043a\u043e\u0432.  <\/p>\n<h3>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e \u0434\u043b\u044f \u0432\u0430\u043b\u044e\u0442\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u043e\u0432<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0432\u0441\u0435\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 \u044d\u0442\u0430\u043f\u0443 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u2014 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e. \u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0448\u0430\u0433\u043e\u0432:<\/p>\n<h4>\u0420\u0430\u0441\u0447\u0435\u0442 \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h4>\n<ol>\n<li>\n<p><strong>\u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0435\u0439<\/strong>: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0443\u0440\u0441\u043e\u0432 USD \u0438 EUR, \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0438. \u042d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0430\u0441\u0447\u0435\u0442 \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u0445 \u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0439<\/strong>: \u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u043e\u0445\u043e\u0434\u043d\u043e\u0441\u0442\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0435\u0433\u043e \u043e\u043a\u043d\u0430 \u0432 252 \u0434\u043d\u044f (\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0440\u0433\u043e\u0432\u044b\u0445 \u0434\u043d\u0435\u0439 \u0432 \u0433\u043e\u0434\u0443) \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u0435 \u0441\u0440\u0435\u0434\u043d\u0438\u0435 \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u044f. \u042d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0440\u0435\u0439\u0444 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u0421\u0435\u043a\u0440\u0435\u0442\u0438\u043a<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0412\u043e\u043e\u0431\u0449\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u044f calculate_confidence_interval \u0431\u044b\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043c\u043d\u043e\u044e \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044f \u0443\u0437\u043d\u0430\u043b \u043f\u0440\u043e GARCH, \u0442\u0430\u043a \u0447\u0442\u043e \u044f \u0438\u0437 \u0434\u043e\u0441\u0430\u0434\u044b \u0440\u0435\u0448\u0438\u043b \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0440\u0435\u0439\u0444\u0430 \u0438 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438<\/p>\n<\/div>\n<\/details>\n<h4>\u041f\u043e\u0434\u0433\u043e\u043d\u043a\u0430 \u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u0438<\/h4>\n<ol start=\"3\">\n<li>\n<p><strong>\u041f\u043e\u0434\u0433\u043e\u043d\u043a\u0430 \u0413\u0410\u0420\u0427 \u043c\u043e\u0434\u0435\u043b\u0438<\/strong>: \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-374545","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/374545","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=374545"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/374545\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=374545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=374545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=374545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}