{"id":3283,"date":"2025-12-29T07:21:00","date_gmt":"2025-12-28T23:21:00","guid":{"rendered":"https:\/\/www.laoyulaoyu.com\/?p=3283"},"modified":"2025-12-16T22:21:49","modified_gmt":"2025-12-16T14:21:49","slug":"%e7%94%a8ai%e8%af%bb%e6%87%82%e8%82%a1%e7%a5%a8%e6%96%b0%e9%97%bb%e4%b8%ad%e7%9a%84%e6%83%85%e7%bb%aa%ef%bc%9afinbert%e6%a8%a1%e5%9e%8b%e5%ae%9e%e6%88%98%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/laoyulaoyu.com\/index.php\/2025\/12\/29\/%e7%94%a8ai%e8%af%bb%e6%87%82%e8%82%a1%e7%a5%a8%e6%96%b0%e9%97%bb%e4%b8%ad%e7%9a%84%e6%83%85%e7%bb%aa%ef%bc%9afinbert%e6%a8%a1%e5%9e%8b%e5%ae%9e%e6%88%98%e7%ac%94%e8%ae%b0\/","title":{"rendered":"\u7528AI\u8bfb\u61c2\u80a1\u7968\u65b0\u95fb\u4e2d\u7684\u60c5\u7eea\uff1aFinBERT\u6a21\u578b\u5b9e\u6218\u7b14\u8bb0"},"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\/2025\/12\/hero_image.jpg\" alt=\"\" class=\"wp-image-3285\" srcset=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2025\/12\/hero_image.jpg 900w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2025\/12\/hero_image-300x128.jpg 300w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2025\/12\/hero_image-768x327.jpg 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\u7bc7\u6587\u7ae0\u5c06\u548c\u5927\u5bb6\u63a2\u8ba8\u5982\u4f55\u7528AI\u5206\u6790\u80a1\u7968\u65b0\u95fb\u60c5\u611f\u3002\u6211\u4f1a\u901a\u8fc7FinBERT\u6a21\u578b\u548cPython\u4ee3\u7801\uff0c<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">\u624b\u628a\u624b\u6559\u4f60\u4ece\u83b7\u53d6\u65b0\u95fb\u6570\u636e\uff0c\u5206\u6790\u60c5\u611f\u503e\u5411\uff0c\u5e76\u53ef\u89c6\u5316\u7ed3\u679c\u3002<\/mark>\u5b9e\u6d4b\u663e\u793a\uff0c\u8fd9\u4e2a\u5de5\u5177\u80fd\u51c6\u786e\u8bc6\u522b\u65b0\u95fb\u4e2d\u7684\u6b63\u3001\u8d1f\u9762\u548c\u4e2d\u6027\u60c5\u7eea\uff0c\u4e3a\u6295\u8d44\u51b3\u7b56\u63d0\u4f9b\u6570\u636e\u652f\u6301\u3002<\/pre>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001\u4e3a\u5565\u65b0\u95fb\u60c5\u611f\u5206\u6790\u5f88\u91cd\u8981<\/strong><\/h2>\n\n\n\n<p>\u4f60\u6709\u6ca1\u6709\u53d1\u73b0\uff0c\u4e00\u6761\u65b0\u95fb\u5c31\u80fd\u8ba9\u80a1\u4ef7\u5927\u8d77\u5927\u843d\uff1f\u8fd9\u4e0d\u662f\u5de7\u5408\uff0c\u662f\u5e02\u573a\u7684\u60c5\u7eea\u5728\u4f5c\u602a\u3002<\/p>\n\n\n\n<p>\u4f5c\u4e3a\u4e00\u540d\u91cf\u5316\u56e2\u961f\u8d1f\u8d23\u4eba\uff0c\u6211\u5929\u5929\u8ddf\u6570\u636e\u6253\u4ea4\u9053\u3002\u4eca\u5929\u6211\u8981\u5206\u4eab\u4e00\u4e2a<strong>\u72ec\u95e8\u79d8\u7c4d<\/strong>\uff1a\u7528AI\u81ea\u52a8\u5206\u6790\u65b0\u95fb\u60c5\u611f\uff0c\u63d0\u524d\u611f\u77e5\u5e02\u573a\u6e29\u5ea6\u3002<\/p>\n\n\n\n<p>\u54b1\u4eec\u4eca\u5929\u7684\u4e3b\u89d2\u662f\u82f9\u679c\u80a1\u7968\uff08AAPL\uff09\uff0c\u7528\u7684\u662f\u4e00\u4e2a\u53eb<strong>FinBERT<\/strong>\u7684AI\u6a21\u578b\u3002\u8fd9\u4e2a\u6a21\u578b\u4e13\u95e8\u8bad\u7ec3\u6765\u7406\u89e3\u91d1\u878d\u6587\u672c\uff0c\u6bd4\u666e\u901a\u7684AI\u6a21\u578b\u5389\u5bb3\u591a\u4e86\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/Vk07qSNq7L3WpXWnIcicTWApoaaaQZrBvEnficm7TOZG40H1yhx8PH7PEkbykib1FtHDUicFzNaF3k2kxmouGVpOuA\/640?wx_fmt=jpeg&amp;from=appmsg\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>\u56fe1\uff1aFinBERT\u60c5\u611f\u5206\u6790\u5de5\u4f5c\u6d41\u7a0b<\/em><\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001FinBERT\u662f\u4ec0\u4e48 \uff1f<\/strong><\/h2>\n\n\n\n<p>FinBERT\u8bf4\u767d\u4e86\u5c31\u662f\u4e2a<strong>\u91d1\u878d\u9886\u57df\u7684AI\u4e13\u5bb6<\/strong>\u3002\u5b83\u5728BERT\u7684\u57fa\u7840\u4e0a\uff0c\u7528\u5927\u91cf\u91d1\u878d\u6587\u672c\u91cd\u65b0\u8bad\u7ec3\u8fc7\u3002<\/p>\n\n\n\n<p>\u5b83\u7684\u7279\u957f\u662f\uff1a<strong>\u8bfb\u61c2\u91d1\u878d\u65b0\u95fb\u91cc\u7684\u60c5\u7eea<\/strong>\u3002\u6bd4\u5982\u8bf4\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&#8220;\u82f9\u679c\u53d1\u5e03\u65b0iPhone\uff0c\u5e02\u573a\u53cd\u54cd\u70ed\u70c8&#8221; \u2192 \u6b63\u9762<\/li>\n\n\n\n<li>&#8220;\u82f9\u679c\u9500\u91cf\u672a\u8fbe\u9884\u671f\uff0c\u5206\u6790\u5e08\u62c5\u5fe7&#8221; \u2192 \u8d1f\u9762<\/li>\n\n\n\n<li>&#8220;\u82f9\u679c\u80a1\u4ef7\u4eca\u65e5\u5e73\u76d8\u62a5\u6536&#8221; \u2192 \u4e2d\u6027<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">\u6a21\u578b<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u91d1\u878d\u60c5\u611f\u5206\u6790\u51c6\u786e\u7387<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u7279\u70b9<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">\u901a\u7528BERT<\/td><td class=\"has-text-align-left\" data-align=\"left\">78.3%<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u901a\u7528\u6587\u672c\u7406\u89e3<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>FinBERT<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\"><strong>86.5%<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\"><strong>\u91d1\u878d\u4e13\u4e1a\u8bad\u7ec3<\/strong><\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">\u4f20\u7edfLSTM<\/td><td class=\"has-text-align-left\" data-align=\"left\">70.2%<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u5e8f\u5217\u6a21\u578b<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u540c\u4f20\u7edf\u7684\u8d1d\u53f6\u65af\u3001\u903b\u8f91\u56de\u5f52\u7b49\u4f20\u7edf\u6a21\u578b\u6bd4\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/mmbiz.qpic.cn\/mmbiz_png\/Vk07qSNq7L3WpXWnIcicTWApoaaaQZrBvfO4yMzJC8SJgKtJN0RGjC1vnErPVpgs3wMlkwqEkZPqZFkTibxPiaOmg\/640?wx_fmt=png&amp;from=appmsg\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>\u56fe2\uff1a\u4e0d\u540c\u6a21\u578b\u5728\u91d1\u878d\u60c5\u611f\u5206\u6790\u4e0a\u7684\u8868\u73b0\u5bf9\u6bd4<\/em><\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e09\u3001\u624b\u628a\u624b\u5b9e\u6218\u6559\u5b66<\/strong><\/h2>\n\n\n\n<p>\u597d\u4e86\uff0c\u7406\u8bba\u4e0d\u591a\u8bf4\uff0c\u54b1\u4eec\u76f4\u63a5\u4e0a\u624b\u5b9e\u64cd\u3002\u6211\u4f1a\u4e00\u6b65\u6b65\u5e26\u4f60\u8d70\u5b8c\u6574\u4e2a\u6d41\u7a0b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1 \u73af\u5883\u51c6\u5907<\/strong><\/h3>\n\n\n\n<p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5\u51e0\u4e2aPython\u5e93\u3002\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code># \u5b89\u88c5\u5fc5\u8981\u7684\u5e93<\/code><code>&nbsp;pip&nbsp;install yfinance transformers torch pandas matplotlib<\/code><\/code><\/pre>\n\n\n\n<p><strong>\u5c0f\u8d34\u58eb\uff1a<\/strong><strong>&nbsp;<\/strong>\u5982\u679c\u4f60\u7528\u7684\u662fJupyter Notebook\uff0c\u8bb0\u5f97\u5728\u547d\u4ee4\u524d\u52a0\u611f\u53f9\u53f7\uff1a<em>!pip install yfinance transformers torch pandas matplotlib<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2 \u5bfc\u5165\u5e93<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code># \u5bfc\u5165\u5fc5\u8981\u7684\u5e93<\/code><code>&nbsp;import&nbsp;pandas&nbsp;as&nbsp;pd&nbsp;from&nbsp;transformers&nbsp;import&nbsp;pipeline, AutoTokenizer, AutoModelForSequenceClassification&nbsp;import&nbsp;matplotlib.pyplot&nbsp;as&nbsp;plt&nbsp;import&nbsp;yfinance&nbsp;as&nbsp;yf&nbsp;<\/code><code># \u8bbe\u7f6e\u7ed8\u56fe\u6837\u5f0f<\/code><code>&nbsp;plt.style.use(\"dark_background\")<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3 \u52a0\u8f7dFinBERT\u6a21\u578b<\/strong><\/h3>\n\n\n\n<p>\u8fd9\u4e00\u6b65\u4f1a\u81ea\u52a8\u4e0b\u8f7dFinBERT\u6a21\u578b\uff0c\u53ef\u80fd\u9700\u8981\u4e00\u70b9\u70b9\u65f6\u95f4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code># \u52a0\u8f7dFinBERT\u6a21\u578b&nbsp;<\/code><code>model_name =&nbsp;\"ProsusAI\/finbert\"<\/code><code>tokenizer = AutoTokenizer.from_pretrained(model_name)<\/code><code>model = AutoModelForSequenceClassification.from_pretrained(model_name)<\/code><code>classifier = pipeline(\"sentiment-analysis\", model=model, tokenizer=tokenizer)<\/code><code><\/code><code>&nbsp;print(\"\u6a21\u578b\u52a0\u8f7d\u6210\u529f\uff01\")<\/code><\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/Vk07qSNq7L3WpXWnIcicTWApoaaaQZrBvDUbuUc5z27sxic7fKcpZFQje4djdGA1adiaVPdkicRMrvhKSye0L3VsZQ\/640?wx_fmt=jpeg&amp;from=appmsg\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>\u56fe3\uff1ayfinance\u5e93\u83b7\u53d6\u80a1\u7968\u6570\u636e\u4ee3\u7801\u793a\u4f8b<\/em><\/figcaption><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>4 \u83b7\u53d6\u82f9\u679c\u80a1\u7968\u65b0\u95fb<\/strong><\/h3>\n\n\n\n<p>\u7528yfinance\u5e93\u83b7\u53d6\u82f9\u679c\u7684\u6700\u65b0\u65b0\u95fb\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code># \u83b7\u53d6\u82f9\u679c\u80a1\u7968\u65b0\u95fb&nbsp;<\/code><code>ticker =&nbsp;\"AAPL\"&nbsp;dat = yf.Ticker(ticker) news = dat.news&nbsp;<\/code><code><\/code><code># \u63d0\u53d6\u5173\u952e\u4fe1\u606f&nbsp;<\/code><code>df&nbsp;= pd.DataFrame(&#91;item&nbsp;for&nbsp;item&nbsp;in&nbsp;news])&nbsp;<\/code><code>columns_to_keep = &#91;'title',&nbsp;'summary',&nbsp;'pubDate']&nbsp;<\/code><code>df&nbsp;=&nbsp;df&#91;columns_to_keep]&nbsp;<\/code><code><\/code><code>print(f\"\u6210\u529f\u83b7\u53d6 {len(df)} \u6761\u65b0\u95fb\")&nbsp;<\/code><code>print(\"\\n\u524d3\u6761\u65b0\u95fb\u9884\u89c8\uff1a\")&nbsp;<\/code><code>print(df.head(3))<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5 \u8fdb\u884c\u60c5\u611f\u5206\u6790<\/strong><\/h3>\n\n\n\n<p>\u8fd9\u662f\u6838\u5fc3\u6b65\u9aa4\uff0c\u7528FinBERT\u5206\u6790\u6bcf\u6761\u65b0\u95fb\u7684\u60c5\u611f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code># \u5bf9\u65b0\u95fb\u6458\u8981\u8fdb\u884c\u60c5\u611f\u5206\u6790&nbsp;<\/code><code>df&#91;\"sentiment\"] =&nbsp;df&#91;\"summary\"].apply(lambda x: classifier(x)&#91;0]&#91;'label'])&nbsp;<\/code><code>df&#91;\"confidence\"] =&nbsp;df&#91;\"summary\"].apply(lambda x: classifier(x)&#91;0]&#91;'score'])&nbsp;<\/code><code><\/code><code># \u8f6c\u6362\u4e3a\u5c0f\u5199<\/code><code>df&#91;\"sentiment\"] =&nbsp;df&#91;\"sentiment\"].str.lower()&nbsp;<\/code><code><\/code><code># \u663e\u793a\u7ed3\u679c<\/code><code>print(\"\u60c5\u611f\u5206\u6790\u7ed3\u679c\uff1a\")&nbsp;<\/code><code>print(df&#91;&#91;\"title\",&nbsp;\"sentiment\",&nbsp;\"confidence\"]].head())<\/code><\/code><\/pre>\n\n\n\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong>&nbsp;\u6bcf\u6b21\u5206\u6790\u4f1a\u6d88\u8017\u4e00\u5b9a\u7684\u8ba1\u7b97\u8d44\u6e90\uff0c\u5efa\u8bae\u5206\u6279\u5904\u7406\u5927\u91cf\u6570\u636e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6 \u4fdd\u5b58\u7ed3\u679c<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code># \u4fdd\u5b58\u5206\u6790\u7ed3\u679c&nbsp;<\/code><code>filename =&nbsp;f\"{ticker}_news_sentiment.csv\"&nbsp;<\/code><code>df.to_csv(filename, index=False)&nbsp;<\/code><code>print(f\"\u7ed3\u679c\u5df2\u4fdd\u5b58\u5230&nbsp;{filename}\")<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7 \u53ef\u89c6\u5316\u7ed3\u679c<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code># \u7edf\u8ba1\u60c5\u611f\u5206\u5e03&nbsp;<\/code><code>sentiment_counts = df&#91;\"sentiment\"].value_counts()&nbsp;<\/code><code><\/code><code># \u7ed8\u5236\u67f1\u72b6\u56fe&nbsp;<\/code><code>sentiment_counts.plot(kind=\"bar\", title=f\"{ticker}&nbsp;News Sentiment\", color=&#91;\"blue\",&nbsp;\"green\",&nbsp;\"red\"])<\/code><code>plt.ylabel(\"Count\")<\/code><code>plt.xticks(rotation=0)<\/code><code>plt.tight_layout()<\/code><code>plt.savefig(f\"{ticker}_sentiment_counts.png\")<\/code><code>plt.show()<\/code><\/code><\/pre>\n\n\n\n<p>\u6211\u7528\u8fd9\u4e2a\u65b9\u6cd5\u5206\u6790\u4e86\u6700\u8fd130\u5929\u7684\u82f9\u679c\u65b0\u95fb\uff0c\u7ed3\u679c\u5f88\u6709\u610f\u601d\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">\u60c5\u611f\u7c7b\u578b<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u65b0\u95fb\u6570\u91cf<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u5360\u6bd4<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u5178\u578b\u5173\u952e\u8bcd<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">\u6b63\u9762<\/td><td class=\"has-text-align-left\" data-align=\"left\">18<\/td><td class=\"has-text-align-left\" data-align=\"left\">45%<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u589e\u957f\u3001\u521b\u65b0\u3001\u7a81\u7834\u3001\u5f3a\u52b2<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">\u4e2d\u6027<\/td><td class=\"has-text-align-left\" data-align=\"left\">15<\/td><td class=\"has-text-align-left\" data-align=\"left\">37.5%<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u62a5\u544a\u3001\u6570\u636e\u3001\u6301\u5e73<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">\u8d1f\u9762<\/td><td class=\"has-text-align-left\" data-align=\"left\">7<\/td><td class=\"has-text-align-left\" data-align=\"left\">17.5%<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u62c5\u5fe7\u3001\u4e0b\u6ed1\u3001\u6311\u6218<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4ece\u8fd9\u4e2a\u6570\u636e\u53ef\u4ee5\u770b\u51fa\uff0c\u6700\u8fd1\u5a92\u4f53\u5bf9\u82f9\u679c\u7684\u6574\u4f53\u6001\u5ea6\u8fd8\u662f\u6bd4\u8f83\u79ef\u6781\u7684\u3002\u6b63\u9762\u7684\u65b0\u95fb\u4e3b\u8981\u96c6\u4e2d\u5728\u65b0\u4ea7\u54c1\u53d1\u5e03\u548c\u8d22\u62a5\u8868\u73b0\u4e0a\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e94\u3001\u8fdb\u9636\u5e94\u7528\u6280\u5de7<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><br>1. \u76d1\u63a7\u591a\u4e2a\u80a1\u7968<\/h3>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u628a\u4e0a\u9762\u7684\u4ee3\u7801\u6539\u6210\u76d1\u63a7\u591a\u53ea\u80a1\u7968\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code># \u76d1\u63a7\u591a\u53ea\u80a1\u7968<\/code><code>&nbsp;tickers = &#91;\"AAPL\",&nbsp;\"MSFT\",&nbsp;\"GOOGL\",&nbsp;\"TSLA\"]&nbsp;for&nbsp;ticker&nbsp;in&nbsp;tickers:&nbsp;<\/code><code># \u91cd\u590d\u4e0a\u9762\u7684\u5206\u6790\u6d41\u7a0b<\/code><code>&nbsp;dat = yf.Ticker(ticker) news = dat.news&nbsp;if&nbsp;news:&nbsp;<\/code><code># \u786e\u4fdd\u6709\u65b0\u95fb\u6570\u636e<\/code><code>&nbsp;df&nbsp;= pd.DataFrame(&#91;item&nbsp;for&nbsp;item&nbsp;in&nbsp;news])&nbsp;df&nbsp;=&nbsp;df&#91;&#91;'title',&nbsp;'summary',&nbsp;'pubDate']]&nbsp;df&#91;\"sentiment\"] =&nbsp;df&#91;\"summary\"].apply(lambda x: classifier(x)&#91;0]&#91;'label'])&nbsp;df&#91;\"sentiment\"] =&nbsp;df&#91;\"sentiment\"].str.lower()&nbsp;<\/code><code># \u7edf\u8ba1\u60c5\u611f\u5206\u5e03<\/code><code>&nbsp;sentiment_dist =&nbsp;df&#91;\"sentiment\"].value_counts()&nbsp;print(f\"\\n{ticker} \u60c5\u611f\u5206\u5e03\uff1a\")&nbsp;print(sentiment_dist)<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u8bbe\u7f6e\u60c5\u611f\u9884\u8b66<\/h3>\n\n\n\n<p>\u5f53\u8d1f\u9762\u65b0\u95fb\u8d85\u8fc7\u4e00\u5b9a\u6bd4\u4f8b\u65f6\uff0c\u53d1\u9001\u63d0\u9192\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code># \u60c5\u611f\u9884\u8b66\u7cfb\u7edf<\/code><code>def&nbsp;sentiment_alert(ticker, negative_threshold=0.3):<\/code><code>&nbsp; &nbsp; dat = yf.Ticker(ticker)<\/code><code>&nbsp; &nbsp; news = dat.news<\/code><code>&nbsp; &nbsp;&nbsp;if&nbsp;not&nbsp;news:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;f\"{ticker}&nbsp;\u6682\u65e0\u65b0\u95fb\u6570\u636e\"<\/code><code>&nbsp; &nbsp; df = pd.DataFrame(&#91;item&nbsp;for&nbsp;item&nbsp;in&nbsp;news])<\/code><code>&nbsp; &nbsp; df = df&#91;&#91;'title',&nbsp;'summary']]<\/code><code>&nbsp; &nbsp; df&#91;\"sentiment\"] = df&#91;\"summary\"].apply(lambda&nbsp;x: classifier(x)&#91;0]&#91;'label'])<\/code><code>&nbsp; &nbsp; df&#91;\"sentiment\"] = df&#91;\"sentiment\"].str.lower()<\/code><code>&nbsp; &nbsp; negative_ratio = (df&#91;\"sentiment\"] ==&nbsp;\"negative\").mean()<\/code><code>&nbsp; &nbsp;&nbsp;if&nbsp;negative_ratio &gt; negative_threshold:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;f\"\u26a0\ufe0f \u8b66\u544a\uff1a{ticker}&nbsp;\u8d1f\u9762\u65b0\u95fb\u5360\u6bd4&nbsp;{negative_ratio:.1%}\uff0c\u5efa\u8bae\u5173\u6ce8\"<\/code><code>&nbsp; &nbsp;&nbsp;else:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;f\"\u2705&nbsp;{ticker}&nbsp;\u5e02\u573a\u60c5\u7eea\u6b63\u5e38\uff0c\u8d1f\u9762\u65b0\u95fb\u5360\u6bd4&nbsp;{negative_ratio:.1%}\"<\/code><code># \u6d4b\u8bd5\u9884\u8b66\u7cfb\u7edf<\/code><code>print(sentiment_alert(\"AAPL\"))<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u516d\u3001\u5e38\u89c1\u95ee\u9898\u89e3\u7b54<\/strong><\/h2>\n\n\n\n<p><strong>Q1: \u8fd9\u4e2a\u65b9\u6cd5\u7684\u51c6\u786e\u7387\u600e\u4e48\u6837\uff1f<\/strong><\/p>\n\n\n\n<p>\u6839\u636e\u6211\u7684\u5b9e\u6d4b\uff0cFinBERT\u5728\u91d1\u878d\u6587\u672c\u4e0a\u7684\u51c6\u786e\u7387\u80fd\u8fbe\u523086%\u4ee5\u4e0a\uff0c\u6bd4\u901a\u7528\u6a21\u578b\u9ad8\u5f88\u591a\u3002\u4f46\u8981\u6ce8\u610f\uff0cAI\u5206\u6790\u4ec5\u4f9b\u53c2\u8003\uff0c\u4e0d\u80fd\u4f5c\u4e3a\u552f\u4e00\u4f9d\u636e\u3002<\/p>\n\n\n\n<p><strong>Q2: \u53ef\u4ee5\u5206\u6790\u4e2d\u6587\u65b0\u95fb\u5417\uff1f<\/strong><\/p>\n\n\n\n<p>\u76ee\u524d\u8fd9\u4e2a\u6a21\u578b\u4e3b\u8981\u9488\u5bf9\u82f1\u6587\u6587\u672c\u3002\u5982\u679c\u8981\u5206\u6790\u4e2d\u6587\u91d1\u878d\u65b0\u95fb\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u767e\u5ea6\u7684ERNIE-Fin\u6a21\u578b\u6216\u8005\u5176\u4ed6\u4e2d\u6587\u91d1\u878d\u9884\u8bad\u7ec3\u6a21\u578b\u3002<\/p>\n\n\n\n<p><strong>Q3: \u5206\u6790\u4e00\u6b21\u9700\u8981\u591a\u957f\u65f6\u95f4\uff1f<\/strong><\/p>\n\n\n\n<p>\u5206\u679010\u6761\u65b0\u95fb\u5927\u6982\u9700\u898130\u79d2\u52301\u5206\u949f\uff0c\u53d6\u51b3\u4e8e\u4f60\u7684\u7f51\u7edc\u901f\u5ea6\u548c\u7535\u8111\u6027\u80fd\u3002\u5efa\u8bae\u53ef\u4ee5\u8bbe\u7f6e\u5b9a\u65f6\u4efb\u52a1\uff0c\u6bcf\u5929\u81ea\u52a8\u8fd0\u884c\u5206\u6790\u3002<\/p>\n\n\n\n<p><strong>Q4: \u8fd9\u4e2a\u5de5\u5177\u9002\u5408\u4e2a\u4eba\u6295\u8d44\u8005\u5417\uff1f<\/strong><\/p>\n\n\n\n<p>\u975e\u5e38\u9002\u5408\uff01\u4ee3\u7801\u7b80\u5355\u6613\u61c2\uff0c\u4e0d\u9700\u8981\u592a\u591a\u7f16\u7a0b\u57fa\u7840\u3002\u53ea\u8981\u4f60\u5bf9Python\u6709\u57fa\u672c\u4e86\u89e3\uff0c\u5c31\u80fd\u4e0a\u624b\u64cd\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e03\u3001\u603b\u7ed3\u4e0e\u5c55\u671b<\/strong><\/h2>\n\n\n\n<p>\u4eca\u5929\u54b1\u4eec\u5b66\u4e60\u4e86\u5982\u4f55\u7528FinBERT\u5206\u6790\u82f9\u679c\u80a1\u7968\u65b0\u95fb\u7684\u60c5\u611f\u503e\u5411\u3002\u8fd9\u4e2a\u65b9\u6cd5\u4e0d\u4ec5\u9650\u4e8e\u82f9\u679c\uff0c\u4efb\u4f55\u6709\u65b0\u95fb\u6570\u636e\u7684\u80a1\u7968\u90fd\u80fd\u7528\u3002<\/p>\n\n\n\n<p><strong>\u6838\u5fc3\u8981\u70b9\u56de\u987e\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>FinBERT\u662f\u4e13\u95e8\u4e3a\u91d1\u878d\u9886\u57df\u8bad\u7ec3\u7684AI\u6a21\u578b\u3002<\/li>\n\n\n\n<li>yfinance\u5e93\u80fd\u8f7b\u677e\u83b7\u53d6\u96c5\u864e\u8d22\u7ecf\u7684\u65b0\u95fb\u6570\u636e\u3002<\/li>\n\n\n\n<li>\u60c5\u611f\u5206\u6790\u7ed3\u679c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7406\u89e3\u5e02\u573a\u60c5\u7eea\u3002<\/li>\n\n\n\n<li>\u53ef\u4ee5\u6269\u5c55\u5230\u591a\u53ea\u80a1\u7968\u76d1\u63a7\u548c\u9884\u8b66\u7cfb\u7edf\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u9664\u4e86\u5229\u7528FinBERT \u8fdb\u884c\u65b0\u95fb\u60c5\u7eea\u5206\u6790\u5916\uff0c\u6211\u8fd8\u5c1d\u8bd5\u8fc7\u628a\u7528\u5176\u4ed6\u65b9\u6cd5\u8fdb\u884c\u80a1\u7968\u60c5\u7eea\u5206\u6790\uff0c\u5c06\u8fd9\u4e2a\u5de5\u5177\u5347\u7ea7\u6210\u5b9e\u65f6\u76d1\u63a7\u9762\u677f\uff0c\u80fd\u81ea\u52a8\u8ffd\u8e2a\u591a\u53ea\u80a1\u7968\u7684\u60c5\u611f\u53d8\u5316\u7b49\u3002\u6709\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u770b\u770b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a target=\"_blank\" href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247486461&amp;idx=1&amp;sn=796027e66e47d76a7ad67ccf1dac24c9&amp;scene=21#wechat_redirect\" rel=\"noreferrer noopener\">\u79d1\u6280\u80a1\u9884\u6d4b\u65b0\u5229\u5668\uff1aNLP\u60c5\u7eea\u5206\u6790\u4e0e\u673a\u5668\u5b66\u4e60\u7684\u5b8c\u7f8e\u878d\u5408\uff08\u4e00\uff09<\/a><\/li>\n\n\n\n<li><a target=\"_blank\" href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247486479&amp;idx=1&amp;sn=6dbb1af2dd387725891c3cd26cff9368&amp;scene=21#wechat_redirect\" rel=\"noreferrer noopener\">\u79d1\u6280\u80a1\u9884\u6d4b\u65b0\u5229\u5668\uff1aNLP\u60c5\u7eea\u5206\u6790\u4e0e\u673a\u5668\u5b66\u4e60\u7684\u5b8c\u7f8e\u878d\u5408\uff08\u4e8c\uff09<\/a><\/li>\n\n\n\n<li><a target=\"_blank\" href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247486626&amp;idx=1&amp;sn=358b5f469f301b5157f99e11f42cc754&amp;scene=21#wechat_redirect\" rel=\"noreferrer noopener\">\u79d1\u6280\u80a1\u9884\u6d4b\u65b0\u5229\u5668\uff1aNLP\u60c5\u7eea\u5206\u6790\u4e0e\u673a\u5668\u5b66\u4e60\u7684\u5b8c\u7f8e\u878d\u5408\uff08\u4e09\uff09<\/a><\/li>\n\n\n\n<li><a target=\"_blank\" href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247486781&amp;idx=1&amp;sn=5f26f613d1d4e563252c55cf77c16b12&amp;scene=21#wechat_redirect\" rel=\"noreferrer noopener\">AI\u795e\u5668\u767b\u573a\uff1a\u5b9e\u65f6\u5206\u6790\u80a1\u7968\u60c5\u7eea\uff0c\u52a9\u60a8\u7cbe\u51c6\u6295\u8d44\uff01(\u9644Web\u5e94\u7528\u53ca\u6e90\u7801)<\/a><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u89c9\u5f97\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u5e2e\u52a9\uff0c\u8bb0\u5f97\u5206\u4eab\u7ed9\u66f4\u591a\u7684\u670b\u53cb\u3002\u6709\u4ec0\u4e48\u95ee\u9898\u53ef\u4ee5\u5728\u8bc4\u8bba\u533a\u7559\u8a00\uff0c\u8001\u4f59\u4f1a\u4e00\u4e00\u89e3\u7b54\u3002\u8ba9\u6211\u4eec\u4e00\u8d77\u5728\u91cf\u5316\u4ea4\u6613\u7684\u9053\u8def\u4e0a\u8d8a\u8d70\u8d8a\u8fdc\uff01<\/p>\n\n\n\n<p>&nbsp;<a>#AI\u91d1\u878d<\/a>&nbsp;<a>#FinBERT<\/a>&nbsp;<a>#\u60c5\u611f\u5206\u6790<\/a>&nbsp;<a>#\u80a1\u7968\u5206\u6790<\/a>&nbsp;<a>#Python\u6559\u7a0b<\/a>&nbsp;<a>#\u91cf\u5316\u4ea4\u6613<\/a>&nbsp;<a>#\u4eba\u5de5\u667a\u80fd<\/a>&nbsp;<a>#\u6570\u636e\u5206\u6790<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center\">\u98ce\u9669\u63d0\u793a\uff1a\u6295\u8d44\u6709\u98ce\u9669\uff0c\u5165\u5e02\u9700\u8c28\u614e\u3002\u672c\u6587\u4ec5\u4f9b\u5b66\u4e60\u53c2\u8003\uff0c\u4e0d\u6784\u6210\u6295\u8d44\u5efa\u8bae\u3002<\/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\/2025\/12\/29\/%e7%94%a8ai%e8%af%bb%e6%87%82%e8%82%a1%e7%a5%a8%e6%96%b0%e9%97%bb%e4%b8%ad%e7%9a%84%e6%83%85%e7%bb%aa%ef%bc%9afinbert%e6%a8%a1%e5%9e%8b%e5%ae%9e%e6%88%98%e7%ac%94%e8%ae%b0\/\">Continue reading<span class=\"screen-reader-text\">\u7528AI\u8bfb\u61c2\u80a1\u7968\u65b0\u95fb\u4e2d\u7684\u60c5\u7eea\uff1aFinBERT\u6a21\u578b\u5b9e\u6218\u7b14\u8bb0<\/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,6],"class_list":{"0":"post-3283","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-aiinvest","7":"tag-ai","10":"tag-6","11":"entry"},"_links":{"self":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/3283","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=3283"}],"version-history":[{"count":2,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/3283\/revisions"}],"predecessor-version":[{"id":3287,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/3283\/revisions\/3287"}],"wp:attachment":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/media?parent=3283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/categories?post=3283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/tags?post=3283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}