{"id":1871,"date":"2025-02-01T07:55:00","date_gmt":"2025-01-31T23:55:00","guid":{"rendered":"https:\/\/blog.laoyulaoyu.top\/?p=1871"},"modified":"2025-01-06T16:11:47","modified_gmt":"2025-01-06T08:11:47","slug":"%e6%8f%ad%e7%a7%98macd%e5%9c%a8%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e7%ae%97%e6%b3%95%e4%ba%a4%e6%98%93%e4%b8%ad%e7%9a%84%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.laoyulaoyu.com\/index.php\/2025\/02\/01\/%e6%8f%ad%e7%a7%98macd%e5%9c%a8%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e7%ae%97%e6%b3%95%e4%ba%a4%e6%98%93%e4%b8%ad%e7%9a%84%e5%ba%94%e7%94%a8\/","title":{"rendered":"\u63ed\u79d8MACD\u5728\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u4ea4\u6613\u4e2d\u7684\u5e94\u7528"},"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\/2025\/01\/120802.png\" alt=\"\" class=\"wp-image-3774\"\/><\/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>\u6700\u8fd1\u6211\u7814\u7a76\u4e86\u4e00\u79cd\u7ed3\u5408MACD\u548c\u673a\u5668\u5b66\u4e60\u7684\u7b97\u6cd5\u4ea4\u6613\u7b56\u7565\u3002<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">\u901a\u8fc7MACD\u7684\u52a8\u91cf\u6355\u6349\u80fd\u529b\u4e0e\u673a\u5668\u5b66\u4e60\u7684\u6a21\u5f0f\u8bc6\u522b\u76f8\u7ed3\u5408\uff0c\u4e3a\u4ea4\u6613\u8005\u63d0\u4f9b\u4e86\u524d\u6240\u672a\u6709\u7684\u9884\u6d4b\u7cbe\u5ea6<\/mark>\u3002\u8fd9\u79cd\u7ed3\u5408\u4e0d\u4ec5\u589e\u5f3a\u4e86\u4ea4\u6613\u51b3\u7b56\u7684\u79d1\u5b66\u6027\uff0c\u4e5f\u4e3a\u5e02\u573a\u53c2\u4e0e\u8005\u5e26\u6765\u4e86\u65b0\u7684\u673a\u9047\u3002\u5982\u679c\u4f60\u4e5f\u60f3\u8ba9\u4ea4\u6613\u66f4\u667a\u80fd\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4f1a\u7ed9\u4f60\u5e26\u6765\u5168\u65b0\u601d\u8def\uff01<\/pre>\n<\/blockquote>\n\n\n\n<p>\u5728\u77ac\u606f\u4e07\u53d8\u7684\u91d1\u878d\u5e02\u573a\u4e2d\uff0c\u673a\u5668\u5b66\u4e60\u9a71\u52a8\u7684\u7b97\u6cd5\u4ea4\u6613\u6b63\u5f7b\u5e95\u6539\u53d8\u4ea4\u6613\u8005\u7684\u6e38\u620f\u89c4\u5219\u3002\u5c3d\u7ba1MACD\u4f5c\u4e3a\u6280\u672f\u4ea4\u6613\u4e2d\u7684\u7ecf\u5178\u6307\u6807\u5e7f\u4e3a\u4eba\u77e5\uff0c\u4f46\u5b83\u540c\u6837\u53ef\u4ee5\u878d\u5165\u56e0\u5b50\u6a21\u578b\uff0c\u6210\u4e3a\u673a\u5668\u5b66\u4e60\u9884\u6d4b\u7684\u5f3a\u5927\u5de5\u5177\u3002\u672c\u6587\u5c06\u6df1\u5165\u5256\u6790MACD\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u5e76\u5c55\u793a\u5982\u4f55\u901a\u8fc7\u673a\u5668\u5b66\u4e60\u6280\u672f\uff0c\u5c06\u5176\u5347\u7ea7\u4e3a\u9884\u6d4b\u80a1\u7968\u6536\u76ca\u7684\u667a\u80fd\u5316\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2025\/01\/image-40-694x1024.png\" alt=\"\" class=\"wp-image-3776\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001\u4ec0\u4e48\u662f MACD\uff1f<\/strong><\/h2>\n\n\n\n<p id=\"3848\">MACD\uff0c\u5168\u79f0\u4e3a\u79fb\u52a8\u5e73\u5747\u6536\u655b\u53d1\u6563\u6307\u6807\uff08Moving Average Convergence Divergence\uff09\uff0c\u662f\u6295\u8d44\u8005\u5728\u80a1\u5e02\u5206\u6790\u4e2d\u5e7f\u6cdb\u91c7\u7528\u7684\u4e00\u79cd\u6280\u672f\u5206\u6790\u5de5\u5177\u3002<strong>\u7b80\u5355\u6765\u8bf4\uff0c\u5b83\u4f7f\u7528\u4e24\u6761\u79fb\u52a8\u5e73\u5747\u7ebf\u6765\u5e2e\u52a9\u9884\u6d4b\u4f55\u65f6\u4e70\u5165\u6216\u5356\u51fa\u3002<\/strong><\/p>\n\n\n\n<p id=\"3848\">\u4f60\u53ef\u4ee5\u8fd9\u6837\u60f3\u8c61\u4e00\u4e0b\uff0c\u4f60\u6b63\u5728\u89c2\u5bdf\u6bd4\u8d5b\u4e2d\u7684\u4e24\u4f4d\u9009\u624b\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e00\u540d\u9009\u624b\u4ee3\u8868\u77ed\u671f\u52bf\u5934\uff08\u66f4\u5feb\uff09\u3002<\/li>\n\n\n\n<li>\u53e6\u4e00\u4e2a\u4ee3\u8868\u957f\u671f\u52a8\u529b\uff08\u8f83\u6162\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p id=\"7c41\">\u5f53\u8dd1\u5f97\u5feb\u7684\u4eba\u8d85\u8fc7\u8dd1\u5f97\u6162\u7684\u4eba\u65f6\uff0c\u9884\u793a\u7740\u4e0a\u5347\u8d8b\u52bf\uff08\u770b\u6da8\uff09\u3002\u5982\u679c\u8dd1\u5f97\u6162\u7684\u8d85\u8fc7\u8dd1\u5f97\u5feb\u7684\uff0c\u5219\u9884\u793a\u7740\u4e0b\u964d\u8d8b\u52bf\uff08\u770b\u8dcc\uff09\u3002\u8fd9\u4e2a\u7b80\u5355\u7684\u7c7b\u6bd4\u6709\u52a9\u4e8e\u6211\u4eec\u7406\u89e3 MACD \u5982\u4f55\u6355\u6349\u80a1\u7968\u4ef7\u683c\u7684\u52a8\u91cf\u53d8\u5316\u3002<\/p>\n\n\n\n<p>\u6211\u66fe\u7ecf\u5199\u8fc7\u4e00\u7bc7\u6587\u7ae0\u4ecb\u7ecd\u300a<a href=\"https:\/\/blog.laoyulaoyu.top\/index.php\/2024\/12\/04\/%e5%86%85%e5%b9%95%e6%8f%ad%e7%a7%98%ef%bc%9a%e7%8e%a9%e8%bd%acmacd%e6%8a%80%e6%9c%af%ef%bc%8c%e7%a0%b4%e8%af%91%e8%82%a1%e7%a5%a8%e7%9b%88%e5%88%a9%e5%af%86%e7%a0%81%ef%bc%8c%e6%8f%90%e5%89%8d\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u5185\u5e55\u63ed\u79d8\uff1a\u73a9\u8f6cMACD\u6280\u672f\uff0c\u7834\u8bd1\u80a1\u7968\u76c8\u5229\u5bc6\u7801\uff0c\u63d0\u524d\u5e03\u5c40\u7ffb\u500d\u6536\u76ca\uff01<\/a>\u300b\uff0c\u4f1a\u6709\u52a9\u4e8e\u60a8\u8fdb\u4e00\u6b65\u7406\u89e3MACD\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001MACD \u7684\u7ec4\u6210<\/strong><\/h2>\n\n\n\n<p id=\"bh-bNhHyEe4rAX5j9_gDgOQ0\"><strong>MACD\u4e3b\u8981\u7531\u4e09\u4e2a\u90e8\u5206\u7ec4\u6210\uff1a<\/strong><\/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-45.png\" alt=\"\" class=\"wp-image-2874\"\/><\/figure>\n<\/div>\n\n\n<ol id=\"bh-aA23eGba2Njh-18Shk--8\" class=\"wp-block-list\">\n<li><strong>MACD\u7ebf<\/strong>\uff1a\u8fd9\u662f\u77ed\u671f\uff08\u901a\u5e38\u4e3a12\u5929\uff09\u548c\u957f\u671f\uff08\u901a\u5e38\u4e3a26\u5929\uff09\u6307\u6570\u79fb\u52a8\u5e73\u5747\u7ebf\uff08EMA\uff09\u4e4b\u95f4\u7684\u5dee\u503c\u3002<\/li>\n\n\n\n<li><strong>\u4fe1\u53f7\u7ebf<\/strong>\uff1a\u8fd9\u662fMACD\u7ebf\u76849\u5929EMA\uff0c\u7528\u4e8e\u751f\u6210\u4e70\u5165\u548c\u5356\u51fa\u4fe1\u53f7\u3002<\/li>\n\n\n\n<li><strong>\u67f1\u72b6\u56fe<\/strong>\uff1a\u663e\u793aMACD\u7ebf\u4e0e\u4fe1\u53f7\u7ebf\u4e4b\u95f4\u7684\u5dee\u8ddd\uff0c\u5e2e\u52a9\u4ea4\u6613\u8005\u76f4\u89c2\u5730\u5224\u65ad\u8d8b\u52bf\u7684\u5f3a\u5ea6\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u7b80\u5355\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\nimport numpy as np\nimport yfinance as yf\nimport matplotlib.pyplot as plt\n\n\n# Fetch historical data for NVDA\nticker = 'NVDA'\nstart_date = '2023-01-01'\nend_date = '2023-12-31'\n\n# Download data using yfinance\ndf = yf.download(ticker, start=start_date, end=end_date)\n\ndef calculate_macd(df, short_period=12, long_period=26, signal_period=9):\n    # Calculate short and long-term EMAs\n    df&#91;'EMA_short'] = df&#91;'Close'].ewm(span=short_period, adjust=False).mean()\n    df&#91;'EMA_long'] = df&#91;'Close'].ewm(span=long_period, adjust=False).mean()\n    \n    # Calculate MACD and Signal Line\n    df&#91;'MACD'] = df&#91;'EMA_short'] - df&#91;'EMA_long']\n    df&#91;'Signal_Line'] = df&#91;'MACD'].ewm(span=signal_period, adjust=False).mean()\n    \n    # Calculate MACD Histogram\n    df&#91;'MACD_Histogram'] = df&#91;'MACD'] - df&#91;'Signal_Line']\n    \n    # Detect Bullish and Bearish Crossovers\n    df&#91;'Bullish_Crossover'] = (df&#91;'MACD'] &gt; df&#91;'Signal_Line']) &amp; \\\n                              (df&#91;'MACD'].shift(1) &lt;= df&#91;'Signal_Line'].shift(1))\n    df&#91;'Bearish_Crossover'] = (df&#91;'MACD'] &lt; df&#91;'Signal_Line']) &amp; \\\n                              (df&#91;'MACD'].shift(1) &gt;= df&#91;'Signal_Line'].shift(1))\n    \n    return df\n\n# Calculate MACD for NVDA\ndf = calculate_macd(df)\n\n# Print sample data\nprint(df.tail())\n\n\n# Plot Closing Price and MACD\nplt.figure(figsize=(12, 8))\n\n# Subplot 1: Closing Price\nplt.subplot(2, 1, 1)\nplt.plot(df&#91;'Close'], label='Close Price', color='blue')\nplt.title(f'{ticker} Stock Price and MACD Analysis')\nplt.legend()\n\n# Subplot 2: MACD and Signal Line\nplt.subplot(2, 1, 2)\nplt.plot(df&#91;'MACD'], label='MACD', color='green')\nplt.plot(df&#91;'Signal_Line'], label='Signal Line', color='red')\nplt.bar(df.index, df&#91;'MACD_Histogram'], label='Histogram', color='gray', alpha=0.5)\nplt.legend()\n\nplt.tight_layout()\nplt.show()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2025\/01\/image-41.png\" alt=\"\" class=\"wp-image-3777\" style=\"width:427px;height:auto\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u80a1\u4ef7\u56fe &#8211; \u663e\u793a NVDA \u5728\u6240\u9009\u65f6\u95f4\u8303\u56f4\u5185\u7684\u6536\u76d8\u4ef7\u3002<\/li>\n\n\n\n<li>MACD \u56fe &#8211; \u663e\u793a MACD \u7ebf\u3001\u4fe1\u53f7\u7ebf\u548c\u67f1\u72b6\u56fe\u3002<\/li>\n\n\n\n<li>\u770b\u6da8\u4fe1\u53f7\uff1aMACD \u5728\u4fe1\u53f7\u7ebf\u4e0a\u65b9\u4ea4\u53c9\u7684\u70b9\u3002<\/li>\n\n\n\n<li>\u770b\u8dcc\u4fe1\u53f7\uff1aMACD \u5728\u4fe1\u53f7\u7ebf\u4e0b\u65b9\u4ea4\u53c9\u7684\u70b9\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e09\u3001\u5982\u4f55\u5728\u4ea4\u6613\u4e2d\u4f7f\u7528 MACD\uff1f<\/strong><\/h2>\n\n\n\n<p id=\"181e\">\u6700\u5e38\u7528\u7684 MACD \u662f\u5bfb\u627e MACD \u7ebf\u548c\u4fe1\u53f7\u7ebf\u4e4b\u95f4\u7684\u4ea4\u53c9\uff1a<\/p>\n\n\n\n<p><strong>\u770b\u6da8\u4fe1\u53f7\uff08\u4e70\u5165\uff09<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f53 MACD \u7ebf\u5728\u4fe1\u53f7\u7ebf\u4e0a\u65b9\u4ea4\u53c9\u65f6\uff0c\u8868\u660e\u6709\u4e0a\u5347\u52bf\u5934\u3002<\/li>\n\n\n\n<li>\u4e3e\u4f8b\u8bf4\u660e\uff1a\u80a1\u4ef7\u4e00\u76f4\u5728\u4e0b\u8dcc\uff0c\u4f46 MACD \u7ebf\u7a81\u7136\u5411\u4e0a\u4ea4\u53c9\u3002\u8fd9\u9884\u793a\u7740\u4e00\u4e2a\u6f5c\u5728\u7684\u4e70\u5165\u673a\u4f1a\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u770b\u8dcc\u4fe1\u53f7\uff08\u5356\u51fa\uff09<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f53 MACD \u7ebf\u5728\u4fe1\u53f7\u7ebf\u4e0b\u65b9\u4ea4\u53c9\u65f6\uff0c\u8868\u660e\u6709\u4e0b\u964d\u52bf\u5934\u3002<\/li>\n\n\n\n<li>\u4e3e\u4f8b\u8bf4\u660e\uff1a\u80a1\u4ef7\u4e00\u76f4\u5728\u4e0a\u6da8\uff0c\u4f46 MACD \u7ebf\u5411\u4e0b\u4ea4\u53c9\u3002\u8fd9\u9884\u793a\u7740\u4e00\u4e2a\u5356\u51fa\u673a\u4f1a\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u76f4\u65b9\u56fe\u5206\u6790<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6b63\u67f1 = \u770b\u6da8\u52bf\u5934\u3002<\/li>\n\n\n\n<li>\u8d1f\u67f1 = \u770b\u8dcc\u52bf\u5934\u3002<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\" id=\"dd38\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.readmedium.com\/v2\/resize:fit:800\/0*hZhNZ4aWNvz-tvxa\" alt=\"\"\/><\/figure>\n\n\n\n<p><br><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n\n\n\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c\u60a8\u6b63\u5728\u5206\u6790\u82f9\u679c\u516c\u53f8\uff08AAPL\uff09\u7684\u80a1\u7968\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u56fe\u8868\u4e0a\uff0c\u60a8\u53ef\u4ee5\u770b\u5230 MACD \u7ebf\u5728 150 \u7f8e\u5143\u7684\u4fe1\u53f7\u7ebf\u4e0a\u65b9\u4ea4\u53c9\u3002<\/li>\n\n\n\n<li>\u60a8\u51b3\u5b9a\u8d2d\u4e70\u8fd9\u53ea\u80a1\u7968\u3002<\/li>\n\n\n\n<li>\u51e0\u5468\u540e\uff0cMACD \u7ebf\u5728 170 \u7f8e\u5143\u7684\u4fe1\u53f7\u7ebf\u4e0b\u65b9\u4ea4\u53c9\u3002<\/li>\n\n\n\n<li>\u4f60\u5356\u51fa\u5e76\u9501\u5b9a\u5229\u6da6\uff01<\/li>\n<\/ul>\n\n\n\n<p id=\"13e0\">\u8fd9\u79cd\u65b9\u6cd5\u5bf9\u4eba\u5de5\u4ea4\u6613\u975e\u5e38\u6709\u6548\u3002\u4f46\u673a\u5668\u5b66\u4e60\u5462\uff1f<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u56db\u3001\u5728\u673a\u5668\u5b66\u4e60\u6a21\u578b\u4e2d\u4f7f\u7528 MACD<\/strong><\/h2>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06MACD\u7eb3\u5165\u673a\u5668\u5b66\u4e60\u7684\u56e0\u5b50\u6a21\u578b\u4e2d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4.1 \u4ec0\u4e48\u662f\u56e0\u5b50\u6a21\u578b\uff1f<\/strong><\/h3>\n\n\n\n<p>\u56e0\u5b50\u6a21\u578b\u662f\u4e00\u79cd\u7528\u4e8e\u5206\u6790\u548c\u89e3\u91ca\u8d44\u4ea7\u6536\u76ca\u7387\u7684\u7edf\u8ba1\u6a21\u578b\uff0c\u5b83\u901a\u8fc7\u8bc6\u522b\u548c\u91cf\u5316\u5f71\u54cd\u8d44\u4ea7\u56de\u62a5\u7684\u6f5c\u5728\u56e0\u7d20\u6765\u5e2e\u52a9\u6295\u8d44\u8005\u7406\u89e3\u5e02\u573a\u52a8\u6001\u3002\u56e0\u5b50\u6a21\u578b\u4f5c\u4e3a\u4e00\u7ec4\u7279\u5f81\uff08\u6307\u6807\uff09\u65f6\uff0c\u88ab\u7528\u4f5c\u8bad\u7ec3\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u7684\u8f93\u5165\u6570\u636e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"7b85\"><strong>4.2 MACD \u5982\u4f55\u53c2\u4e0e\u5176\u4e2d\uff1f<\/strong><\/h3>\n\n\n\n<p id=\"4acf\">MACD \u503c\u53ef\u4f5c\u4e3a\u9884\u6d4b\u4e0d\u540c\u65f6\u95f4\u6bb5\u80a1\u7968\u56de\u62a5\u7684\u7279\u5f81\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>1 Day (1D)<\/strong><\/li>\n\n\n\n<li><strong>5 Days (5D)<\/strong><\/li>\n\n\n\n<li><strong>10 Days (10D)<\/strong><\/li>\n\n\n\n<li><strong>21 Days (21D)<\/strong><br><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"32a7\"><strong>4.3 \u673a\u5668\u5b66\u4e60\u5de5\u4f5c\u6d41\u7a0b<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6570\u636e\u51c6\u5907\uff1a\u6536\u96c6\u5386\u53f2\u80a1\u4ef7\u6570\u636e\uff0c\u7136\u540e\u8ba1\u7b97\u6bcf\u4e2a\u6570\u636e\u70b9\u7684 MACD\u3001\u4fe1\u53f7\u7ebf\u548c\u67f1\u72b6\u56fe\u3002<\/li>\n\n\n\n<li>\u529f\u80fd\u5de5\u7a0b\uff1a\u5c06 MACD \u503c\u4e0e\u5176\u4ed6\u6280\u672f\u6307\u6807\uff08\u5982 RSI \u6216\u5e03\u6797\u7ebf\uff09\u4e00\u8d77\u4f7f\u7528\u3002<\/li>\n\n\n\n<li>\u8bad\u7ec3\u673a\u5668\u5b66\u4e60\u6a21\u578b\uff1a\u968f\u673a\u68ee\u6797\u3001\u68af\u5ea6\u63d0\u5347\u6216\u795e\u7ecf\u7f51\u7edc\u7b49\u6a21\u578b\u90fd\u662f\u5229\u7528\u7279\u5f81\u8fdb\u884c\u8bad\u7ec3\u7684\u3002<\/li>\n\n\n\n<li>\u9884\u6d4b\uff1a\u6839\u636e\u5b66\u4e60\u5230\u7684\u6a21\u5f0f\u9884\u6d4b\u80a1\u7968\u7684\u672a\u6765\u56de\u62a5\u3002<\/li>\n\n\n\n<li>\u56de\u6eaf\u6d4b\u8bd5\uff1a\u5728\u5c06\u6a21\u578b\u90e8\u7f72\u5230\u5b9e\u9645\u4ea4\u6613\u4e2d\u4e4b\u524d\uff0c\u5148\u8bc4\u4f30\u6a21\u578b\u5728\u5386\u53f2\u6570\u636e\u4e2d\u7684\u8868\u73b0\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u7b80\u5355\u4fee\u590d\u7684\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def calculate_macd(df, short_period=12, long_period=26, signal_period=9):\n    # Calculate the short-term EMA (Exponential Moving Average)\n    df&#91;'EMA_short'] = df&#91;'Close'].ewm(span=short_period, adjust=False).mean()\n    \n    # Calculate the long-term EMA\n    df&#91;'EMA_long'] = df&#91;'Close'].ewm(span=long_period, adjust=False).mean()\n    \n    # Calculate the MACD line\n    df&#91;'MACD'] = df&#91;'EMA_short'] - df&#91;'EMA_long']\n    \n    # Calculate the Signal Line\n    df&#91;'Signal_Line'] = df&#91;'MACD'].ewm(span=signal_period, adjust=False).mean()\n    \n    # Calculate the MACD Histogram\n    df&#91;'MACD_Histogram'] = df&#91;'MACD'] - df&#91;'Signal_Line']\n    \n    # Identify Bullish Crossover\n    df&#91;'Bullish_Crossover'] = (df&#91;'MACD'] &gt; df&#91;'Signal_Line']) &amp; \\\n                              (df&#91;'MACD'].shift(1) &lt;= df&#91;'Signal_Line'].shift(1))\n    \n    # Identify Bearish Crossover\n    df&#91;'Bearish_Crossover'] = (df&#91;'MACD'] &lt; df&#91;'Signal_Line']) &amp; \\\n                              (df&#91;'MACD'].shift(1) &gt;= df&#91;'Signal_Line'].shift(1))\n    \n    return df\n\n\n# Example Usage\n# Assuming 'df' is a Pandas DataFrame containing stock price data with a 'Close' column.\n# Replace this with your actual data.\n\nimport pandas as pd\n\n# Sample Data\ndata = {'Close': &#91;100, 102, 104, 103, 107, 110, 108, 105, 107, 109]}\ndf = pd.DataFrame(data)\n\n# Calculate MACD\ndf_with_macd = calculate_macd(df)\n\n# Display results\nprint(df_with_macd)<\/code><\/pre>\n\n\n\n<p>\u4ee3\u7801\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53c2\u6570\u9ed8\u8ba4\u503c\uff1a\u4e3a short_period=12\u3001long_period=26 \u548c signal_period=9 \u6dfb\u52a0\u4e86\u9ed8\u8ba4\u503c\u3002<\/li>\n\n\n\n<li>\u8bed\u6cd5\u9519\u8bef\uff1a\u4fee\u590d\u4e86\u7f3a\u5931\u7684\u5706\u62ec\u53f7\u3001\u62ec\u53f7\u548c\u8fd0\u7b97\u7b26\uff08-\u3001&gt;\u3001&lt;\u3001&amp;\u3001|\uff09\u3002<\/li>\n\n\n\n<li>\u5217\u540d\uff1a \u66f4\u6b63\u4e86\u4e0d\u4e00\u81f4\u7684\u5217\u540d\uff0c\u5982 &#8220;EMA long&#8221;\u2192&#8221;EMA_long&#8221;\u3002<\/li>\n\n\n\n<li>\u5e03\u5c14\u6761\u4ef6\uff1a\u4fee\u6b63\u4e86\u770b\u6da8\u548c\u770b\u8dcc\u4ea4\u53c9\u6761\u4ef6\u7684\u903b\u8f91\u3002<\/li>\n\n\n\n<li>\u683c\u5f0f\u548c\u53ef\u8bfb\u6027\uff1a\u6539\u8fdb\u4e86\u95f4\u8ddd\u548c\u6ce8\u91ca\uff0c\u4f7f\u5176\u66f4\u52a0\u6e05\u6670\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e94\u3001\u4e3a\u4ec0\u4e48\u8981\u5c06 MACD \u4e0e\u673a\u5668\u5b66\u4e60\u76f8\u7ed3\u5408\uff1f<\/strong><\/h2>\n\n\n\n<p id=\"3a37\">\u867d\u7136 MACD \u5728\u4f20\u7edf\u4ea4\u6613\u4e2d\u8fd0\u4f5c\u826f\u597d\uff0c\u4f46\u5e02\u573a\u662f\u590d\u6742\u7684\uff0c\u53d7\u591a\u79cd\u56e0\u7d20\u5f71\u54cd\u3002\u673a\u5668\u5b66\u4e60\u53ef\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u589e\u5f3a MACD\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\uff1a\u9ad8\u6548\u5904\u7406\u5927\u91cf\u5386\u53f2\u6570\u636e\u548c\u5b9e\u65f6\u6570\u636e\u3002<\/li>\n\n\n\n<li>\u5bfb\u627e\u9690\u85cf\u6a21\u5f0f\uff1a\u68c0\u6d4b\u4eba\u5de5\u5206\u6790\u53ef\u80fd\u4e0d\u660e\u663e\u7684\u6a21\u5f0f\u3002<\/li>\n\n\n\n<li>\u9002\u5e94\u6027\u5b66\u4e60\uff1a\u6839\u636e\u83b7\u5f97\u7684\u65b0\u6570\u636e\u4e0d\u65ad\u6539\u8fdb\u3002<\/li>\n\n\n\n<li>\u591a\u56e0\u7d20\u5206\u6790\uff1a\u5c06 MACD \u4e0e\u6210\u4ea4\u91cf\u3001\u6ce2\u52a8\u7387\u548c\u57fa\u672c\u9762\u6570\u636e\u7b49\u5176\u4ed6\u529f\u80fd\u76f8\u7ed3\u5408\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u516d\u3001\u89c2\u70b9\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MACD\u662f\u4e00\u4e2a\u5386\u7ecf\u5e02\u573a\u8003\u9a8c\u7684\u591a\u529f\u80fd\u6307\u6807\uff0c\u901a\u8fc7\u4e0e\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u7ed3\u5408\uff0c\u4ea4\u6613\u8005\u53ef\u4ee5\u6784\u5efa\u66f4\u667a\u80fd\u7684\u6570\u636e\u9a71\u52a8\u7cfb\u7edf\uff0c\u7cbe\u51c6\u9884\u6d4b\u6536\u76ca\u5e76\u4f18\u5316\u4ea4\u6613\u51b3\u7b56\u3002<\/li>\n\n\n\n<li>\u901a\u8fc7\u5c06MACD\u4f5c\u4e3a\u56e0\u5b50\u6a21\u578b\u4e2d\u7684\u4e00\u4e2a\u7279\u5f81\uff0c\u53ef\u4ee5\u5728\u673a\u5668\u5b66\u4e60\u6a21\u578b\u4e2d\u6355\u6349\u5230\u66f4\u590d\u6742\u7684\u5e02\u573a\u52a8\u6001\u548c\u4ea4\u6613\u4fe1\u53f7\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u4ea4\u6613\u8005\u9884\u6d4b\u80a1\u7968\u56de\u62a5\uff0c\u5236\u5b9a\u66f4\u667a\u80fd\u7684\u4ea4\u6613\u7b56\u7565\uff0c\u5e76\u901a\u8fc7\u5386\u53f2\u6570\u636e\u7684\u56de\u6eaf\u6d4b\u8bd5\u6765\u8bc4\u4f30\u7b56\u7565\u7684\u6709\u6548\u6027\u3002<\/li>\n\n\n\n<li>\u65e0\u8bba\u4f60\u662f\u65b0\u624b\u8fd8\u662f\u8d44\u6df1\u4ea4\u6613\u5458\uff0c\u5c06MACD\u878d\u5165\u7b56\u7565\uff08\u5c24\u5176\u662f\u7ed3\u5408\u673a\u5668\u5b66\u4e60\uff09\uff0c\u90fd\u80fd\u4e3a\u4f60\u63d0\u4f9b\u5f3a\u5927\u7684\u5e02\u573a\u6d1e\u5bdf\u529b\uff0c\u663e\u8457\u63d0\u5347\u76c8\u5229\u80fd\u529b\u3002<\/li>\n<\/ul>\n\n\n\n<p id=\"3011\"><strong>\u6838\u5fc3\u542f\u793a\uff1a<\/strong>&nbsp;\u4e0d\u8981\u4f9d\u8d56\u76f4\u89c9\u4ea4\u6613\uff01\u5c06MACD\u4e0e\u673a\u5668\u5b66\u4e60\u7ed3\u5408\uff0c\u9884\u6d4b\u8d8b\u52bf\uff0c\u62a2\u5360\u5e02\u573a\u5148\u673a\uff01<\/p>\n\n\n\n<p id=\"3011\"><\/p>\n\n\n\n<p><em>\u611f\u8c22\u60a8\u9605\u8bfb\u5230\u6700\u540e\uff0c\u5e0c\u671b\u672c\u6587\u80fd\u7ed9\u60a8\u5e26\u6765\u65b0\u7684\u6536\u83b7\u3002\u7801\u5b57\u4e0d\u6613\uff0c\u8bf7\u5e2e\u6211\u70b9\u8d5e\u3001\u5206\u4eab\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<\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center\" id=\"a1c6\">\u672c\u6587\u5185\u5bb9\u4ec5\u9650\u6280\u672f\u63a2\u8ba8\u548c\u5b66\u4e60\uff0c\u4e0d\u6784\u6210\u4efb\u4f55\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:\/\/www.laoyulaoyu.com\/index.php\/2025\/02\/01\/%e6%8f%ad%e7%a7%98macd%e5%9c%a8%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e7%ae%97%e6%b3%95%e4%ba%a4%e6%98%93%e4%b8%ad%e7%9a%84%e5%ba%94%e7%94%a8\/\">Continue reading<span class=\"screen-reader-text\">\u63ed\u79d8MACD\u5728\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u4ea4\u6613\u4e2d\u7684\u5e94\u7528<\/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":[5,6],"class_list":["post-1871","post","type-post","status-publish","format-standard","hentry","category-aiinvest","tag-ai","tag-6","entry"],"_links":{"self":[{"href":"https:\/\/www.laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/comments?post=1871"}],"version-history":[{"count":1,"href":"https:\/\/www.laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1871\/revisions"}],"predecessor-version":[{"id":1872,"href":"https:\/\/www.laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1871\/revisions\/1872"}],"wp:attachment":[{"href":"https:\/\/www.laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/media?parent=1871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/categories?post=1871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/tags?post=1871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}