{"id":1691,"date":"2024-12-06T07:29:00","date_gmt":"2024-12-05T23:29:00","guid":{"rendered":"https:\/\/blog.laoyulaoyu.top\/?p=1691"},"modified":"2024-11-11T22:34:05","modified_gmt":"2024-11-11T14:34:05","slug":"%e8%bd%bb%e6%9d%be%e4%b8%8a%e6%89%8b%ef%bc%81%e6%99%ba%e8%83%bd%e8%ae%a1%e7%ae%97%e8%82%a1%e7%a5%a8%e5%9b%9e%e6%8a%a5%e7%8e%87%e5%b9%b6%e4%b8%8e%e6%8c%87%e6%95%b0%e7%9b%b8%e8%be%83","status":"publish","type":"post","link":"https:\/\/laoyulaoyu.com\/index.php\/2024\/12\/06\/%e8%bd%bb%e6%9d%be%e4%b8%8a%e6%89%8b%ef%bc%81%e6%99%ba%e8%83%bd%e8%ae%a1%e7%ae%97%e8%82%a1%e7%a5%a8%e5%9b%9e%e6%8a%a5%e7%8e%87%e5%b9%b6%e4%b8%8e%e6%8c%87%e6%95%b0%e7%9b%b8%e8%be%83\/","title":{"rendered":"\u8f7b\u677e\u4e0a\u624b\uff01\u667a\u80fd\u8ba1\u7b97\u80a1\u7968\u56de\u62a5\u7387\u5e76\u4e0e\u6307\u6570\u76f8\u8f83"},"content":{"rendered":"\n<p>\u4f5c\u8005\uff1a<a href=\"https:\/\/www.laoyulaoyu.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u8001\u4f59\u635e\u9c7c<\/a><\/p>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-cyan-bluish-gray-color\">\u539f\u521b\u4e0d\u6613\uff0c\u8f6c\u8f7d\u8bf7\u6807\u660e\u51fa\u5904\u53ca\u539f\u4f5c\u8005\u3002<\/mark><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2024\/11\/111001.png\" alt=\"\" class=\"wp-image-2897\"\/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-verse\"><strong>\u5199\u5728\u524d\u9762\u7684\u8bdd\uff1a<\/strong>\u4e4b\u524d\u6211\u5199\u4e86\u5f88\u591a\u7528 python \u5b9e\u73b0\u5404\u79cd\u6295\u8d44\u5de5\u5177\u7684\u6587\u7ae0\uff0c\u6709\u8bfb\u8005\u7559\u8a00\u5e0c\u671b\u6211\u591a\u5199\u4e00\u4e9b\u9002\u5408\u201c\u5c0f\u767d\u201d\u5b66\u4e60\u7684\u8bfe\u7a0b\uff0c\u6216\u8005\u76f8\u5bf9\u5bb9\u6613\u4e0a\u624b\u7684\u5185\u5bb9\u3002<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">\u672c\u6587\u5c31\u662f\u4e00\u7bc7\u5165\u95e8\u7ea7\u7684\u6559\u7a0b\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528 Python \u548c yfinance \u6765\u8f7b\u677e\u8ba1\u7b97\u4efb\u4f55\u80a1\u7968\u7684\u6708\u6536\u76ca\u1f49<\/mark>\uff0c\u5e76\u5c06\u5176\u4e0e\u6807\u51c6\u666e\u5c14\uff08SPY\uff09 500 \u6307\u6570\u8fdb\u884c\u6bd4\u8f83\uff0c\u4ece\u800c\u5206\u6790\u4f60\u7684\u80a1\u7968\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u76f8\u5bf9\u4e8e\u6574\u4e2a\u5e02\u573a\u7684\u8868\u73b0\u3002<\/pre>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u4e00\u3001\u4e3a\u4ec0\u4e48\u8981\u62ff\u6708\u56de\u62a5\u7387\u548c\u6807\u51c6\u666e\u5c14500 \u8fdb\u884c\u5bf9\u6bd4<\/strong><\/h3>\n\n\n\n<p>\u63a2\u7d22\u4e00\u53ea\u80a1\u7968\u5728\u4e00\u5b9a\u65f6\u95f4\u6846\u67b6\u5185\u7684\u8f68\u8ff9\uff0c\u6708\u5ea6\u56de\u62a5\u7387\u65e0\u7591\u662f\u4e00\u6247\u6d1e\u5bdf\u5176\u8868\u73b0\u7684\u7a97\u6237\u3002\u4e0d\u8bba\u60a8\u662f\u8d44\u6df1\u7684\u5e02\u573a\u8001\u624b\uff0c\u8fd8\u662f\u521d\u6d89\u80a1\u5e02\u7684\u65b0\u624b\uff0c\u8fd9\u79cd\u7b80\u6d01\u800c\u6709\u529b\u7684\u5206\u6790\u65b9\u6cd5\u90fd\u80fd\u6e05\u6670\u5730\u63ed\u793a\u51fa\u80a1\u7968\u76f8\u5bf9\u4e8e\u6574\u4f53\u5e02\u573a\u7684\u8d70\u52bf\u548c\u8868\u73b0\u3002\u6bcf\u6708\u7684\u6536\u76ca\u6ce2\u52a8\uff0c\u4e3a\u60a8\u52fe\u52d2\u51fa\u4e00\u5e45\u6295\u8d44\u6545\u4e8b\u7684\u8f6e\u5ed3\uff0c\u52a9\u60a8\u5728\u6295\u8d44\u7684\u5f81\u9014\u4e2d\u505a\u51fa\u66f4\u4e3a\u660e\u667a\u7684\u51b3\u7b56\u3002<\/p>\n\n\n\n<p>\u5f53\u7136\uff0c\u4f60\u901a\u8fc7\u80a1\u7968app\u4e0a\u80fd\u770b\u5230\u4f60\u6bcf\u53ea\u80a1\u7968\u7684\u6536\u76ca\u60c5\u51b5\uff0c\u8fd8\u53ef\u4ee5\u5728\u7535\u8111\u7aef\u901a\u8fc7\u5212\u7ebf\u5de5\u5177\u540c\u6307\u6570\u8fdb\u884c\u5404\u65f6\u95f4\u6bb5\u6536\u76ca\u7387\u6bd4\u8f83\u3002\u4f46\u5982\u679c\u4f60\u8981\u8fdb\u4e00\u6b65\u7684\u5b9e\u73b0\u81ea\u5df1\u60f3\u8981\u7684\u529f\u80fd\uff0c\u6253\u9020\u4e13\u5c5e\u4e8e\u81ea\u5df1\u8c03\u6027\u7684\u6295\u8d44\u5de5\u5177\uff0c\u6bd4\u5982<strong>\u751f\u6210\u5404\u79cd\u6280\u672f\u5206\u6790\u56fe<\/strong>\uff1a\u300a<a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247484069&amp;idx=1&amp;sn=9a4e688c2f5c134670c8c6887f2cc1f6&amp;chksm=c28d035bf5fa8a4dbd4ce5403ce9dea7bf82e39a6245f8c5da30559117ef65d633707aa40ade&amp;token=777909591&amp;lang=zh_CN#rd\" target=\"_blank\" rel=\"noreferrer noopener\"><em>\u624b\u628a\u624b\u6559\u4f60AI\u987e\u6295<\/em>\uff1a\u8f7b\u677e\u81ea\u52a8\u751f\u6210A\u80a1\u591a\u6280\u672f\u6307\u6807K\u7ebf\u56fe\u7684\u65b9\u6cd5<\/a>\u300b\u3001\u300a<a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247485087&amp;idx=1&amp;sn=b74be89f32110b4486c01908baa60208&amp;chksm=c28d0761f5fa8e777339d5d4334164a1c00d6ba715a7fccfa009dc1123102ac1c16ef18d7f84&amp;token=777909591&amp;lang=zh_CN#rd\" target=\"_blank\" rel=\"noreferrer noopener\">\u624b\u628a\u624b\u5e26\u4f60\u7528&nbsp;<em>Python<\/em>&nbsp;\u753b\u51fa\u53ef\u89c6\u5316\u4ea4\u6613\u4fe1\u53f7<\/a>\u300b\u3002\u6bd4\u5982<strong>\u8fdb\u884cAPI\u8c03\u7528\u548c\u7b56\u7565\u7f16\u5199<\/strong>\uff1a\u300a<a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247484363&amp;idx=1&amp;sn=ce5c6be1fbf8c71c079ce7a4d1ba6cc4&amp;chksm=c28d0235f5fa8b23f06e081be54e3f97dcab60f3c2854b922ec13ad8efb2167648d884777ff0&amp;token=777909591&amp;lang=zh_CN#rd\" target=\"_blank\" rel=\"noreferrer noopener\">\u624b\u628a\u624b\u6559\u4f60&nbsp;AI&nbsp;\u987e\u6295\uff1a\u5728&nbsp;Ollama&nbsp;\u4e2d\u4f7f\u7528&nbsp;Python&nbsp;\u8c03\u7528\u91d1\u878d&nbsp;API&nbsp;\u670d\u52a1<\/a><span style=\"font-size: revert;\">\u300b\u3001\u300a<a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247485325&amp;idx=1&amp;sn=744fd82668b7a4b0b21c87344628b0e5&amp;chksm=c28d0673f5fa8f659465aba88e83e70f9c3365bb77e852833df198874dca6a5995211477177f&amp;token=777909591&amp;lang=zh_CN#rd\" target=\"_blank\" rel=\"noreferrer noopener\">\u624b\u628a\u624b\u6559\u4f60&nbsp;AI&nbsp;\u987e\u6295\uff1a&nbsp;Python&nbsp;\u52a9\u529b\uff0c\u8f7b\u677e\u8fc8\u5165\u7b97\u6cd5\u4ea4\u6613\u5458\u4e4b\u95e8<\/a><span style=\"font-size: revert;\">\u300b\u3001\u300a<a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247485087&amp;idx=1&amp;sn=b74be89f32110b4486c01908baa60208&amp;chksm=c28d0761f5fa8e777339d5d4334164a1c00d6ba715a7fccfa009dc1123102ac1c16ef18d7f84&amp;token=777909591&amp;lang=zh_CN#rd\" target=\"_blank\" rel=\"noreferrer noopener\">\u771f\u6b63\u624b\u628a\u624b\u6559\u4f1a\u4f60\uff1a\u7528&nbsp;Python&nbsp;\u6784\u5efa\u7f51\u683c\u4ea4\u6613\u7b56\u7565<\/a><\/span>\u300b\u3002\u518d\u6bd4\u5982<strong>\u548cAI\u52a9\u624b\u7ed3\u5408\u8fdb\u884c\u5e02\u573a\u6d1e\u5bdf\u548c\u9884\u6d4b\uff1a<\/strong>\u300a<a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247485414&amp;idx=1&amp;sn=24d70d6d58f38689571d285ace8ce329&amp;chksm=c28d0618f5fa8f0efa67bcde871baee9d0d37ca91e2dd1d3b77ad6946d26ef0cd8b98a039e14&amp;token=777909591&amp;lang=zh_CN#rd\" target=\"_blank\" rel=\"noreferrer noopener\">Ollama \u51fa\u9a6c\uff0c\u4e3a\u60a8\u521b\u5efa\u5b9e\u65f6 AI \u80a1\u7968\u987e\u95ee<\/a>\u300b\u3001\u300a\u624b<a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247484881&amp;idx=1&amp;sn=9ba580490cdaf8370d4f7e2d67e0adc8&amp;chksm=c28d042ff5fa8d391018e491bd604e063d231137b35b42c0d19cf4b969dc7b2963f1e14b1faf&amp;token=777909591&amp;lang=zh_CN#rd\">\u628a\u624b\u6559\u4f1a\u4f60\u7528&nbsp;AI&nbsp;\u548c&nbsp;Python&nbsp;\u8fdb\u884c\u80a1\u7968\u4ea4\u6613\u9884\u6d4b\uff08\u5b8c\u6574\u4ee3\u7801\u5e72\u8d27\uff09<\/a><span style=\"font-size: revert;\">\u300b\u3001\u300a<\/span><a style=\"font-size: revert; background-color: rgb(255, 255, 255);\" href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247484930&amp;idx=1&amp;sn=524e8ec0b0880d58bd7e4a630e66b9a0&amp;chksm=c28d07fcf5fa8eeae4fb957f34bd0ebe1795309f2ac6cf4e0660b83269550b0c12de391ec40c#rd\" target=\"_blank\" rel=\"noreferrer noopener\">\u878d\u5408\u7bc7\uff1a\u7528&nbsp;OpenAI&nbsp;o1&nbsp;\u8349\u8393\u6a21\u578b\u548c&nbsp;Python&nbsp;\u9884\u6d4b\u80a1\u5e02\u884c\u60c5<\/a><span style=\"font-size: revert; background-color: rgb(255, 255, 255);\">\u300b<\/span><\/span>\u7b49\u7b49\u3002\u5982\u679c\u6ca1\u6709\u57fa\u7840\u7684\u94fa\u57ab\uff0c\u4e0a\u9762\u8fd9\u4e9b\u6587\u7ae0\u53ef\u80fd\u4f60\u5f88\u96be\u6d3b\u5b66\u6d3b\u7528\u597d\u3002<\/p>\n\n\n\n<p>\u90a3\u4e3a\u4ec0\u4e48\u81ea\u5df1\u7684\u80a1\u7968\u4e00\u5b9a\u8981\u548c\u6307\u6570\u6bd4\u8f83\u56de\u62a5\u7387\u5462\uff1f\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u6211\u8ba4\u4e3a\u603b\u4f53\u4e0a\u6765\u8bb2\u5c31\u662f\u4e0b\u9762\u4e09\u70b9\u539f\u56e0\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2024\/11\/image-50.png\" alt=\"\" class=\"wp-image-2899\"\/><\/figure>\n<\/div>\n\n\n<p>\u800c\u672c\u6587\u9009\u53d6\u6807\u51c6\u666e\u5c14\uff08SPY\uff09 500 \u6307\u6570\u7684\u539f\u56e0\u5982\u4e0b\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2024\/11\/image-49.png\" alt=\"\" class=\"wp-image-2898\"\/><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\"><br><strong>\u4e8c\u3001\u5b9e\u73b0\u65b9\u6cd5<\/strong><\/h3>\n\n\n\n<p id=\"fb62\"><strong>\u65b9\u6cd5\u53ea\u9700\u8981\u4ee5\u4e0b\u4e09\u6b65\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4e0b\u8f7d\u5386\u53f2\u80a1\u7968\u6570\u636e\u3002<\/li>\n\n\n\n<li>\u8ba1\u7b97\u6bcf\u6708\u56de\u62a5\u7387&#8211;\u6bcf\u6708\u6700\u540e\u4e00\u5929\u7684\u4ef7\u683c\u53d8\u5316\u767e\u5206\u6bd4\u3002<\/li>\n\n\n\n<li>\u5c06\u8fd9\u4e9b\u56de\u62a5\u4e0e\u6807\u51c6\u666e\u5c14 500 \u6307\u6570\uff08\u66f4\u5e7f\u6cdb\u5e02\u573a\u7684\u57fa\u51c6\uff09\u8fdb\u884c\u6bd4\u8f83\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u60f3\u4ece 2023 \u5e74 1 \u6708\u5f00\u59cb\u5206\u6790\u82f9\u679c\u516c\u53f8 (AAPL) \u7684\u80a1\u7968\uff08\u8fd9\u4e2a\u7968\u5b50\u5728\u79d1\u62807\u96c4\u4e2d\u8868\u73b0\u7684\u4e0d\u6e29\u4e0d\u706b\uff0c\u6240\u4ee5\u62ff\u5b83\u51fa\u6765\u6bd4\u8f83 SPY\uff0c\u4f60\u89c9\u5f97\u8c01\u8f93\u8c01\u8d62\uff1f\uff09\u3002\u8fd0\u884c\u4ee3\u7801\u540e\uff0c\u6211\u4eec\u5c06\u5f97\u5230\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Monthly Returns Comparison:\n   Date  AAPL Price  AAPL Return (%)  S&amp;P 500 Price  S&amp;P 500 Return (%)  Return Difference (%)\n2023-01      142.95              NaN        4076.60                 NaN                    NaN\n2023-02      146.26             2.32        3970.15               -2.61                   4.93\n2023-03      163.61            11.86        4109.31                3.51                   8.36\n2023-04      168.36             2.90        4169.48                1.46                   1.43\n2023-05      176.11             4.61        4179.83                0.25                   4.36\n2023-06      192.72             9.43        4450.38                6.47                   2.96\n2023-07      195.19             1.28        4588.96                3.11                  -1.84\n2023-08      186.91            -4.24        4507.66               -1.77                  -2.47\n2023-09      170.34            -8.87        4288.05               -4.87                  -4.00\n2023-10      169.90            -0.26        4193.80               -2.20                   1.94\n2023-11      189.23            11.38        4567.80                8.92                   2.46\n2023-12      191.80             1.36        4769.83                4.42                  -3.06\n2024-01      183.70            -4.22        4845.65                1.59                  -5.81\n2024-02      180.30            -1.85        5096.27                5.17                  -7.03\n2024-03      171.05            -5.13        5254.35                3.10                  -8.23\n2024-04      169.90            -0.67        5035.69               -4.16                   3.49\n2024-05      192.03            13.02        5277.51                4.80                   8.22\n2024-06      210.38             9.56        5460.48                3.47                   6.09\n2024-07      221.82             5.44        5522.30                1.13                   4.31\n2024-08      229.00             3.24        5648.40                2.28                   0.95\n2024-09      233.00             1.75        5762.48                2.02                  -0.27\n2024-10      225.91            -3.04        5705.45               -0.99                  -2.05\n2024-11      226.96             0.46        5995.54                5.08                  -4.62\n\nSummary Statistics:\nAAPL Mean Monthly Return (%): 2.29%\nAAPL Total Return (%): 58.77%\nS&amp;P 500 Mean Monthly Return (%): 1.83%\nS&amp;P 500 Total Return (%): 47.07%<\/code><\/pre>\n\n\n\n<p>\u82f9\u679c\u80a1\u7968\u8fd9\u6bb5\u65f6\u95f4\u5185\u7684\u603b\u56de\u62a5\u7387\u4e3a58.77% \uff0c\u662f\u4f18\u4e8e\u6807\u51c6\u666e\u5c14 500 \u6307\u657047.07%\u7684\uff0c\u4f46\u4ece\u957f\u8fdc\u6765\u770b\u8c01\u77e5\u9053\u4f1a\u53d1\u751f\u4ec0\u4e48\u5462\uff1f\u8fd9\u4e9b\u7edf\u8ba1\u6570\u636e\u53ef\u4ee5\u5e2e\u52a9\u6295\u8d44\u8005\u6839\u636e\u4e00\u8d2f\u7684\u8d8b\u52bf\u505a\u51fa\u51b3\u7b56\u3002<\/p>\n\n\n\n<p>\u5c31\u662f\u4e0b\u9762\u7684 Python \u4ee3\u7801\u4e3a\u6211\u4eec\u5b8c\u6210\u4e86\u6240\u6709\u7e41\u91cd\u7684\u5de5\u4f5c\u3002\u5b83\u5e72\u51c0\u3001\u7b80\u5355\u3001\u9ad8\u6548\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import yfinance as yf\nimport pandas as pd\n\ndef calculate_monthly_returns(ticker_symbol='AAPL', start_date='2020-01-01', compare_to_sp500=True):\n    \"\"\"\n    Calculate monthly returns for a given stock ticker and optionally compare to S&amp;P 500\n    \n    Parameters:\n    ticker_symbol (str): Stock ticker symbol\n    start_date (str): Start date in YYYY-MM-DD format\n    compare_to_sp500 (bool): Whether to include S&amp;P 500 comparison\n    \n    Returns:\n    pandas.DataFrame: Monthly returns data\n    \"\"\"\n    # Download stock data\n    stock = yf.Ticker(ticker_symbol)\n    df = stock.history(start=start_date, interval='1d')\n    \n    # Download S&amp;P 500 data if requested\n    if compare_to_sp500:\n        sp500 = yf.Ticker('^GSPC')\n        sp500_df = sp500.history(start=start_date, interval='1d')\n    \n    # Resample to monthly data using 'ME' (Month End) and get last price of each month\n    monthly_prices = df&#91;'Close'].resample('ME').last()\n    monthly_returns = monthly_prices.pct_change() * 100\n    \n    result_data = {\n        'Date': monthly_returns.index.strftime('%Y-%m'),\n        f'{ticker_symbol} Price': monthly_prices.round(2),\n        f'{ticker_symbol} Return (%)': monthly_returns.round(2)\n    }\n    \n    if compare_to_sp500:\n        sp500_monthly_prices = sp500_df&#91;'Close'].resample('ME').last()\n        sp500_monthly_returns = sp500_monthly_prices.pct_change() * 100\n        \n        result_data.update({\n            'S&amp;P 500 Price': sp500_monthly_prices.round(2),\n            'S&amp;P 500 Return (%)': sp500_monthly_returns.round(2),\n            'Return Difference (%)': (monthly_returns - sp500_monthly_returns).round(2)\n        })\n    \n    result_df = pd.DataFrame(result_data)\n    \n    # Calculate summary statistics\n    summary = {\n        f'{ticker_symbol} Mean Monthly Return (%)': monthly_returns.mean().round(2),\n        f'{ticker_symbol} Total Return (%)': ((1 + monthly_returns\/100).prod() - 1) * 100\n    }\n    \n    if compare_to_sp500:\n        summary.update({\n            'S&amp;P 500 Mean Monthly Return (%)': sp500_monthly_returns.mean().round(2),\n            'S&amp;P 500 Total Return (%)': ((1 + sp500_monthly_returns\/100).prod() - 1) * 100\n        })\n    \n    return result_df, summary\n\n# Example usage\nif __name__ == \"__main__\":\n    returns_df, summary = calculate_monthly_returns('AAPL', '2023-01-01')\n    \n    print(\"\\nMonthly Returns Comparison:\")\n    print(returns_df.to_string(index=False))\n    \n    print(\"\\nSummary Statistics:\")\n    for metric, value in summary.items():\n        print(f\"{metric}: {value:.2f}%\")<\/code><\/pre>\n\n\n\n<p><strong>\u4ee3\u7801\u7684\u4e3b\u8981\u5185\u5bb9\u8bf4\u660e\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u80a1\u7968\u6570\u636e\u4e0b\u8f7d <\/strong>\uff1a\u6211\u4eec\u4f7f\u7528&nbsp;<code>yfinance<\/code>&nbsp;\u83b7\u53d6\u5386\u53f2\u80a1\u7968\u4ef7\u683c\u3002\u6211\u4eec\u83b7\u53d6\u80a1\u7968\u4ee3\u7801\uff08\u5982\u82f9\u679c\u516c\u53f8\uff0c&#8221;AAPL&#8221;\uff09\u548c\u6807\u51c6\u666e\u5c14 500 \u6307\u6570\uff08^GSPC\uff09\u7684\u6bcf\u65e5\u6570\u636e\u3002<\/li>\n\n\n\n<li><strong>\u6708\u5ea6\u6570\u636e\u91cd\u91c7\u6837<\/strong>\uff1a\u6211\u4eec\u4f7f\u7528&nbsp;<code>.resample('ME')<\/code>&nbsp;\u65b9\u6cd5\u5c06\u6bcf\u65e5\u6570\u636e\u8f6c\u6362\u4e3a\u6708\u5ea6\u6570\u636e\uff0c\u8be5\u65b9\u6cd5\u4f1a\u6293\u53d6\u6bcf\u4e2a\u6708\u7684\u6700\u540e\u6536\u76d8\u4ef7\u3002\u8fd9\u6837\u6211\u4eec\u5c31\u80fd\u5f97\u5230\u4e00\u4e2a\u66f4\u7b80\u6d01\u3001\u66f4\u6613\u7406\u89e3\u7684\u6570\u636e\u96c6\u3002<\/li>\n\n\n\n<li><strong>\u6708\u56de\u62a5\u8ba1\u7b97\uff1a<\/strong>\u4f7f\u7528<code>pct_change()<\/code>\uff0c\u6211\u4eec\u53ef\u4ee5\u8ba1\u7b97\u51fa\u6708\u4e0e\u6708\u4e4b\u95f4\u7684\u4ef7\u683c\u53d8\u5316\u767e\u5206\u6bd4\u3002\u8fd9\u663e\u793a\u4e86\u80a1\u7968\u548c\u6807\u51c6\u666e\u5c14 500 \u6307\u6570\u5728\u4e00\u4e2a\u6708\u5185\u7684\u767e\u5206\u6bd4\u53d8\u5316\u3002<\/li>\n\n\n\n<li><strong>\u7ed3\u679c\u6570\u636e\uff1a<\/strong>\u7136\u540e\uff0c\u6211\u4eec\u51c6\u5907\u4e00\u4e2a DataFrame\uff0c\u5176\u4e2d\u5305\u542b\u80a1\u7968\u548c\u6807\u51c6\u666e\u5c14 500 \u6307\u6570\u7684\u6708\u5ea6\u4ef7\u683c\u548c\u6536\u76ca\uff0c\u4ee5\u53ca\u6536\u76ca\u7684\u5dee\u5f02\u3002<\/li>\n\n\n\n<li><strong>\u7b80\u8981\u7edf\u8ba1<\/strong>\uff1a\u6700\u540e\uff0c\u6211\u4eec\u4f1a\u8ba1\u7b97\u5e73\u5747\u6708\u56de\u62a5\u7387\uff08\u6240\u6709\u6708\u4efd\u7684\u5e73\u5747\u56de\u62a5\u7387\uff09\u548c\u603b\u56de\u62a5\u7387\uff08\u6574\u4e2a\u671f\u95f4\u80a1\u7968\u7684\u6da8\u8dcc\u5e45\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u4e09\u3001\u89c2\u70b9\u603b\u7ed3<\/strong><\/h3>\n\n\n\n<p>\u5bf9\u4e8e\u60f3\u8981\u5feb\u901f\u8bc4\u4f30\u81ea\u5df1\u7684\u6295\u8d44\u5728\u5927\u76d8\u80cc\u666f\u4e0b\u7684\u8868\u73b0\u7684\u4eba\u6765\u8bf4\uff0c\u8fd9\u9879\u5206\u6790\u6539\u53d8\u4e86\u6e38\u620f\u89c4\u5219\u3002\u65e0\u8bba\u60a8\u662f\u5c06\u82f9\u679c\u4e0e\u6807\u51c6\u666e\u5c14 500 \u6216\u4efb\u4f55\u5176\u4ed6\u80a1\u7968\u8fdb\u884c\u6bd4\u8f83\uff0c\u8fd9\u4e9b\u89c1\u89e3\u90fd\u80fd\u5e2e\u52a9\u60a8\u505a\u51fa\u66f4\u660e\u667a\u7684\u6295\u8d44\u9009\u62e9\u3002\u53ea\u9700\u51e0\u884c\u4ee3\u7801\uff0c\u5373\u53ef\u5f00\u59cb\u5206\u6790\u81ea\u5df1\u7684\u6295\u8d44\u7ec4\u5408\uff01\u4f60\u5b66\u4f1a\u4e86\u5417\uff1f<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2024\/11\/image-51.png\" alt=\"\" class=\"wp-image-2900\"\/><\/figure>\n<\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u80a1\u7968\u6708\u5ea6\u56de\u62a5\u7387\u7684\u8ba1\u7b97<\/strong>\uff1a\u901a\u8fc7Python\u7f16\u7a0b\u548cyfinance\u5e93\uff0c\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u548c\u8ba1\u7b97\u80a1\u7968\u7684\u6708\u5ea6\u56de\u62a5\u7387\uff0c\u8fd9\u4e3a\u5206\u6790\u80a1\u7968\u8868\u73b0\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7b80\u5355\u800c\u5f3a\u5927\u7684\u65b9\u6cd5\u3002<\/li>\n\n\n\n<li><strong>\u4e0e\u6807\u51c6\u666e\u5c14500\u7684\u6bd4\u8f83<\/strong>\uff1a\u5c06\u80a1\u7968\u7684\u6708\u5ea6\u56de\u62a5\u7387\u4e0e\u6807\u51c6\u666e\u5c14500\u6307\u6570\u8fdb\u884c\u6bd4\u8f83\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6295\u8d44\u8005\u4e86\u89e3\u5176\u6295\u8d44\u662f\u5426\u8dd1\u8d62\u4e86\u5e02\u573a\uff0c\u6216\u8005\u662f\u5426\u5b58\u5728\u6ede\u540e\u3002<\/li>\n\n\n\n<li><strong>\u5e02\u573a\u8d8b\u52bf\u7684\u7406\u89e3<\/strong>\uff1a\u80a1\u7968\u8868\u73b0\u53ef\u80fd\u4f1a\u53d7\u5230\u5e02\u573a\u6574\u4f53\u56e0\u7d20\u7684\u5f71\u54cd\uff0c\u5305\u62ec\u7ecf\u6d4e\u3001\u5730\u7f18\u653f\u6cbb\u6216\u5168\u7403\u4e8b\u4ef6\uff0c\u8fd9\u4e9b\u56e0\u7d20\u4f1a\u5f71\u54cd\u6574\u4e2a\u5e02\u573a\u73af\u5883\u548c\u6295\u8d44\u8005\u60c5\u7eea\u3002<\/li>\n\n\n\n<li><strong>\u957f\u671f\u8868\u73b0\u7684\u8ddf\u8e2a<\/strong>\uff1a\u6708\u5ea6\u56de\u62a5\u7387\u7684\u6570\u636e\u4f7f\u5f97\u6295\u8d44\u8005\u53ef\u4ee5\u8f7b\u677e\u8ddf\u8e2a\u80a1\u7968\u7684\u957f\u671f\u8868\u73b0\uff0c\u5e76\u8bc6\u522b\u4e00\u81f4\u7684\u8d8b\u52bf\uff0c\u4ee5\u4fbf\u505a\u51fa\u57fa\u4e8e\u6570\u636e\u7684\u6295\u8d44\u51b3\u7b56\u3002<\/li>\n\n\n\n<li><strong>\u6570\u636e\u9a71\u52a8\u7684\u6295\u8d44\u51b3\u7b56<\/strong>\uff1a\u901a\u8fc7\u8ba1\u7b97\u5e73\u5747\u6708\u5ea6\u56de\u62a5\u7387\u548c\u603b\u56de\u62a5\u7387\uff0c\u6295\u8d44\u8005\u53ef\u4ee5\u66f4\u597d\u5730\u7406\u89e3\u81ea\u5df1\u7684\u6295\u8d44\u7ec4\u5408\uff0c\u5e76\u6839\u636e\u4e00\u8d2f\u7684\u8d8b\u52bf\u505a\u51fa\u51b3\u7b56\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u611f\u8c22\u60a8\u9605\u8bfb\u5230\u6700\u540e\uff0c\u5e0c\u671b\u672c\u6587\u80fd\u7ed9\u60a8\u5e26\u6765\u65b0\u7684\u6536\u83b7\u3002\u795d\u60a8\u6295\u8d44\u987a\u5229\uff01\u5982\u679c\u5bf9\u6587\u4e2d\u7684\u5185\u5bb9\u6709\u4efb\u4f55\u7591\u95ee\uff0c\u8bf7\u7ed9\u6211\u7559\u8a00\uff0c\u5fc5\u590d\u3002<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong><mark style=\"background-color:#ffffff\" class=\"has-inline-color has-cyan-bluish-gray-color\">\u672c\u6587\u5185\u5bb9\u4ec5\u4ec5\u662f\u6280\u672f\u63a2\u8ba8\u548c\u5b66\u4e60\uff0c\u5e76\u4e0d\u6784\u6210\u4efb\u4f55\u6295\u8d44\u5efa\u8bae\u3002<\/mark><\/strong><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u8001\u4f59\u635e\u9c7c \u539f\u521b\u4e0d\u6613\uff0c\u8f6c\u8f7d\u8bf7\u6807\u660e\u51fa\u5904\u53ca\u539f\u4f5c\u8005\u3002&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/laoyulaoyu.com\/index.php\/2024\/12\/06\/%e8%bd%bb%e6%9d%be%e4%b8%8a%e6%89%8b%ef%bc%81%e6%99%ba%e8%83%bd%e8%ae%a1%e7%ae%97%e8%82%a1%e7%a5%a8%e5%9b%9e%e6%8a%a5%e7%8e%87%e5%b9%b6%e4%b8%8e%e6%8c%87%e6%95%b0%e7%9b%b8%e8%be%83\/\">Continue reading<span class=\"screen-reader-text\">\u8f7b\u677e\u4e0a\u624b\uff01\u667a\u80fd\u8ba1\u7b97\u80a1\u7968\u56de\u62a5\u7387\u5e76\u4e0e\u6307\u6570\u76f8\u8f83<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[3,5],"class_list":{"0":"post-1691","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-aiinvest","7":"tag-ai","9":"entry"},"_links":{"self":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/comments?post=1691"}],"version-history":[{"count":1,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1691\/revisions"}],"predecessor-version":[{"id":1692,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1691\/revisions\/1692"}],"wp:attachment":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/media?parent=1691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/categories?post=1691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/tags?post=1691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}