{"id":1026397,"date":"2024-12-31T10:42:16","date_gmt":"2024-12-31T02:42:16","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1026397.html"},"modified":"2024-12-31T10:42:18","modified_gmt":"2024-12-31T02:42:18","slug":"python%e5%a6%82%e4%bd%95%e4%bd%bf%e6%96%b9%e5%b7%ae%e6%9c%80%e5%b0%8f%e8%b5%84%e4%ba%a7%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1026397.html","title":{"rendered":"python\u5982\u4f55\u4f7f\u65b9\u5dee\u6700\u5c0f\u8d44\u4ea7\u914d\u7f6e"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/209e562a-f3d8-42f9-80b6-98ab9250f19d.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u4f7f\u65b9\u5dee\u6700\u5c0f\u8d44\u4ea7\u914d\u7f6e\" \/><\/p>\n<p><p> <strong>Python\u5982\u4f55\u4f7f\u65b9\u5dee\u6700\u5c0f\u8d44\u4ea7\u914d\u7f6e<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u6295\u8d44\u7ec4\u5408\u7ba1\u7406\u4e2d\uff0c\u4f7f\u65b9\u5dee\u6700\u5c0f\u5316\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u4ee5\u964d\u4f4e\u6295\u8d44\u7ec4\u5408\u7684\u98ce\u9669\u3002<strong>\u65b9\u5dee\u6700\u5c0f\u5316\u3001\u8d44\u4ea7\u914d\u7f6e\u3001Python\u4ee3\u7801\u3001\u6295\u8d44\u7ec4\u5408\u4f18\u5316\u3001\u73b0\u4ee3\u6295\u8d44\u7ec4\u5408\u7406\u8bba<\/strong>\u7b49\u662f\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u7684\u5173\u952e\u70b9\u3002\u65b9\u5dee\u6700\u5c0f\u5316\u7684\u8d44\u4ea7\u914d\u7f6e\u662f\u901a\u8fc7\u51cf\u5c11\u6295\u8d44\u7ec4\u5408\u4e2d\u5404\u8d44\u4ea7\u7684\u6ce2\u52a8\u6027\uff0c\u4ece\u800c\u964d\u4f4e\u6574\u4f53\u98ce\u9669\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u5b9e\u73b0\u65b9\u5dee\u6700\u5c0f\u8d44\u4ea7\u914d\u7f6e\uff0c\u5e76\u5bf9\u5176\u4e2d\u7684\u6838\u5fc3\u6b65\u9aa4\u8fdb\u884c\u6df1\u5165\u63a2\u8ba8\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u73b0\u4ee3\u6295\u8d44\u7ec4\u5408\u7406\u8bba\uff08MPT\uff09<\/h3>\n<\/p>\n<p><p>\u73b0\u4ee3\u6295\u8d44\u7ec4\u5408\u7406\u8bba\uff08Modern Portfolio Theory, MPT\uff09\u662f\u7531\u54c8\u91cc\u00b7\u9a6c\u79d1\u7ef4\u8328\u57281952\u5e74\u63d0\u51fa\u7684\u3002\u5176\u6838\u5fc3\u601d\u60f3\u662f\u901a\u8fc7\u5206\u6563\u6295\u8d44\u6765\u4f18\u5316\u7ec4\u5408\u7684\u98ce\u9669\u548c\u56de\u62a5\u3002\u5177\u4f53\u6765\u8bf4\uff0cMPT\u901a\u8fc7\u8ba1\u7b97\u5404\u8d44\u4ea7\u7684\u9884\u671f\u6536\u76ca\u3001\u98ce\u9669\uff08\u6807\u51c6\u5dee\u6216\u65b9\u5dee\uff09\u4ee5\u53ca\u8d44\u4ea7\u4e4b\u95f4\u7684\u534f\u65b9\u5dee\u77e9\u9635\uff0c\u6765\u786e\u5b9a\u6700\u4f18\u7684\u8d44\u4ea7\u914d\u7f6e\u3002<\/p>\n<\/p>\n<p><h4>1.1 \u9884\u671f\u6536\u76ca\u548c\u98ce\u9669<\/h4>\n<\/p>\n<p><p>\u9884\u671f\u6536\u76ca\u662f\u6307\u6295\u8d44\u7ec4\u5408\u5728\u672a\u6765\u4e00\u6bb5\u65f6\u95f4\u5185\u53ef\u80fd\u83b7\u5f97\u7684\u5e73\u5747\u6536\u76ca\u3002\u98ce\u9669\u901a\u5e38\u7528\u65b9\u5dee\u6216\u6807\u51c6\u5dee\u6765\u8868\u793a\uff0c\u53cd\u6620\u4e86\u6536\u76ca\u7684\u6ce2\u52a8\u6027\u3002\u65b9\u5dee\u8d8a\u5927\uff0c\u98ce\u9669\u8d8a\u9ad8\u3002<\/p>\n<\/p>\n<p><h4>1.2 \u534f\u65b9\u5dee\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u534f\u65b9\u5dee\u77e9\u9635\u662f\u63cf\u8ff0\u4e0d\u540c\u8d44\u4ea7\u4e4b\u95f4\u7684\u534f\u65b9\u5dee\u7684\u77e9\u9635\uff0c\u5b83\u53cd\u6620\u4e86\u8d44\u4ea7\u4e4b\u95f4\u7684\u76f8\u5173\u6027\u3002\u534f\u65b9\u5dee\u77e9\u9635\u5728\u4f18\u5316\u6295\u8d44\u7ec4\u5408\u65f6\u975e\u5e38\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7406\u89e3\u5982\u4f55\u901a\u8fc7\u7ec4\u5408\u4e0d\u540c\u7684\u8d44\u4ea7\u6765\u964d\u4f4e\u6574\u4f53\u98ce\u9669\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001Python\u5b9e\u73b0\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u5b9e\u73b0\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e\uff0c\u6211\u4eec\u9700\u8981\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u83b7\u53d6\u8d44\u4ea7\u7684\u5386\u53f2\u4ef7\u683c\u6570\u636e<\/li>\n<li>\u8ba1\u7b97\u8d44\u4ea7\u7684\u6536\u76ca\u7387\u548c\u534f\u65b9\u5dee\u77e9\u9635<\/li>\n<li>\u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u627e\u5230\u4f7f\u65b9\u5dee\u6700\u5c0f\u7684\u8d44\u4ea7\u6743\u91cd<\/li>\n<\/ol>\n<p><h4>2.1 \u83b7\u53d6\u8d44\u4ea7\u7684\u5386\u53f2\u4ef7\u683c\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>yfinance<\/code>\u5e93\u6765\u83b7\u53d6\u8d44\u4ea7\u7684\u5386\u53f2\u4ef7\u683c\u6570\u636e\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import yfinance as yf<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u5b9a\u4e49\u8d44\u4ea7\u5217\u8868<\/strong><\/h2>\n<p>assets = [&#39;AAPL&#39;, &#39;MSFT&#39;, &#39;GOOGL&#39;, &#39;AMZN&#39;]<\/p>\n<h2><strong>\u83b7\u53d6\u8d44\u4ea7\u7684\u5386\u53f2\u4ef7\u683c\u6570\u636e<\/strong><\/h2>\n<p>data = yf.download(assets, start=&#39;2020-01-01&#39;, end=&#39;2023-01-01&#39;)[&#39;Adj Close&#39;]<\/p>\n<h2><strong>\u6253\u5370\u6570\u636e<\/strong><\/h2>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2 \u8ba1\u7b97\u8d44\u4ea7\u7684\u6536\u76ca\u7387\u548c\u534f\u65b9\u5dee\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u8ba1\u7b97\u8d44\u4ea7\u7684\u6bcf\u65e5\u6536\u76ca\u7387\u548c\u534f\u65b9\u5dee\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u6bcf\u65e5\u6536\u76ca\u7387<\/p>\n<p>returns = data.pct_change().dropna()<\/p>\n<h2><strong>\u8ba1\u7b97\u534f\u65b9\u5dee\u77e9\u9635<\/strong><\/h2>\n<p>cov_matrix = returns.cov()<\/p>\n<h2><strong>\u6253\u5370\u534f\u65b9\u5dee\u77e9\u9635<\/strong><\/h2>\n<p>print(cov_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.3 \u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u627e\u5230\u4f7f\u65b9\u5dee\u6700\u5c0f\u7684\u8d44\u4ea7\u6743\u91cd<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>scipy<\/code>\u5e93\u4e2d\u7684\u4f18\u5316\u7b97\u6cd5\u6765\u627e\u5230\u4f7f\u65b9\u5dee\u6700\u5c0f\u7684\u8d44\u4ea7\u6743\u91cd\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>scipy.optimize.minimize<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from scipy.optimize import minimize<\/p>\n<h2><strong>\u5b9a\u4e49\u76ee\u6807\u51fd\u6570\uff08\u6295\u8d44\u7ec4\u5408\u7684\u65b9\u5dee\uff09<\/strong><\/h2>\n<p>def portfolio_variance(weights, cov_matrix):<\/p>\n<p>    return np.dot(weights.T, np.dot(cov_matrix, weights))<\/p>\n<h2><strong>\u5b9a\u4e49\u7ea6\u675f\u6761\u4ef6\uff08\u6743\u91cd\u4e4b\u548c\u4e3a1\uff09<\/strong><\/h2>\n<p>constr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>nts = ({&#39;type&#39;: &#39;eq&#39;, &#39;fun&#39;: lambda x: np.sum(x) - 1})<\/p>\n<h2><strong>\u5b9a\u4e49\u521d\u59cb\u6743\u91cd<\/strong><\/h2>\n<p>init_weights = np.array([0.25, 0.25, 0.25, 0.25])<\/p>\n<h2><strong>\u5b9a\u4e49\u6743\u91cd\u7684\u8fb9\u754c\uff08\u6240\u6709\u6743\u91cd\u57280\u52301\u4e4b\u95f4\uff09<\/strong><\/h2>\n<p>bounds = tuple((0, 1) for asset in range(len(assets)))<\/p>\n<h2><strong>\u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u627e\u5230\u6700\u4f18\u6743\u91cd<\/strong><\/h2>\n<p>result = minimize(portfolio_variance, init_weights, args=(cov_matrix,), method=&#39;SLSQP&#39;, bounds=bounds, constraints=constraints)<\/p>\n<h2><strong>\u6253\u5370\u6700\u4f18\u6743\u91cd<\/strong><\/h2>\n<p>print(result.x)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u627e\u5230\u4f7f\u65b9\u5dee\u6700\u5c0f\u7684\u8d44\u4ea7\u6743\u91cd\uff0c\u4ece\u800c\u5b9e\u73b0\u6700\u4f18\u7684\u8d44\u4ea7\u914d\u7f6e\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u5bf9\u4e0a\u8ff0\u6bcf\u4e2a\u6b65\u9aa4\u8fdb\u884c\u8be6\u7ec6\u63a2\u8ba8\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u7406\u89e3\u548c\u5b9e\u73b0\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u83b7\u53d6\u8d44\u4ea7\u7684\u5386\u53f2\u4ef7\u683c\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u83b7\u53d6\u51c6\u786e\u548c\u5168\u9762\u7684\u8d44\u4ea7\u5386\u53f2\u4ef7\u683c\u6570\u636e\u662f\u5b9e\u73b0\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e\u7684\u7b2c\u4e00\u6b65\u3002\u5e38\u7528\u7684\u6570\u636e\u6e90\u5305\u62ecYahoo Finance\u3001Google Finance\u3001Alpha Vantage\u7b49\u3002\u672c\u6587\u5c06\u4f7f\u7528<code>yfinance<\/code>\u5e93\u6765\u83b7\u53d6\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>3.1 \u5b89\u88c5\u548c\u4f7f\u7528<code>yfinance<\/code><\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5<code>yfinance<\/code>\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install yfinance<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>yfinance<\/code>\u5e93\u6765\u83b7\u53d6\u8d44\u4ea7\u7684\u5386\u53f2\u4ef7\u683c\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import yfinance as yf<\/p>\n<h2><strong>\u5b9a\u4e49\u8d44\u4ea7\u5217\u8868<\/strong><\/h2>\n<p>assets = [&#39;AAPL&#39;, &#39;MSFT&#39;, &#39;GOOGL&#39;, &#39;AMZN&#39;]<\/p>\n<h2><strong>\u83b7\u53d6\u8d44\u4ea7\u7684\u5386\u53f2\u4ef7\u683c\u6570\u636e<\/strong><\/h2>\n<p>data = yf.download(assets, start=&#39;2020-01-01&#39;, end=&#39;2023-01-01&#39;)[&#39;Adj Close&#39;]<\/p>\n<h2><strong>\u6253\u5370\u6570\u636e<\/strong><\/h2>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2 \u6570\u636e\u6e05\u6d17\u548c\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u83b7\u53d6\u6570\u636e\u540e\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u548c\u5904\u7406\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u51c6\u786e\u6027\u548c\u5b8c\u6574\u6027\u3002\u8fd9\u5305\u62ec\u5904\u7406\u7f3a\u5931\u503c\u3001\u8c03\u6574\u65f6\u95f4\u9891\u7387\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u68c0\u67e5\u7f3a\u5931\u503c<\/p>\n<p>print(data.isnull().sum())<\/p>\n<h2><strong>\u586b\u8865\u7f3a\u5931\u503c<\/strong><\/h2>\n<p>data = data.fillna(method=&#39;ffill&#39;)<\/p>\n<h2><strong>\u786e\u4fdd\u6570\u636e\u6ca1\u6709\u7f3a\u5931\u503c<\/strong><\/h2>\n<p>print(data.isnull().sum())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u8ba1\u7b97\u8d44\u4ea7\u7684\u6536\u76ca\u7387\u548c\u534f\u65b9\u5dee\u77e9\u9635<\/h3>\n<\/p>\n<p><p>\u8ba1\u7b97\u8d44\u4ea7\u7684\u6536\u76ca\u7387\u548c\u534f\u65b9\u5dee\u77e9\u9635\u662f\u5b9e\u73b0\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e\u7684\u5173\u952e\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h4>4.1 \u8ba1\u7b97\u6bcf\u65e5\u6536\u76ca\u7387<\/h4>\n<\/p>\n<p><p>\u6bcf\u65e5\u6536\u76ca\u7387\u662f\u6307\u8d44\u4ea7\u5728\u8fde\u7eed\u4e24\u4e2a\u4ea4\u6613\u65e5\u4e4b\u95f4\u7684\u4ef7\u683c\u53d8\u5316\u7387\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>pct_change<\/code>\u51fd\u6570\u6765\u8ba1\u7b97\u6bcf\u65e5\u6536\u76ca\u7387\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u6bcf\u65e5\u6536\u76ca\u7387<\/p>\n<p>returns = data.pct_change().dropna()<\/p>\n<h2><strong>\u6253\u5370\u6bcf\u65e5\u6536\u76ca\u7387<\/strong><\/h2>\n<p>print(returns.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2 \u8ba1\u7b97\u534f\u65b9\u5dee\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u534f\u65b9\u5dee\u77e9\u9635\u53cd\u6620\u4e86\u8d44\u4ea7\u4e4b\u95f4\u7684\u76f8\u5173\u6027\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>cov<\/code>\u51fd\u6570\u6765\u8ba1\u7b97\u534f\u65b9\u5dee\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u534f\u65b9\u5dee\u77e9\u9635<\/p>\n<p>cov_matrix = returns.cov()<\/p>\n<h2><strong>\u6253\u5370\u534f\u65b9\u5dee\u77e9\u9635<\/strong><\/h2>\n<p>print(cov_matrix)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u627e\u5230\u4f7f\u65b9\u5dee\u6700\u5c0f\u7684\u8d44\u4ea7\u6743\u91cd<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u627e\u5230\u4f7f\u65b9\u5dee\u6700\u5c0f\u7684\u8d44\u4ea7\u6743\u91cd\u662f\u5b9e\u73b0\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e\u7684\u6700\u540e\u4e00\u6b65\u3002\u6211\u4eec\u5c06\u4f7f\u7528<code>scipy.optimize.minimize<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<\/p>\n<\/p>\n<p><h4>5.1 \u5b9a\u4e49\u76ee\u6807\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u76ee\u6807\u51fd\u6570\u662f\u6307\u6211\u4eec\u5e0c\u671b\u6700\u5c0f\u5316\u7684\u51fd\u6570\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5e0c\u671b\u6700\u5c0f\u5316\u6295\u8d44\u7ec4\u5408\u7684\u65b9\u5dee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u5b9a\u4e49\u76ee\u6807\u51fd\u6570\uff08\u6295\u8d44\u7ec4\u5408\u7684\u65b9\u5dee\uff09<\/strong><\/h2>\n<p>def portfolio_variance(weights, cov_matrix):<\/p>\n<p>    return np.dot(weights.T, np.dot(cov_matrix, weights))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5.2 \u5b9a\u4e49\u7ea6\u675f\u6761\u4ef6\u548c\u8fb9\u754c<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u7ea6\u675f\u6761\u4ef6\u548c\u8fb9\u754c\uff0c\u4ee5\u786e\u4fdd\u4f18\u5316\u7ed3\u679c\u7684\u5408\u7406\u6027\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5e0c\u671b\u6240\u6709\u6743\u91cd\u4e4b\u548c\u4e3a1\uff0c\u4e14\u6bcf\u4e2a\u6743\u91cd\u57280\u52301\u4e4b\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u7ea6\u675f\u6761\u4ef6\uff08\u6743\u91cd\u4e4b\u548c\u4e3a1\uff09<\/p>\n<p>constraints = ({&#39;type&#39;: &#39;eq&#39;, &#39;fun&#39;: lambda x: np.sum(x) - 1})<\/p>\n<h2><strong>\u5b9a\u4e49\u521d\u59cb\u6743\u91cd<\/strong><\/h2>\n<p>init_weights = np.array([0.25, 0.25, 0.25, 0.25])<\/p>\n<h2><strong>\u5b9a\u4e49\u6743\u91cd\u7684\u8fb9\u754c\uff08\u6240\u6709\u6743\u91cd\u57280\u52301\u4e4b\u95f4\uff09<\/strong><\/h2>\n<p>bounds = tuple((0, 1) for asset in range(len(assets)))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5.3 \u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u627e\u5230\u6700\u4f18\u6743\u91cd<\/h4>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u6211\u4eec\u4f7f\u7528<code>scipy.optimize.minimize<\/code>\u51fd\u6570\u6765\u627e\u5230\u4f7f\u65b9\u5dee\u6700\u5c0f\u7684\u8d44\u4ea7\u6743\u91cd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from scipy.optimize import minimize<\/p>\n<h2><strong>\u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u627e\u5230\u6700\u4f18\u6743\u91cd<\/strong><\/h2>\n<p>result = minimize(portfolio_variance, init_weights, args=(cov_matrix,), method=&#39;SLSQP&#39;, bounds=bounds, constraints=constraints)<\/p>\n<h2><strong>\u6253\u5370\u6700\u4f18\u6743\u91cd<\/strong><\/h2>\n<p>print(result.x)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u9a8c\u8bc1\u548c\u8bc4\u4f30\u4f18\u5316\u7ed3\u679c<\/h3>\n<\/p>\n<p><p>\u5728\u627e\u5230\u6700\u4f18\u6743\u91cd\u540e\uff0c\u6211\u4eec\u9700\u8981\u9a8c\u8bc1\u548c\u8bc4\u4f30\u4f18\u5316\u7ed3\u679c\uff0c\u4ee5\u786e\u4fdd\u5176\u6709\u6548\u6027\u548c\u5408\u7406\u6027\u3002\u8fd9\u5305\u62ec\u8ba1\u7b97\u6295\u8d44\u7ec4\u5408\u7684\u9884\u671f\u6536\u76ca\u3001\u98ce\u9669\uff0c\u4ee5\u53ca\u6bd4\u8f83\u4e0d\u540c\u8d44\u4ea7\u914d\u7f6e\u65b9\u6848\u7684\u8868\u73b0\u3002<\/p>\n<\/p>\n<p><h4>6.1 \u8ba1\u7b97\u6295\u8d44\u7ec4\u5408\u7684\u9884\u671f\u6536\u76ca\u548c\u98ce\u9669<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6700\u4f18\u6743\u91cd\u6765\u8ba1\u7b97\u6295\u8d44\u7ec4\u5408\u7684\u9884\u671f\u6536\u76ca\u548c\u98ce\u9669\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u6295\u8d44\u7ec4\u5408\u7684\u9884\u671f\u6536\u76ca<\/p>\n<p>portfolio_return = np.dot(result.x, returns.mean()) * 252<\/p>\n<h2><strong>\u8ba1\u7b97\u6295\u8d44\u7ec4\u5408\u7684\u65b9\u5dee\u548c\u6807\u51c6\u5dee<\/strong><\/h2>\n<p>portfolio_variance = portfolio_variance(result.x, cov_matrix)<\/p>\n<p>portfolio_std = np.sqrt(portfolio_variance) * np.sqrt(252)<\/p>\n<h2><strong>\u6253\u5370\u7ed3\u679c<\/strong><\/h2>\n<p>print(f&quot;\u6295\u8d44\u7ec4\u5408\u7684\u9884\u671f\u6536\u76ca: {portfolio_return}&quot;)<\/p>\n<p>print(f&quot;\u6295\u8d44\u7ec4\u5408\u7684\u65b9\u5dee: {portfolio_variance}&quot;)<\/p>\n<p>print(f&quot;\u6295\u8d44\u7ec4\u5408\u7684\u6807\u51c6\u5dee: {portfolio_std}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>6.2 \u6bd4\u8f83\u4e0d\u540c\u8d44\u4ea7\u914d\u7f6e\u65b9\u6848<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u6bd4\u8f83\u4e0d\u540c\u8d44\u4ea7\u914d\u7f6e\u65b9\u6848\u7684\u8868\u73b0\uff0c\u4ee5\u8bc4\u4f30\u4f18\u5316\u7ed3\u679c\u7684\u6709\u6548\u6027\u3002\u8fd9\u5305\u62ec\u6bd4\u8f83\u4e0d\u540c\u8d44\u4ea7\u914d\u7f6e\u7684\u9884\u671f\u6536\u76ca\u3001\u98ce\u9669\uff0c\u4ee5\u53ca\u5728\u5386\u53f2\u6570\u636e\u4e2d\u7684\u8868\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e0d\u540c\u8d44\u4ea7\u914d\u7f6e\u65b9\u6848<\/p>\n<p>equal_weights = np.array([0.25, 0.25, 0.25, 0.25])<\/p>\n<p>random_weights = np.random.random(len(assets))<\/p>\n<p>random_weights \/= np.sum(random_weights)<\/p>\n<h2><strong>\u8ba1\u7b97\u4e0d\u540c\u8d44\u4ea7\u914d\u7f6e\u7684\u9884\u671f\u6536\u76ca\u548c\u98ce\u9669<\/strong><\/h2>\n<p>equal_return = np.dot(equal_weights, returns.mean()) * 252<\/p>\n<p>equal_variance = portfolio_variance(equal_weights, cov_matrix)<\/p>\n<p>equal_std = np.sqrt(equal_variance) * np.sqrt(252)<\/p>\n<p>random_return = np.dot(random_weights, returns.mean()) * 252<\/p>\n<p>random_variance = portfolio_variance(random_weights, cov_matrix)<\/p>\n<p>random_std = np.sqrt(random_variance) * np.sqrt(252)<\/p>\n<h2><strong>\u6253\u5370\u7ed3\u679c<\/strong><\/h2>\n<p>print(f&quot;\u7b49\u6743\u91cd\u914d\u7f6e\u7684\u9884\u671f\u6536\u76ca: {equal_return}&quot;)<\/p>\n<p>print(f&quot;\u7b49\u6743\u91cd\u914d\u7f6e\u7684\u65b9\u5dee: {equal_variance}&quot;)<\/p>\n<p>print(f&quot;\u7b49\u6743\u91cd\u914d\u7f6e\u7684\u6807\u51c6\u5dee: {equal_std}&quot;)<\/p>\n<p>print(f&quot;\u968f\u673a\u6743\u91cd\u914d\u7f6e\u7684\u9884\u671f\u6536\u76ca: {random_return}&quot;)<\/p>\n<p>print(f&quot;\u968f\u673a\u6743\u91cd\u914d\u7f6e\u7684\u65b9\u5dee: {random_variance}&quot;)<\/p>\n<p>print(f&quot;\u968f\u673a\u6743\u91cd\u914d\u7f6e\u7684\u6807\u51c6\u5dee: {random_std}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e\uff0c\u5e76\u8bc4\u4f30\u5176\u6709\u6548\u6027\u548c\u5408\u7406\u6027\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5386\u53f2\u6570\u636e\u5e76\u4e0d\u80fd\u5b8c\u5168\u9884\u6d4b\u672a\u6765\u7684\u8868\u73b0\uff0c\u56e0\u6b64\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u5e94\u7ed3\u5408\u5176\u4ed6\u5206\u6790\u65b9\u6cd5\u548c\u5de5\u5177\uff0c\u4ee5\u505a\u51fa\u66f4\u5168\u9762\u7684\u6295\u8d44\u51b3\u7b56\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u8fdb\u4e00\u6b65\u4f18\u5316\u548c\u6269\u5c55<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u4e00\u6b65\u4f18\u5316\u548c\u6269\u5c55\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e\u7684\u65b9\u6cd5\uff0c\u4ee5\u63d0\u9ad8\u5176\u9002\u7528\u6027\u548c\u51c6\u786e\u6027\u3002\u8fd9\u5305\u62ec\u8003\u8651\u4ea4\u6613\u6210\u672c\u3001\u589e\u52a0\u7ea6\u675f\u6761\u4ef6\u3001\u4f7f\u7528\u5176\u4ed6\u4f18\u5316\u7b97\u6cd5\u7b49\u3002<\/p>\n<\/p>\n<p><h4>7.1 \u8003\u8651\u4ea4\u6613\u6210\u672c<\/h4>\n<\/p>\n<p><p>\u4ea4\u6613\u6210\u672c\u662f\u6295\u8d44\u8fc7\u7a0b\u4e2d\u4e0d\u53ef\u5ffd\u89c6\u7684\u56e0\u7d20\u3002\u5728\u4f18\u5316\u8d44\u4ea7\u914d\u7f6e\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4ea4\u6613\u6210\u672c\u7eb3\u5165\u76ee\u6807\u51fd\u6570\uff0c\u4ee5\u83b7\u5f97\u66f4\u5b9e\u9645\u7684\u4f18\u5316\u7ed3\u679c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u76ee\u6807\u51fd\u6570\uff08\u8003\u8651\u4ea4\u6613\u6210\u672c\uff09<\/p>\n<p>def portfolio_variance_with_cost(weights, cov_matrix, transaction_cost):<\/p>\n<p>    var = np.dot(weights.T, np.dot(cov_matrix, weights))<\/p>\n<p>    cost = transaction_cost * np.sum(np.abs(weights - init_weights))<\/p>\n<p>    return var + cost<\/p>\n<h2><strong>\u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u627e\u5230\u6700\u4f18\u6743\u91cd<\/strong><\/h2>\n<p>transaction_cost = 0.01<\/p>\n<p>result_with_cost = minimize(portfolio_variance_with_cost, init_weights, args=(cov_matrix, transaction_cost), method=&#39;SLSQP&#39;, bounds=bounds, constraints=constraints)<\/p>\n<h2><strong>\u6253\u5370\u6700\u4f18\u6743\u91cd<\/strong><\/h2>\n<p>print(result_with_cost.x)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>7.2 \u589e\u52a0\u7ea6\u675f\u6761\u4ef6<\/h4>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u589e\u52a0\u4e00\u4e9b\u7ea6\u675f\u6761\u4ef6\uff0c\u4ee5\u6ee1\u8db3\u7279\u5b9a\u7684\u6295\u8d44\u9700\u6c42\u3002\u4f8b\u5982\uff0c\u9650\u5236\u67d0\u4e9b\u8d44\u4ea7\u7684\u6743\u91cd\u5728\u7279\u5b9a\u8303\u56f4\u5185\uff0c\u6216\u8005\u8981\u6c42\u6295\u8d44\u7ec4\u5408\u7684\u9884\u671f\u6536\u76ca\u8fbe\u5230\u67d0\u4e2a\u6c34\u5e73\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574<code>constraints<\/code>\u53c2\u6570\u6765\u5b9e\u73b0\u8fd9\u4e9b\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u7ea6\u675f\u6761\u4ef6\uff08\u6743\u91cd\u4e4b\u548c\u4e3a1\uff0c\u4e14\u6295\u8d44\u7ec4\u5408\u7684\u9884\u671f\u6536\u76ca\u4e0d\u4f4e\u4e8e0.1\uff09<\/p>\n<p>constraints = (<\/p>\n<p>    {&#39;type&#39;: &#39;eq&#39;, &#39;fun&#39;: lambda x: np.sum(x) - 1},<\/p>\n<p>    {&#39;type&#39;: &#39;ineq&#39;, &#39;fun&#39;: lambda x: np.dot(x, returns.mean()) * 252 - 0.1}<\/p>\n<p>)<\/p>\n<h2><strong>\u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u627e\u5230\u6700\u4f18\u6743\u91cd<\/strong><\/h2>\n<p>result_with_constraints = minimize(portfolio_variance, init_weights, args=(cov_matrix,), method=&#39;SLSQP&#39;, bounds=bounds, constraints=constraints)<\/p>\n<h2><strong>\u6253\u5370\u6700\u4f18\u6743\u91cd<\/strong><\/h2>\n<p>print(result_with_constraints.x)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>7.3 \u4f7f\u7528\u5176\u4ed6\u4f18\u5316\u7b97\u6cd5<\/h4>\n<\/p>\n<p><p>\u9664\u4e86<code>scipy.optimize.minimize<\/code>\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u4f18\u5316\u7b97\u6cd5\u6765\u5b9e\u73b0\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e\u3002\u4f8b\u5982\uff0c\u9057\u4f20\u7b97\u6cd5\u3001\u7c92\u5b50\u7fa4\u4f18\u5316\u7b49\u3002\u8fd9\u4e9b\u7b97\u6cd5\u5728\u5904\u7406\u590d\u6742\u95ee\u9898\u65f6\u53ef\u80fd\u66f4\u6709\u6548\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u9057\u4f20\u7b97\u6cd5\u4f18\u5316<\/p>\n<p>from scipy.optimize import differential_evolution<\/p>\n<h2><strong>\u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u627e\u5230\u6700\u4f18\u6743\u91cd<\/strong><\/h2>\n<p>result_de = differential_evolution(portfolio_variance, bounds, args=(cov_matrix,), constraints=constraints)<\/p>\n<h2><strong>\u6253\u5370\u6700\u4f18\u6743\u91cd<\/strong><\/h2>\n<p>print(result_de.x)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Python\u5b9e\u73b0\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e\u3002\u6211\u4eec\u9996\u5148\u4e86\u89e3\u4e86\u73b0\u4ee3\u6295\u8d44\u7ec4\u5408\u7406\u8bba\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u7136\u540e\u901a\u8fc7\u83b7\u53d6\u8d44\u4ea7\u7684\u5386\u53f2\u4ef7\u683c\u6570\u636e\u3001\u8ba1\u7b97\u6536\u76ca\u7387\u548c\u534f\u65b9\u5dee\u77e9\u9635\u3001\u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\u627e\u5230\u6700\u4f18\u6743\u91cd\u7b49\u6b65\u9aa4\uff0c\u5b9e\u73b0\u4e86\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e\u3002\u6700\u540e\uff0c\u6211\u4eec\u8ba8\u8bba\u4e86\u8fdb\u4e00\u6b65\u4f18\u5316\u548c\u6269\u5c55\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u8003\u8651\u4ea4\u6613\u6210\u672c\u3001\u589e\u52a0\u7ea6\u675f\u6761\u4ef6\u3001\u4f7f\u7528\u5176\u4ed6\u4f18\u5316\u7b97\u6cd5\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u8bfb\u8005\u53ef\u4ee5\u638c\u63e1\u4f7f\u7528Python\u5b9e\u73b0\u65b9\u5dee\u6700\u5c0f\u5316\u8d44\u4ea7\u914d\u7f6e\u7684\u57fa\u672c\u65b9\u6cd5\u548c\u6280\u5de7\uff0c\u5e76\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u4e0d\u65ad\u4f18\u5316\u548c\u6269\u5c55\uff0c\u4ee5\u5b9e\u73b0\u66f4\u4f18\u7684\u6295\u8d44\u51b3\u7b56\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6295\u8d44\u51b3\u7b56\u5e94\u7efc\u5408\u8003\u8651\u591a\u65b9\u9762\u56e0\u7d20\uff0c\u5386\u53f2\u6570\u636e\u5e76\u4e0d\u80fd\u5b8c\u5168\u9884\u6d4b\u672a\u6765\u7684\u8868\u73b0\uff0c\u56e0\u6b64\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u5e94\u7ed3\u5408\u5176\u4ed6\u5206\u6790\u65b9\u6cd5\u548c\u5de5\u5177\uff0c\u4ee5\u505a\u51fa\u66f4\u5168\u9762\u7684\u6295\u8d44\u51b3\u7b56\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u901a\u8fc7Python\u5b9e\u73b0\u6700\u5c0f\u65b9\u5dee\u8d44\u4ea7\u914d\u7f6e\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u5b9e\u73b0\u6700\u5c0f\u65b9\u5dee\u8d44\u4ea7\u914d\u7f6e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5e93\u5982NumPy\u548cPandas\u6765\u5904\u7406\u6570\u636e\uff0c\u5e76\u5229\u7528SciPy\u5e93\u4e2d\u7684\u4f18\u5316\u5de5\u5177\u6765\u6c42\u89e3\u6700\u4f18\u6743\u91cd\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u6536\u96c6\u8d44\u4ea7\u7684\u5386\u53f2\u6536\u76ca\u7387\u6570\u636e\uff0c\u5e76\u8ba1\u7b97\u6536\u76ca\u7387\u7684\u534f\u65b9\u5dee\u77e9\u9635\u3002\u63a5\u7740\uff0c\u901a\u8fc7\u5b9a\u4e49\u76ee\u6807\u51fd\u6570\uff08\u6700\u5c0f\u5316\u7ec4\u5408\u65b9\u5dee\uff09\u5e76\u4f7f\u7528\u4f18\u5316\u7b97\u6cd5\uff08\u5982\u6700\u5c0f\u5316\u51fd\u6570\uff09\u6765\u786e\u5b9a\u5404\u8d44\u4ea7\u7684\u6700\u4f18\u914d\u7f6e\u6bd4\u4f8b\u3002<\/p>\n<p><strong>\u5728\u8fdb\u884c\u6700\u5c0f\u65b9\u5dee\u8d44\u4ea7\u914d\u7f6e\u65f6\uff0c\u54ea\u4e9b\u6570\u636e\u662f\u5fc5\u8981\u7684\uff1f<\/strong><br \/>\u8fdb\u884c\u6700\u5c0f\u65b9\u5dee\u8d44\u4ea7\u914d\u7f6e\u65f6\uff0c\u60a8\u9700\u8981\u7684\u4e3b\u8981\u6570\u636e\u5305\u62ec\u8d44\u4ea7\u7684\u5386\u53f2\u4ef7\u683c\u6216\u6536\u76ca\u7387\u3001\u5404\u8d44\u4ea7\u4e4b\u95f4\u7684\u534f\u65b9\u5dee\u77e9\u9635\u4ee5\u53ca\u65e0\u98ce\u9669\u5229\u7387\uff08\u5982\u679c\u8003\u8651\u98ce\u9669\u8c03\u6574\uff09\u3002\u8fd9\u4e9b\u6570\u636e\u53ef\u4ee5\u4ece\u91d1\u878d\u6570\u636e\u5e93\u6216API\u83b7\u53d6\uff0c\u4ee5\u4fbf\u8fdb\u884c\u6709\u6548\u7684\u5206\u6790\u548c\u8ba1\u7b97\u3002<\/p>\n<p><strong>\u5982\u4f55\u9a8c\u8bc1\u6700\u5c0f\u65b9\u5dee\u8d44\u4ea7\u914d\u7f6e\u7684\u6709\u6548\u6027\uff1f<\/strong><br \/>\u9a8c\u8bc1\u6700\u5c0f\u65b9\u5dee\u8d44\u4ea7\u914d\u7f6e\u7684\u6709\u6548\u6027\u53ef\u4ee5\u901a\u8fc7\u8ba1\u7b97\u6295\u8d44\u7ec4\u5408\u7684\u5386\u53f2\u8868\u73b0\u6765\u5b9e\u73b0\u3002\u60a8\u53ef\u4ee5\u5bf9\u6bd4\u8be5\u6295\u8d44\u7ec4\u5408\u7684\u5b9e\u9645\u6536\u76ca\u7387\u4e0e\u9884\u671f\u6536\u76ca\u7387\uff0c\u5206\u6790\u5176\u6ce2\u52a8\u7387\u548c\u590f\u666e\u6bd4\u7387\u7b49\u6307\u6807\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u8fdb\u884c\u56de\u6d4b\uff0c\u67e5\u770b\u5728\u4e0d\u540c\u5e02\u573a\u6761\u4ef6\u4e0b\u6295\u8d44\u7ec4\u5408\u7684\u8868\u73b0\uff0c\u4ee5\u786e\u4fdd\u5176\u7a33\u5065\u6027\u548c\u9002\u5e94\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5982\u4f55\u4f7f\u65b9\u5dee\u6700\u5c0f\u8d44\u4ea7\u914d\u7f6e \u5728\u6295\u8d44\u7ec4\u5408\u7ba1\u7406\u4e2d\uff0c\u4f7f\u65b9\u5dee\u6700\u5c0f\u5316\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u4ee5\u964d\u4f4e\u6295\u8d44\u7ec4\u5408\u7684\u98ce\u9669\u3002\u65b9\u5dee [&hellip;]","protected":false},"author":3,"featured_media":1026402,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1026397"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1026397"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1026397\/revisions"}],"predecessor-version":[{"id":1026403,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1026397\/revisions\/1026403"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1026402"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1026397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1026397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1026397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}