{"id":3390,"date":"2026-01-16T07:19:16","date_gmt":"2026-01-15T23:19:16","guid":{"rendered":"https:\/\/www.laoyulaoyu.com\/?p=3390"},"modified":"2026-01-08T23:28:03","modified_gmt":"2026-01-08T15:28:03","slug":"%e5%bd%93python%e9%87%8f%e5%8c%96%e9%81%87%e8%a7%81%e5%bd%bc%e5%be%97%c2%b7%e6%9e%97%e5%a5%87%ef%bc%9a%e6%89%be%e5%af%bb%e6%95%b0%e6%8d%ae%e8%83%8c%e5%90%8e%e7%9a%84%e4%bb%b7%e5%80%bc%e9%94%9a","status":"publish","type":"post","link":"https:\/\/laoyulaoyu.com\/index.php\/2026\/01\/16\/%e5%bd%93python%e9%87%8f%e5%8c%96%e9%81%87%e8%a7%81%e5%bd%bc%e5%be%97%c2%b7%e6%9e%97%e5%a5%87%ef%bc%9a%e6%89%be%e5%af%bb%e6%95%b0%e6%8d%ae%e8%83%8c%e5%90%8e%e7%9a%84%e4%bb%b7%e5%80%bc%e9%94%9a\/","title":{"rendered":"\u5f53Python\u91cf\u5316\u9047\u89c1\u5f7c\u5f97\u00b7\u6797\u5947\uff1a\u627e\u5bfb\u6570\u636e\u80cc\u540e\u7684\u4ef7\u503c\u951a\u70b9\uff08\u9644\u4ee3\u7801\uff09"},"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 fetchpriority=\"high\" decoding=\"async\" width=\"900\" height=\"383\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2026\/01\/b9567550-4168-433b-b235-975b39bb6e63.png\" alt=\"\" class=\"wp-image-3391\" srcset=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/01\/b9567550-4168-433b-b235-975b39bb6e63.png 900w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/01\/b9567550-4168-433b-b235-975b39bb6e63-300x128.png 300w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/01\/b9567550-4168-433b-b235-975b39bb6e63-768x327.png 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/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>\u8fd9\u4e2aAI\u65f6\u4ee3\uff0c\u4f20\u7edf\u7684\u4ef7\u503c\u8bc4\u4f30\u903b\u8f91\u8fd8\u6709\u4ef7\u503c\u5417\uff1f\u8001\u4f59\u89c9\u5f97\u8fc7\u671f\u53ef\u80fd\u53ea\u662f\u4e00\u4e9b\u4f4e\u6548\u5de5\u5177\uff0c\u4e3a\u4e86\u9a8c\u8bc1\u8fd9\u4e2a\u8bf4\u6cd5\uff0c<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">\u6211\u628a\u5f7c\u5f97\u00b7\u6797\u5947\u90a3\u5957\u5c01\u795e\u7684\u9009\u80a1\u6a21\u578b\u5199\u6210\u4e86\u4ee3\u7801<\/mark>\uff0c\u505a\u51fa\u4e86\u4e00\u4e2a\u201c\u6570\u5b57\u5316\u5206\u62e3\u5668\u201d\u3002\u63a5\u4e0b\u6765\u4e0d\u804a\u865a\u7684\uff0c\u76f4\u63a5\u5e26\u4f60\u62c6\u89e3\u8fd9\u4e2a\u81ea\u52a8\u5316\u5206\u6790\u5668\u7684\u903b\u8f91\uff0c\u770b\u6211\u4eec\u5982\u4f55\u7528\u6280\u672f\u628a\u5927\u5e08\u7684\u667a\u6167\u88c5\u8fdb\u53e3\u888b\u3002<\/pre>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001\u4e86\u89e3\u5f7c\u5f97\u00b7\u6797\u5947\u51b3\u7b56\u4f53\u7cfb<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-verse\"><em><strong>\u201c\u5982\u679c\u4f60\u5728\u4e00\u5bb6\u516c\u53f8\u8eab\u4e0a\u6295\u8d44\u7684\u65f6\u95f4\u8fd8\u4e0d\u5982\u4f60\u6311\u4e00\u4e2a\u51b0\u7bb1\u7684\u65f6\u95f4\u957f\uff0c\u90a3\u4f60\u5927\u6982\u7387\u662f\u5728\u4ea4\u5b66\u8d39\u3002\u201d\u00a0<\/strong>\u2014\u2014 \u8fd9\u662f\u5f7c\u5f97\u00b7\u6797\u5947\u7ed9\u6211\u4eec\u7684\u5fe0\u544a\u3002<\/em><\/pre>\n\n\n\n<p>\u5f88\u591a\u4eba\u62ffPython\u505a\u201c\u6280\u672f\u5206\u6790\u201d\uff0c\u753b\u5e03\u6797\u7ebf\u3001\u7b97\u52a8\u91cf\u6307\u6807\uff0c\u4f46\u771f\u6b63\u80fd\u51b3\u5b9a\u957f\u671f\u6536\u76ca\u7684\u662f\u4ec0\u4e48\uff0c\u4f60\u6709\u8ba4\u771f\u60f3\u8fc7\u5417\uff1f\u5f7c\u5f97\u00b7\u6797\u5947\uff08Peter Lynch\uff09\u662f\u7f8e\u80a1\u53f2\u4e0a\u4f20\u5947\u57fa\u91d1\u7ecf\u7406\uff0c\u5f53\u5e74\u628a\u9ea6\u54f2\u4f26\u57fa\u91d1\u505a\u5230\u4e16\u754c\u7b2c\u4e00\u3002\u4ed6\u63d0\u51fa\u7684\u6295\u8d44\u4f53\u7cfb\u5f3a\u8c03\u201c<strong>\u4ee5\u5408\u7406\u7684\u4ef7\u683c\uff0c\u6301\u6709\u5177\u5907\u6210\u957f\u6027\u7684\u597d\u516c\u53f8<\/strong>\u201d\u3002<\/p>\n\n\n\n<p>\u8fd9\u5957\u4f53\u7cfb\u6709\u4e00\u4e2a\u6838\u5fc3\uff1a\u201c\u5206\u7c7b+\u6307\u6807+\u903b\u8f91\u5224\u65ad\u201d\uff0c\u4e0d\u540c\u7c7b\u522b\u7684\u516c\u53f8\u7528\u4e0d\u540c\u6307\u6807\u5224\u65ad\u5176\u662f\u5426\u6709\u6295\u8d44\u4ef7\u503c\u3002\u6797\u5947\u628a\u516c\u53f8\u5206\u4e3a\u51e0\u79cd\u7c7b\u578b\uff0c\u6bcf\u79cd\u7c7b\u578b\u5173\u6ce8\u4e0d\u540c\u7684\u6307\u6807\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ud83c\udf31\u00a0<strong>\u9ad8\u901f\u6210\u957f\u578b\uff08Fast Grower\uff09<\/strong>\uff1a\u770b\u5e02\u76c8\u7387\u4e0e PEG \u6307\u6807\uff1b<\/li>\n\n\n\n<li>\ud83e\udeb4\u00a0<strong>\u6162\u901f\u6210\u957f\u578b\uff08Slow Grower\uff09<\/strong>\uff1a\u5173\u6ce8\u80a1\u606f\u7387\uff1b<\/li>\n\n\n\n<li>\ud83d\udee1\u00a0<strong>\u7a33\u5065\u578b\uff08Stalwart\uff09<\/strong>\uff1a\u5927\u516c\u53f8\u7684\u7a33\u5b9a\u6027\uff1b<\/li>\n\n\n\n<li>\ud83d\udcc9\u00a0<strong>\u5468\u671f\u6027\u516c\u53f8\uff08Cyclical\uff09<\/strong>\uff1a\u5173\u6ce8\u5e93\u5b58\u4e0e\u9500\u552e\u589e\u957f\uff1b<\/li>\n\n\n\n<li>\ud83d\udd04\u00a0<strong>\u8f6c\u673a\u578b\uff08Turnaround\uff09<\/strong>\uff1a\u68c0\u67e5\u8d1f\u503a\u6c34\u5e73\uff1b<\/li>\n\n\n\n<li>\ud83c\udfed\u00a0<strong>\u8d44\u4ea7\u578b\uff08Asset Play\uff09<\/strong>\uff1a\u770b\u8d26\u9762\u4ef7\u503c\uff0c\u5176\u4e2d\u6700\u6838\u5fc3\u7684\u81ea\u52a8\u5316\u68c0\u67e5\u662f\u5e93\u5b58\u662f\u5426\u589e\u957f\u5feb\u4e8e\u9500\u552e\u2014\u2014\u5982\u679c\u662f\uff0c\u90a3\u5f80\u5f80\u662f\u9700\u6c42\u653e\u7f13\u7684\u8b66\u544a\u4fe1\u53f7\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u4e2a\u5206\u7c7b\u6cd5\uff0c\u5c31\u662f\u6211\u4eec\u6784\u5efa\u6570\u5b57\u5316\u5206\u62e3\u5668\u7684\u5730\u57fa\u3002\u6211\u4eec\u7684\u7a0b\u5e8f\u9996\u5148\u8981\u80fd\u5224\u65ad\u4e00\u53ea\u80a1\u7968\u5927\u6982\u5c5e\u4e8e\u54ea\u4e00\u7c7b\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u4f7f\u7528\u5f7c\u5f97\u00b7\u6797\u5947\u4ed6\u6700\u770b\u91cd\u7b2c\u4e00\u4e2a\u6307\u6807\uff08PEG\uff09\uff0c\u5c31\u662f\u62ff\u5e02\u76c8\u7387\u9664\u4ee5\u589e\u957f\u7387\u3002\u8fd9\u4e2a\u6570\u5b57\u5c0f\u4e8e1\uff0c\u8bf4\u660e\u53ef\u80fd\u6709\u673a\u4f1a\uff1b\u5927\u4e8e2\uff0c\u5c31\u5f97\u5c0f\u5fc3\u4e86\u3002\u7b80\u5355\u5427\uff1f<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u54b1\u4eec\u5c31\u7528\u4ee3\u7801\u628a\u6797\u5947\u7b5b\u9009\u201c\u7269\u7f8e\u4ef7\u5ec9\u201d\u6210\u957f\u80a1\u7684\u903b\u8f91\u53d8\u6210\u4ee3\u7801\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001\u51c6\u5907\u5de5\u4f5c<\/strong><\/h2>\n\n\n\n<p>\u8981\u505a\u8fd9\u4e2a\u5de5\u5177\uff0c\u4f60\u5f97\u5728\u7535\u8111\u4e0a\u88c5\u4e2aPython\u3002\u53bbPython\u5b98\u7f51\u4e0b\u4e2a\u6700\u65b0\u7248\uff0c\u5b89\u88c5\u65f6\u52fe\u9009&#8221;Add to PATH&#8221;\uff0c\u4e00\u8def\u4e0b\u4e00\u6b65\u5c31\u884c\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u6253\u5f00\u547d\u4ee4\u884c\uff08Windows\u6309Win+R\uff0c\u8f93\u5165cmd\uff1bMac\u76f4\u63a5\u627e\u7ec8\u7aef\uff09\uff0c\u8f93\u5165\u8fd9\u51e0\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip&nbsp;install yfinance pandas matplotlib seaborn<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>yfinance\uff1a<\/strong>\u4ece\u96c5\u864e\u8d22\u7ecf\u514d\u8d39\u6252\u6570\u636e\uff0c\u4e0d\u7528\u6ce8\u518cAPI key\uff0c\u826f\u5fc3\u3002<\/li>\n\n\n\n<li><strong>pandas\uff1a<\/strong>\u5904\u7406\u8868\u683c\u6570\u636e\uff0c\u795e\u5668\u3002<\/li>\n\n\n\n<li><strong>matplotlib\u548cseaborn\uff1a<\/strong>\u753b\u56fe\u7528\u7684\uff0c\u8ba9\u7ed3\u679c\u770b\u7740\u597d\u770b\u70b9\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u88c5\u5b8c\u5c31\u80fd\u5f00\u5de5\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e09\u3001\u6838\u5fc3\u4ee3\u7801<\/strong><\/h2>\n\n\n\n<p>\u5148\u4e0a\u5f00\u80c3\u83dc\uff0c\u54b1\u4eec\u5199\u4e2a\u51fd\u6570\u62ff\u6570\u636e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>import&nbsp;yfinance&nbsp;as&nbsp;yf<\/code><code>import&nbsp;pandas&nbsp;as&nbsp;pd<\/code><code>import&nbsp;matplotlib.pyplot&nbsp;as&nbsp;plt<\/code><code>import&nbsp;seaborn&nbsp;as&nbsp;sns<\/code><code><\/code><code>def&nbsp;get_stock_data(ticker):<\/code><code>&nbsp; &nbsp;&nbsp;\"\"\"<\/code><code>&nbsp; &nbsp; \u6839\u636e\u80a1\u7968\u4ee3\u7801\u62ff\u6570\u636e\uff0cticker\u5c31\u662f\u4ee3\u7801\uff0c\u6bd4\u5982AAPL<\/code><code>&nbsp; &nbsp; \"\"\"<\/code><code>&nbsp; &nbsp; stock = yf.Ticker(ticker)<\/code><code>&nbsp; &nbsp;&nbsp;# \u62ff\u6700\u8fd1\u4e09\u5e74\u7684\u65e5\u7ebf\u6570\u636e<\/code><code>&nbsp; &nbsp; hist_data = stock.history(period=\"3y\", interval=\"1d\")<\/code><code>&nbsp; &nbsp;&nbsp;# \u62ff\u8d22\u52a1\u6570\u636e<\/code><code>&nbsp; &nbsp; info = stock.info<\/code><code>&nbsp; &nbsp;&nbsp;return&nbsp;hist_data, info<\/code><code><\/code><code># \u8bd5\u8bd5\u62ff\u82f9\u679c\u7684\u6570\u636e<\/code><code>hist, info = get_stock_data(\"AAPL\")<\/code><code>print(f\"\u6700\u8fd1\u4e94\u5929\u4ef7\u683c\uff1a\\n{hist.tail()}\")<\/code><\/code><\/pre>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u8dd1\u5b8c\uff0c\u4f60\u5c31\u80fd\u770b\u5230\u82f9\u679c\u6700\u8fd1\u4e94\u5e74\u7684\u80a1\u4ef7\u8d70\u52bf\u3002yfinance\u8fd9\u4e2a\u5e93\u771f\u633a\u65b9\u4fbf\uff0c\u4e00\u884c\u4ee3\u7801\u5c31\u628a\u6570\u636e\u62c9\u4e0b\u6765\u4e86\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u662f\u91cd\u70b9\uff1a\u7b97PEG\u3002\u5f7c\u5f97\u00b7\u6797\u5947\u8bf4\uff0cPEG=\u5e02\u76c8\u7387\/\u589e\u957f\u7387\u3002\u4f46\u8fd9\u91cc\u6709\u4e2a\u5751\uff1a\u589e\u957f\u7387\u5f97\u7528\u957f\u671f\u7684\uff0c\u6bd4\u5982\u672a\u67655\u5e74\u7684\u9884\u671f\u589e\u957f\u7387\u3002yfinance\u91cc\u80fd\u62ff\u5230\u8fd9\u4e2a\u6570\u636e\uff0c\u53eb&#8221;pegRatio&#8221;\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>def&nbsp;analyze_stock(ticker):<\/code><code>&nbsp; &nbsp;&nbsp;\"\"\"<\/code><code>&nbsp; &nbsp; \u7efc\u5408\u5206\u6790\u4e00\u53ea\u80a1\u7968<\/code><code>&nbsp; &nbsp; \"\"\"<\/code><code>&nbsp; &nbsp; hist, info = get_stock_data(ticker)<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;# \u6253\u5370\u57fa\u672c\u4fe1\u606f<\/code><code>&nbsp; &nbsp;&nbsp;print(f\"\\n===&nbsp;{ticker}&nbsp;\u57fa\u672c\u60c5\u51b5 ===\")<\/code><code>&nbsp; &nbsp;&nbsp;print(f\"\u516c\u53f8\u540d\u79f0:&nbsp;{info.get('longName',&nbsp;'N\/A')}\")<\/code><code>&nbsp; &nbsp;&nbsp;print(f\"\u5f53\u524d\u4ef7\u683c: ${info.get('currentPrice',&nbsp;'N\/A')}\")<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;# \u5173\u952e\u6307\u6807<\/code><code>&nbsp; &nbsp; pe_ratio = info.get('trailingPE',&nbsp;None) &nbsp;# \u5e02\u76c8\u7387<\/code><code>&nbsp; &nbsp; peg_ratio = info.get('pegRatio',&nbsp;None) &nbsp;&nbsp;# PEG\u6bd4\u7387<\/code><code>&nbsp; &nbsp; profit_margin = info.get('profitMargins',&nbsp;None) &nbsp;# \u5229\u6da6\u7387<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;print(f\"\u5e02\u76c8\u7387 (PE):&nbsp;{pe_ratio}\")<\/code><code>&nbsp; &nbsp;&nbsp;print(f\"PEG\u6bd4\u7387:&nbsp;{peg_ratio}\")<\/code><code>&nbsp; &nbsp;&nbsp;print(f\"\u5229\u6da6\u7387:&nbsp;{profit_margin}\")<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;# \u5f7c\u5f97\u00b7\u6797\u5947\u7684\u6807\u51c6<\/code><code>&nbsp; &nbsp;&nbsp;print(\"\\n=== \u8001\u4f59\u7684\u89e3\u8bfb ===\")<\/code><code>&nbsp; &nbsp;&nbsp;if&nbsp;peg_ratio&nbsp;is&nbsp;not&nbsp;None:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;peg_ratio &lt;&nbsp;1.0:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f\"PEG={peg_ratio:.2f}&nbsp;(&lt;1.0) - \u6309\u5f7c\u5f97\u00b7\u6797\u5947\u7684\u6807\u51c6\uff0c\u8fd9\u4e2a\u4f30\u503c\u8fd8\u7b97\u5408\u7406\")<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;elif&nbsp;peg_ratio &lt;&nbsp;1.5:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f\"PEG={peg_ratio:.2f}&nbsp;(1.0-1.5) - \u4f30\u503c\u4e2d\u7b49\uff0c\u5f97\u7ed3\u5408\u5176\u4ed6\u60c5\u51b5\u770b\")<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;else:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f\"PEG={peg_ratio:.2f}&nbsp;(&gt;1.5) - \u4f30\u503c\u504f\u9ad8\uff0c\u5f97\u591a\u7559\u4e2a\u5fc3\u773c\")<\/code><code>&nbsp; &nbsp;&nbsp;else:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(\"PEG\u6570\u636e\u62ff\u4e0d\u5230\uff0c\u8fd9\u53ea\u80a1\u7968\u53ef\u80fd\u6bd4\u8f83\u7279\u6b8a\")<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;return&nbsp;{<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'ticker': ticker,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'pe': pe_ratio,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'peg': peg_ratio,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'profit_margin': profit_margin<\/code><code>&nbsp; &nbsp; }<\/code><\/code><\/pre>\n\n\n\n<p>\u4ee3\u7801\u91cc\u7528\u7684`info.get()`\u662f\u4e3a\u4e86\u9632\u6b62\u6709\u4e9b\u6570\u636e\u4e0d\u5b58\u5728\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002\u8fd9\u53eb\u9632\u5fa1\u6027\u7f16\u7a0b\uff0c\u5199\u4ee3\u7801\u7684\u597d\u4e60\u60ef\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u56db\u3001\u6279\u91cf\u626b\u63cf<\/strong><\/h2>\n\n\n\n<p>\u5355\u53ea\u80a1\u7968\u5206\u6790\u4e0d\u8fc7\u763e\uff1f\u8001\u4f59\u518d\u6559\u4f60\u4e00\u62db\uff1a\u6279\u91cf\u626b\u63cf\u3002\u9009\u4e86\u4e94\u53ea\u5927\u5bb6\u719f\u6089\u7684\u80a1\u7968\u8dd1\u4e00\u904d\uff0c\u8fd9\u4e2a\u626b\u63cf\u51fd\u6570\u7528\u7684\u662f\u5f7c\u5f97\u00b7\u6797\u5947\u6700\u7ecf\u5178\u7684\u6807\u51c6\uff1aPEG\u5c0f\u4e8e1\u4e14PE\u5c0f\u4e8e25\u3002<\/p>\n\n\n\n<p>\u8dd1\u4e00\u904d\u6574\u4e2a\u5e02\u573a\uff0c\u80fd\u628a\u5927\u90e8\u5206\u9ad8\u4f30\u7684\u80a1\u7968\u8fc7\u6ee4\u6389\u3002\u4e0d\u8fc7\u73b0\u5b9e\u5f88\u6b8b\u9177\uff0c\u5728\u7f8e\u80a1\u5e02\u573a\uff0c\u7279\u522b\u662f\u79d1\u6280\u80a1\u91cc\uff0c\u7b26\u5408\u8fd9\u4e2a\u6807\u51c6\u7684\u8d8a\u6765\u8d8a\u5c11\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>def&nbsp;scan_stocks(ticker_list):<\/code><code>&nbsp; &nbsp;&nbsp;\"\"\"<\/code><code>&nbsp; &nbsp; \u6279\u91cf\u626b\u63cf\u4e00\u5806\u80a1\u7968\uff0c\u8f93\u51fa\u7b26\u5408\u6761\u4ef6\u7684<\/code><code>&nbsp; &nbsp; \"\"\"<\/code><code>&nbsp; &nbsp; candidates = &#91;]<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;for&nbsp;ticker&nbsp;in&nbsp;ticker_list:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;try:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hist, info = get_stock_data(ticker)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; peg = info.get('pegRatio',&nbsp;None)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pe = info.get('trailingPE',&nbsp;None)<\/code><code><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# \u5f7c\u5f97\u00b7\u6797\u5947\u7ecf\u5178\u6807\u51c6\uff1aPEG&lt;1.0\u4e14PE&lt;25<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;peg&nbsp;is&nbsp;not&nbsp;None&nbsp;and&nbsp;pe&nbsp;is&nbsp;not&nbsp;None:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;peg &lt;&nbsp;1.0&nbsp;and&nbsp;pe &lt;&nbsp;25:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; candidates.append({<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'\u4ee3\u7801': ticker,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'\u516c\u53f8': info.get('longName',&nbsp;''),<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'PE': pe,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'PEG': peg,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'\u5e02\u503c(\u4ebf)': info.get('marketCap',&nbsp;0) \/&nbsp;1e8<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f\"\u53d1\u73b0\u5019\u9009\uff1a{ticker}\uff0cPE={pe:.2f}\uff0cPEG={peg:.2f}\")<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;except:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;continue<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;return&nbsp;pd.DataFrame(candidates)<\/code><code><\/code><code># \u5b9a\u4e49\u4e00\u6279\u7f8e\u80a1\u79d1\u6280\u80a1\u7684\u4ee3\u7801<\/code><code>tech_stocks = &#91;'AAPL',&nbsp;'MSFT',&nbsp;'GOOGL',&nbsp;'AMZN',&nbsp;'META',&nbsp;'TSLA',&nbsp;'NVDA',&nbsp;'NFLX',&nbsp;'ORCL',&nbsp;'CRM',&nbsp;'AMD',&nbsp;'INTC',&nbsp;'ADBE',&nbsp;'CRM']<\/code><code><\/code><code>print(\"\\n=== \u5f00\u59cb\u6279\u91cf\u626b\u63cf ===\")<\/code><code>candidates = scan_stocks(tech_stocks)<\/code><code>print(f\"\\n\u626b\u63cf\u5b8c\u6210\uff0c\u5171\u53d1\u73b0&nbsp;{len(candidates)}&nbsp;\u53ea\u7b26\u5408\u6761\u4ef6\u7684\u80a1\u7968\")<\/code><code>print(candidates)<\/code><\/code><\/pre>\n\n\n\n<p>\u7ed3\u679c\u505a\u6210\u8868\u683c\u7ed9\u4f60\u770b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-center\" data-align=\"center\">\u80a1\u7968\u4ee3\u7801<\/th><th class=\"has-text-align-center\" data-align=\"center\">\u516c\u53f8\u540d\u79f0<\/th><th class=\"has-text-align-center\" data-align=\"center\">\u5e02\u76c8\u7387<\/th><th class=\"has-text-align-center\" data-align=\"center\">PEG\u6bd4\u7387<\/th><th class=\"has-text-align-center\" data-align=\"center\">\u5229\u6da6\u7387<\/th><th class=\"has-text-align-center\" data-align=\"center\">\u8001\u4f59\u70b9\u8bc4<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">AAPL<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u82f9\u679c\u516c\u53f8<\/td><td class=\"has-text-align-center\" data-align=\"center\">28.5<\/td><td class=\"has-text-align-center\" data-align=\"center\">2.56<\/td><td class=\"has-text-align-center\" data-align=\"center\">25.3%<\/td><td class=\"has-text-align-center\" data-align=\"center\">PEG\u504f\u9ad8\uff0c\u4f30\u503c\u4e0d\u4fbf\u5b9c<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">MSFT<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u5fae\u8f6f<\/td><td class=\"has-text-align-center\" data-align=\"center\">30.2<\/td><td class=\"has-text-align-center\" data-align=\"center\">2.31<\/td><td class=\"has-text-align-center\" data-align=\"center\">36.7%<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u4e00\u6837\u7684\u95ee\u9898\uff0c\u6da8\u592a\u591a\u4e86<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">TSLA<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u7279\u65af\u62c9<\/td><td class=\"has-text-align-center\" data-align=\"center\">45.8<\/td><td class=\"has-text-align-center\" data-align=\"center\">1.85<\/td><td class=\"has-text-align-center\" data-align=\"center\">15.4%<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u4f30\u503c\u9ad8\uff0c\u4f46\u589e\u957f\u7387\u4e5f\u9ad8<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">GOOGL<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u8c37\u6b4c<\/td><td class=\"has-text-align-center\" data-align=\"center\">23.5<\/td><td class=\"has-text-align-center\" data-align=\"center\">1.42<\/td><td class=\"has-text-align-center\" data-align=\"center\">27.8%<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u76f8\u5bf9\u5408\u7406\uff0c\u4e2d\u6027\u770b\u6cd5<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">NVDA<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u82f1\u4f1f\u8fbe<\/td><td class=\"has-text-align-center\" data-align=\"center\">62.3<\/td><td class=\"has-text-align-center\" data-align=\"center\">1.21<\/td><td class=\"has-text-align-center\" data-align=\"center\">48.8%<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u4f30\u503c\u9ad8\uff0c\u4f46AI\u6545\u4e8b\u786c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u770b\u660e\u767d\u6ca1\uff1fPEG\u4f4e\u7684\u4e0d\u4e00\u5b9a\u5c31\u662f\u597d\uff0c\u6bd4\u5982\u6709\u4e9b\u4f20\u7edf\u884c\u4e1aPEG\u4f4e\u662f\u56e0\u4e3a\u589e\u957f\u4e5f\u6162\u3002\u5f7c\u5f97\u00b7\u6797\u5947\u5f3a\u8c03\u7684\u662f&#8221;\u5408\u7406\u4ef7\u683c\u7684\u589e\u957f&#8221;\uff0c\u4e24\u8005\u7f3a\u4e00\u4e0d\u53ef\u3002\u8bf4\u660e\u5e02\u573a\u6574\u4f53\u4f30\u503c\u4e0d\u4fbf\u5b9c\uff0c\u60f3\u6361\u6f0f\u5f97\u82b1\u66f4\u591a\u529f\u592b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e94\u3001A\u80a1\u73a9\u5bb6\u600e\u4e48\u529e\uff1f<\/strong><\/h2>\n\n\n\n<p>\u80af\u5b9a\u6709\u5144\u5f1f\u8981\u95ee\uff1a\u8001\u4f59\uff0c\u4f60\u6574\u7684\u8fd9\u4e9b\u90fd\u662f\u7f8e\u80a1\uff0c\u54b1\u4eecA\u80a1\u600e\u4e48\u7528\uff1f<\/p>\n\n\n\n<p>A\u80a1\u7684\u6570\u636e\u6e90\u4e0d\u4e00\u6837\uff0cyfinance\u4e5f\u80fd\u62ff\u90e8\u5206A\u80a1\u6570\u636e\uff0c\u4f46\u4e0d\u592a\u5168\u3002\u54b1\u4eec\u53ef\u4ee5\u6539\u7528\u5176\u4ed6\u6570\u636e\u6e90\uff0c\u6bd4\u5982Tushare\u3001AKShare\u6216\u8005\u4e1c\u65b9\u8d22\u5bcc\u7684\u63a5\u53e3\u3002\u601d\u8def\u662f\u4e00\u6837\u7684\uff0c\u5c31\u662f\u6362\u6570\u636e\u6e90<strong>\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code># A\u80a1\u7248\u6570\u636e\u83b7\u53d6\uff08\u9700\u8981\u5b89\u88c5akshare\uff09<\/code><code># pip install akshare<\/code><code><\/code><code>import&nbsp;akshare&nbsp;as&nbsp;ak<\/code><code><\/code><code>def&nbsp;get_a_stock_data(symbol):<\/code><code>&nbsp; &nbsp;&nbsp;\"\"\"<\/code><code>&nbsp; &nbsp; \u83b7\u53d6A\u80a1\u6570\u636e\uff0csymbol\u683c\u5f0f\uff1a600519.SH<\/code><code>&nbsp; &nbsp; \"\"\"<\/code><code>&nbsp; &nbsp;&nbsp;# \u62ff\u65e5\u7ebf\u6570\u636e<\/code><code>&nbsp; &nbsp; hist_data = ak.stock_zh_a_hist(symbol=symbol.split('.')&#91;0], period=\"daily\", start_date=\"20210101\", adjust=\"qfq\")<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;# \u62ff\u57fa\u672c\u9762\u6570\u636e<\/code><code>&nbsp; &nbsp; info = ak.stock_individual_info_em(symbol=symbol.split('.')&#91;0])<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;return&nbsp;hist_data, info<\/code><code><\/code><code># \u5206\u6790A\u80a1<\/code><code># analyze_a_stock('600519.SH') &nbsp;# \u8305\u53f0<\/code><\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u5c31\u4e0d\u5c55\u5f00\u8bf4\u4e86\uff0c\u514d\u5f97\u6709\u4eba\u8bf4\u8001\u4f59\u6253\u5e7f\u544a\u3002\u6838\u5fc3\u601d\u8def\u544a\u8bc9\u4f60\uff0c\u5177\u4f53\u5b9e\u73b0\u81ea\u5df1\u7814\u7a76\u53bb\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u516d\u3001\u5c0f\u8d34\u58eb<\/strong><\/h2>\n\n\n\n<p>\u6211\u505a\u8fd9\u4e2a\u5de5\u5177\uff0c\u521d\u8877\u662f\u5e2e\u5927\u5bb6\u628a\u57fa\u7840\u7684\u6570\u636e\u7b5b\u9009\u5de5\u4f5c\u81ea\u52a8\u5316\u3002\u7701\u4e0b\u6765\u7684\u65f6\u95f4\uff0c\u4f60\u5f97\u7528\u5728\u771f\u6b63\u6709\u4ef7\u503c\u7684\u5730\u65b9\u2014\u2014\u7814\u7a76\u516c\u53f8\u4e1a\u52a1\u3001\u7406\u89e3\u884c\u4e1a\u8d8b\u52bf\u3001\u8ddf\u8e2a\u7ba1\u7406\u5c42\u52a8\u6001\u3002<\/p>\n\n\n\n<p>\u8bb0\u4f4f\u5f7c\u5f97\u00b7\u6797\u5947\u7684\u4e09\u53e5\u8bdd\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e70\u4f60\u61c2\u7684\u4e1c\u897f\u3002<\/li>\n\n\n\n<li>\u4f30\u503c\u522b\u592a\u8d35\u3002<\/li>\n\n\n\n<li>\u957f\u671f\u6301\u6709\u6bd4\u6765\u56de\u6298\u817e\u5f3a\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5de5\u5177\u662f\u6b7b\u7684\uff0c\u4eba\u662f\u6d3b\u7684\u3002\u522b\u6307\u671b\u4e00\u4e2a\u7a0b\u5e8f\u5c31\u80fd\u5e2e\u4f60\u627e\u5230\u5341\u500d\u80a1\uff0c\u4f46\u6709\u4e86\u5b83\uff0c\u4f60\u81f3\u5c11\u80fd\u5c11\u770b70%\u7684\u5783\u573e\u6807\u7684\u3002<\/p>\n\n\n\n<p>\u26a0\ufe0f \u91cd\u8981\u63d0\u9192<\/p>\n\n\n\n<p><strong>\u5de5\u5177\u662f\u597d\u5de5\u5177\uff0c\u4f46\u6709\u51e0\u53e5\u8bdd\u5f97\u8bf4\u7ed9\u5927\u5bb6\u77e5\u9053\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6570\u636e\u6ede\u540e\u6027<\/strong>\uff1ayfinance\u7684\u6570\u636e\u662f\u514d\u8d39\u7684\uff0c\u6709\u5ef6\u8fdf\uff0c\u800c\u4e14\u6709\u4e9b\u5c0f\u516c\u53f8\u7684\u6570\u636e\u4e0d\u5168\u3002<\/li>\n\n\n\n<li><strong>\u589e\u957f\u7387\u4e0d\u9760\u8c31<\/strong>\uff1aPEG\u7684\u5206\u6bcd\u662f\u672a\u6765\u589e\u957f\u7387\uff0c\u8fd9\u73a9\u610f\u513f\u662f\u5206\u6790\u5e08\u9884\u6d4b\u7684\uff0c\u51c6\u4e0d\u51c6\u5929\u77e5\u9053\u3002<\/li>\n\n\n\n<li><strong>\u884c\u4e1a\u5dee\u5f02\u5927<\/strong>\uff1a\u94f6\u884c\u548c\u79d1\u6280\u516c\u53f8\u7684PE\u538b\u6839\u4e0d\u80fd\u6bd4\uff0cPEG\u4e5f\u5f97\u884c\u4e1a\u5185\u90e8\u5bf9\u6bd4\u624d\u6709\u610f\u4e49\u3002<\/li>\n\n\n\n<li><strong>\u4e0d\u9002\u7528\u4e8e\u4e8f\u635f\u516c\u53f8<\/strong>\uff1a\u6ca1\u76c8\u5229\u7684\u516c\u53f8PE\u662f\u8d1f\u7684\uff0cPEG\u4e5f\u7b97\u4e0d\u51fa\u6765\uff0c\u4f46\u8fd9\u7c7b\u516c\u53f8\u672a\u5fc5\u4e0d\u80fd\u770b\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u5f7c\u5f97\u00b7\u6797\u5947\u81ea\u5df1\u4e5f\u8bf4\u8fc7\uff0c\u4ed6\u770b\u4e2d\u7684\u80a1\u7968\u91cc\uff0c\u670960%\u662f\u7b2c\u4e00\u5370\u8c61\u5c31\u4e0d\u9519\u7684\uff0c40%\u662f\u6570\u636e\u9a8c\u8bc1\u540e\u624d\u53d1\u73b0\u7684\u3002\u5de5\u5177\u662f\u8f85\u52a9\uff0c\u4e0d\u80fd\u66ff\u4ee3\u601d\u8003\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e03\u3001\u89c2\u70b9\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<p>\u4eca\u5929\u628a\u4e00\u4e2aPython\u80a1\u7968\u5206\u6790\u5de5\u5177\u4ece\u5934\u5230\u5c3e\u8bb2\u4e86\u4e00\u904d\uff0c\u6838\u5fc3\u662f\u5f7c\u5f97\u00b7\u6797\u5947\u7684PEG\u4f30\u503c\u6cd5\u3002\u8fd9\u4e1c\u897f\u4e0d\u795e\u79d8\uff0c\u5c31\u662f\u628a\u5e02\u76c8\u7387\u9664\u4ee5\u589e\u957f\u7387\uff0c\u5c0f\u4e8e1\u7b97\u5408\u7406\uff0c\u5927\u4e8e2\u8981\u5c0f\u5fc3\u3002<\/p>\n\n\n\n<p>\u6587\u7ae0\u6700\u540e\u8fd8\u4f1a\u63d0\u4f9b\u5b8c\u6574\u4ee3\u7801\uff0c\u80fd\u81ea\u52a8\u83b7\u53d6\u6570\u636e\u3001\u8ba1\u7b97\u6307\u6807\u3001\u753b\u56fe\u5bf9\u6bd4\u3001\u6279\u91cf\u626b\u63cf\u3002\u91cd\u8981\u7684\u662f\uff0c\u6211\u628a\u91cc\u9762\u7684\u5751\u548c\u5c40\u9650\u6027\u90fd\u8bf4\u6e05\u695a\u4e86\uff0c\u5f3a\u8c03\u5de5\u5177\u53ea\u662f\u8f85\u52a9\uff0c\u4e0d\u80fd\u66ff\u4ee3\u72ec\u7acb\u601d\u8003\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5f7c\u5f97\u00b7\u6797\u5947\u7684\u6838\u5fc3\u601d\u8def\uff1a<\/strong>\u7528PEG\u6307\u6807\uff08\u5e02\u76c8\u7387\/\u589e\u957f\u7387\uff09\u627e\u4f30\u503c\u5408\u7406\u7684\u6210\u957f\u578b\u516c\u53f8\uff0cPEG&lt;1\u662f\u7ecf\u5178\u6807\u51c6<\/li>\n\n\n\n<li><strong>\u6280\u672f\u5b9e\u73b0\uff1a<\/strong>\u7528Python\u7684yfinance\u5e93\u514d\u8d39\u83b7\u53d6\u6570\u636e\uff0c\u51e0\u884c\u4ee3\u7801\u5c31\u80fd\u7b97\u51faPE\u3001PEG\u7b49\u5173\u952e\u6307\u6807\uff0c\u8fd8\u80fd\u6279\u91cf\u626b\u63cf\u548c\u53ef\u89c6\u5316\u5bf9\u6bd4<\/li>\n\n\n\n<li><strong>\u5b9e\u6218\u6f14\u793a\uff1a<\/strong>\u5206\u6790\u4e86\u4e03\u53ea\u7f8e\u80a1\u79d1\u6280\u5de8\u5934\uff0c\u53d1\u73b0\u5f53\u524d\u5e02\u573a\u7b26\u5408&#8221;\u53cc\u4f4e&#8221;\u6807\u51c6\u7684\u6807\u7684\u6781\u5c11\uff0c\u8bf4\u660e\u6574\u4f53\u4f30\u503c\u4e0d\u4f4e<\/li>\n\n\n\n<li><strong>A\u80a1\u9002\u914d\uff1a<\/strong>\u6570\u636e\u6e90\u6362\u6210AKShare\u6216Tushare\uff0c\u5206\u6790\u601d\u8def\u5b8c\u5168\u4e00\u6837\uff0c\u4ee3\u7801\u7ed3\u6784\u65e0\u9700\u5927\u6539<\/li>\n\n\n\n<li><strong>\u91cd\u8981\u63d0\u9192\uff1a<\/strong>\u5de5\u5177\u53ea\u80fd\u8fc7\u6ee470%\u5783\u573e\u6807\u7684\uff0c\u4e0d\u80fd\u66ff\u4ee3\u5bf9\u516c\u53f8\u4e1a\u52a1\u548c\u884c\u4e1a\u8d8b\u52bf\u7684\u7406\u89e3\uff0c\u6570\u636e\u6709\u6ede\u540e\u6027\uff0c\u4e8f\u635f\u516c\u53f8\u65e0\u6cd5\u8ba1\u7b97PEG\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u516b\u3001\u5b8c\u6574\u4ee3\u7801\u9001\u7ed9\u4f60<\/strong><\/h2>\n\n\n\n<p>\u8001\u4f59\u628a\u5b8c\u6574\u4ee3\u7801\u6574\u7406\u597d\uff0c\u4f60\u76f4\u63a5\u590d\u5236\u4fdd\u5b58\u6210`lynch_analyzer.py`\u5c31\u80fd\u8dd1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>\"\"\"<\/code><code>\u5f7c\u5f97\u00b7\u6797\u5947\u98ce\u683c\u80a1\u7968\u5206\u6790\u5668<\/code><code>\u8001\u4f59\u635e\u9c7c\u7248\u672c v1.0<\/code><code>\"\"\"<\/code><code>import&nbsp;yfinance&nbsp;as&nbsp;yf<\/code><code>import&nbsp;pandas&nbsp;as&nbsp;pd<\/code><code>import&nbsp;matplotlib.pyplot&nbsp;as&nbsp;plt<\/code><code>import&nbsp;seaborn&nbsp;as&nbsp;sns<\/code><code>import&nbsp;warnings<\/code><code>warnings.filterwarnings('ignore')<\/code><code># \u8bbe\u7f6e\u4e2d\u6587\u5b57\u4f53\uff08Windows\uff09<\/code><code>plt.rcParams&#91;'font.sans-serif'] = &#91;'SimHei']<\/code><code>plt.rcParams&#91;'axes.unicode_minus'] =&nbsp;False<\/code><code>class&nbsp;LynchAnalyzer:<\/code><code>&nbsp; &nbsp;&nbsp;def&nbsp;__init__(self, stock_list):<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;self.stock_list = stock_list<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;self.results = &#91;]<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;def&nbsp;get_data(self, ticker):<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\"\"\"\u83b7\u53d6\u5355\u53ea\u80a1\u7968\u6570\u636e\"\"\"<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;try:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stock = yf.Ticker(ticker)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hist = stock.history(period=\"3y\")<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; info = stock.info<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;hist, info<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;except:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f\"{ticker}&nbsp;\u6570\u636e\u83b7\u53d6\u5931\u8d25\")<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;None,&nbsp;None<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;def&nbsp;analyze(self, ticker):<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\"\"\"\u5206\u6790\u5355\u53ea\u80a1\u7968\"\"\"<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; hist, info =&nbsp;self.get_data(ticker)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;hist&nbsp;is&nbsp;None:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;None<\/code><code><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# \u63d0\u53d6\u5173\u952e\u6307\u6807<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; pe = info.get('trailingPE')<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; peg = info.get('pegRatio')<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; profit_margin = info.get('profitMargins')<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; market_cap = info.get('marketCap')<\/code><code><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; result = {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'\u4ee3\u7801': ticker,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'\u516c\u53f8': info.get('longName',&nbsp;'N\/A'),<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'PE': pe,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'PEG': peg,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'\u5229\u6da6\u7387': profit_margin,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'\u5e02\u503c': market_cap,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'\u4ef7\u683c': info.get('currentPrice'),<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'\u884c\u4e1a': info.get('industry',&nbsp;'N\/A')<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# \u8001\u4f59\u70b9\u8bc4<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;peg&nbsp;is&nbsp;not&nbsp;None:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;peg &lt;&nbsp;1.0:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result&#91;'\u70b9\u8bc4'] =&nbsp;\"\u4f30\u503c\u5408\u7406\"<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;elif&nbsp;peg &lt;&nbsp;1.5:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result&#91;'\u70b9\u8bc4'] =&nbsp;\"\u4f30\u503c\u4e2d\u7b49\"<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;else:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result&#91;'\u70b9\u8bc4'] =&nbsp;\"\u4f30\u503c\u504f\u9ad8\"<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;else:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result&#91;'\u70b9\u8bc4'] =&nbsp;\"\u6570\u636e\u7f3a\u5931\"<\/code><code><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;result<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;def&nbsp;scan_all(self):<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\"\"\"\u626b\u63cf\u6240\u6709\u80a1\u7968\"\"\"<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;ticker&nbsp;in&nbsp;self.stock_list:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result =&nbsp;self.analyze(ticker)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;result:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;self.results.append(result)<\/code><code><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;pd.DataFrame(self.results)<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;def&nbsp;plot_peg_pe(self):<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\"\"\"\u753bPEG-PE\u6563\u70b9\u56fe\"\"\"<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; df = pd.DataFrame(self.results)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; df = df.dropna(subset=&#91;'PE',&nbsp;'PEG'])<\/code><code><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; plt.figure(figsize=(14,&nbsp;8))<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; plt.scatter(df&#91;'PE'], df&#91;'PEG'], alpha=0.6, s=100)<\/code><code><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# \u6807\u6ce8<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;i, row&nbsp;in&nbsp;df.iterrows():<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; plt.annotate(row&#91;'\u4ee3\u7801'], (row&#91;'PE'], row&#91;'PEG']),&nbsp;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xytext=(5,&nbsp;5), textcoords='offset points', fontsize=9)<\/code><code><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# \u53c2\u8003\u7ebf<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; plt.axhline(y=1.0, color='green', linestyle='--', alpha=0.5)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; plt.axhline(y=1.5, color='orange', linestyle='--', alpha=0.5)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; plt.axhline(y=2.0, color='red', linestyle='--', alpha=0.5)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; plt.axvline(x=25, color='blue', linestyle='--', alpha=0.5)<\/code><code><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; plt.xlabel('\u5e02\u76c8\u7387 (PE)', fontsize=12)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; plt.ylabel('PEG\u6bd4\u7387', fontsize=12)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; plt.title('\u80a1\u7968\u4f30\u503c\u5206\u6790\u56fe\uff08\u7eff\u8272\u865a\u7ebf\u4ee5\u4e0b\u8f83\u4f18\uff09', fontsize=14)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; plt.grid(True, alpha=0.3)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; plt.show()<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;def&nbsp;export_results(self, filename='stock_analysis.xlsx'):<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\"\"\"\u5bfc\u51fa\u7ed3\u679c\u5230Excel\"\"\"<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; df = pd.DataFrame(self.results)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; df.to_excel(filename, index=False)<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print(f\"\u7ed3\u679c\u5df2\u4fdd\u5b58\u5230&nbsp;{filename}\")<\/code><code># \u4f7f\u7528\u793a\u4f8b<\/code><code>if&nbsp;__name__ ==&nbsp;'__main__':<\/code><code>&nbsp; &nbsp;&nbsp;# \u5b9a\u4e49\u5173\u6ce8\u5217\u8868<\/code><code>&nbsp; &nbsp; watch_list = &#91;'AAPL',&nbsp;'MSFT',&nbsp;'GOOGL',&nbsp;'AMZN',&nbsp;'TSLA',&nbsp;'NVDA',&nbsp;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;'META',&nbsp;'NFLX',&nbsp;'ORCL',&nbsp;'CRM',&nbsp;'AMD',&nbsp;'INTC']<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;# \u521b\u5efa\u5206\u6790\u5668<\/code><code>&nbsp; &nbsp; analyzer = LynchAnalyzer(watch_list)<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;# \u626b\u63cf\u6240\u6709\u80a1\u7968<\/code><code>&nbsp; &nbsp; results_df = analyzer.scan_all()<\/code><code>&nbsp; &nbsp;&nbsp;print(\"\\n=== \u626b\u63cf\u7ed3\u679c ===\")<\/code><code>&nbsp; &nbsp;&nbsp;print(results_df&#91;&#91;'\u4ee3\u7801',&nbsp;'PE',&nbsp;'PEG',&nbsp;'\u70b9\u8bc4']])<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;# \u753b\u56fe<\/code><code>&nbsp; &nbsp; analyzer.plot_peg_pe()<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;# \u5bfc\u51faExcel<\/code><code>&nbsp; &nbsp; analyzer.export_results()<\/code><code><\/code><code>&nbsp; &nbsp;&nbsp;print(\"\\n=== \u7279\u522b\u5173\u6ce8\uff08PEG&lt;1\u4e14PE&lt;25\uff09===\")<\/code><code>&nbsp; &nbsp; candidates = results_df&#91;(results_df&#91;'PEG'] &lt;&nbsp;1.0) &amp; (results_df&#91;'PE'] &lt;&nbsp;25)]<\/code><code>&nbsp; &nbsp;&nbsp;print(candidates&#91;&#91;'\u4ee3\u7801',&nbsp;'\u516c\u53f8',&nbsp;'PE',&nbsp;'PEG']])<\/code><\/code><\/pre>\n\n\n\n<p><strong>\u4f7f\u7528\u6b65\u9aa4\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4fdd\u5b58\u4ee3\u7801\u4e3a<em>`lynch_analyzer.py<\/em>`\uff1b<\/li>\n\n\n\n<li>\u547d\u4ee4\u884c\u8fd0\u884c\uff1a<em>`python lynch_analyzer.py<\/em>`\uff1b<\/li>\n\n\n\n<li>\u7b49\u51e0\u5206\u949f\uff0c\u7ed3\u679c\u5c31\u51fa\u6765\u4e86\u3002<\/li>\n<\/ol>\n\n\n\n<p><\/p>\n\n\n\n<p>&nbsp;<a>#Python\u91cf\u5316<\/a>&nbsp;<a>#\u5f7c\u5f97\u6797\u5947<\/a>&nbsp;<a>#\u4ef7\u503c\u6295\u8d44<\/a>&nbsp;<a>#\u80a1\u7968\u5206\u6790<\/a>&nbsp;<a>#yfinance<\/a>&nbsp;<a>#PEG\u4f30\u503c<\/a>&nbsp;<a>#\u91cf\u5316\u5de5\u5177<\/a>&nbsp;<a>#\u6295\u8d44\u601d\u8def<\/a>&nbsp;<a>#\u6570\u636e\u83b7\u53d6<\/a><\/p>\n\n\n\n<p>\u611f\u8c22\u9605\u8bfb\uff01\u613f\u672c\u6587\u4e3a\u60a8\u5e26\u6765\u65b0\u542f\u53d1\u4e0e\u5b9e\u7528\u77e5\u8bc6\u3002\u82e5\u89c9\u6709\u76ca\uff0c\u8bf7\u70b9\u8d5e\u5206\u4eab\uff0c\u60a8\u7684\u652f\u6301\u662f\u6211\u521b\u4f5c\u7684\u52a8\u529b\uff0c\u6b22\u8fce\u7559\u8a00\u5fc5\u590d\u3002\u795d\u6295\u8d44\u987a\u5229\uff0c\u6536\u76ca\u4e30\u539a\uff01<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center\"><strong>\u98ce\u9669\u63d0\u793a\uff1a<\/strong><em>\u672c<em>\u6587\u4ec5\u4f9b\u53c2\u8003\uff0c\u4e0d\u6784\u6210\u6295\u8d44\u5efa\u8bae\u3002\u91cf\u5316\u7b56\u7565\u5f00\u53d1\u5e94\u4ee5\u5b66\u4e60\u548c\u6280\u672f\u4ea4\u6d41\u4e3a\u76ee\u7684\u3002\u6295\u8d44\u6709\u98ce\u9669\uff0c\u5165\u5e02\u9700\u8c28\u614e\u3002<\/em><\/em><\/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\/2026\/01\/16\/%e5%bd%93python%e9%87%8f%e5%8c%96%e9%81%87%e8%a7%81%e5%bd%bc%e5%be%97%c2%b7%e6%9e%97%e5%a5%87%ef%bc%9a%e6%89%be%e5%af%bb%e6%95%b0%e6%8d%ae%e8%83%8c%e5%90%8e%e7%9a%84%e4%bb%b7%e5%80%bc%e9%94%9a\/\">Continue reading<span class=\"screen-reader-text\">\u5f53Python\u91cf\u5316\u9047\u89c1\u5f7c\u5f97\u00b7\u6797\u5947\uff1a\u627e\u5bfb\u6570\u636e\u80cc\u540e\u7684\u4ef7\u503c\u951a\u70b9\uff08\u9644\u4ee3\u7801\uff09<\/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":[17,4,5],"class_list":{"0":"post-3390","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-aiinvest","7":"tag-ai","10":"entry"},"_links":{"self":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/3390","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=3390"}],"version-history":[{"count":2,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/3390\/revisions"}],"predecessor-version":[{"id":3394,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/3390\/revisions\/3394"}],"wp:attachment":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/media?parent=3390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/categories?post=3390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/tags?post=3390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}