{"id":7183,"date":"2023-09-05T20:41:10","date_gmt":"2023-09-05T20:41:10","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=7183"},"modified":"2026-11-10T06:44:00","modified_gmt":"2026-11-10T06:44:00","slug":"sp-500-sma200-trading-strategy","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy","title":{"rendered":"S&amp;P 500 200-Day Moving Average Strategy: A 33-Year Backtest in Python"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The S&amp;P 500 200-day moving average strategy holds the index while its price is above the average of the last 200 daily closes, and moves to cash when the price falls below it. Tested on SPY from November 1993 to November 2026 with EODHD data, it cut the maximum drawdown from 55.19% to 30.24%, but grew $1 to $12.02 instead of $28.44 for buy and hold. It gave up return in exchange for smaller losses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide shows the backtest step by step in Python, then tests the stricter version from the 2023 edition of this article, which combines weekly, daily and hourly 200-period averages. On HSBC&#8217;s S&amp;P 500 ETF from November 2020 to November 2026, those rules won 2 of 7 closed trades and returned 16.9%, against a 107.3% price change for holding the ETF.<\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" target=\"_blank\" rel=\"noopener\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n\n\n\n<h2 id=\"h-what-the-s-amp-p-500-200-day-moving-average-shows\" class=\"wp-block-heading\">What the S&amp;P 500 200-day moving average shows<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A simple moving average (SMA) is the average closing price over a fixed number of periods. The 200-day SMA covers roughly the last ten months of trading, so it changes slowly and shows the long-term trend. When the S&amp;P 500 trades above its 200-day moving average, the trend is usually described as up. When it trades below, the trend is described as down.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The trading rule built on it is simple:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Stay invested while the close is above the 200-day SMA.<\/li>\n\n\n\n<li>Move to cash when the close falls below it.<\/li>\n\n\n\n<li>Buy again when the close rises back above it.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The idea is to stay in during long rises and step aside during long declines. The cost is that every crossing triggers a trade, including the ones that reverse a few days later.<\/p>\n\n\n\n<h2 id=\"h-the-test-setup\" class=\"wp-block-heading\">The test setup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Everything below is reproducible with the code in this guide:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Data: daily adjusted closes of <a href=\"https:\/\/www.ssga.com\/us\/en\/intermediary\/etfs\/spdr-sp-500-etf-trust-spy\">SPY<\/a> (SPY.US) from the EODHD end-of-day API, January 29, 1993 to November 6, 2026. The first 200 days are used to build the first average, so the backtest starts on November 11, 1993.<\/li>\n\n\n\n<li>Signal: computed on each day&#8217;s close and applied to the next day&#8217;s return, so no trade uses a price it couldn&#8217;t have known.<\/li>\n\n\n\n<li>Costs: 0.1% on every switch in or out of the market. Cash earns nothing, which understates the strategy slightly in years with high interest rates.<\/li>\n\n\n\n<li>Comparison: buy and hold of the same SPY series, with dividends reinvested through the adjusted close.<\/li>\n<\/ul>\n\n\n\n<h2 id=\"h-how-to-get-your-eodhd-api-key\" class=\"wp-block-heading\">How to get your EODHD API key<\/h2>\n\n\n\n<p class=\"bordered_paragraph wp-block-paragraph\">1. Use the \u201cdemo\u201d API key to test our data from a limited set of tickers without registering:<br>AAPL.US | TSLA.US | VTI.US | AMZN.US | BTC-USD | EUR-USD<br>Real-Time Data and all of the APIs (except Bulk) are included without API calls limitations with these tickers and the demo key.<br>2. Register to get your free API key (limited to 20 API calls per day) with access to:<br>End-Of-Day Historical Data with only the past year for any ticker, and the List of tickers per Exchange.<br>3. To unlock your API key, we recommend to choose the <a href=\"https:\/\/eodhd.com\/pricing\" target=\"_blank\" rel=\"noreferrer noopener\">subscription plan<\/a> which covers your needs.<\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" target=\"_blank\" rel=\"noopener\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SPY isn&#8217;t one of the demo tickers, and the backtest uses 33 years of history, so it needs the EOD Historical All-World plan or higher. The hourly test later in the guide uses intraday data, which is part of the EOD + Intraday All-World Extended plan and the All-In-One plan.<\/p>\n\n\n\n<h2 id=\"h-backtesting-the-s-amp-p-500-200-day-moving-average-in-python\" class=\"wp-block-heading\">Backtesting the S&amp;P 500 200-day moving average in Python<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The script downloads the adjusted closes, builds the 200-day SMA, and compares the filter with buy and hold over the whole period, during five major sell-offs and during the 2020 rebound:<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code class=\"\">import os<br>import sys<br><br>import numpy as np<br>import pandas as pd<br>import requests<br><br>API_KEY = os.environ.get(\"EODHD_API_KEY\", \"demo\")<br>FEE = 0.001  # 0.1% per switch, in or out<br><br><br>def get_eod(ticker, start, end):<br>    url = f\"https:\/\/eodhd.com\/api\/eod\/{ticker}\"<br>    params = {\"api_token\": API_KEY, \"fmt\": \"json\", \"from\": start, \"to\": end}<br>    data = requests.get(url, params=params, timeout=60).json()<br>    df = pd.DataFrame(data).set_index(\"date\")<br>    df.index = pd.to_datetime(df.index)<br>    return df[\"adjusted_close\"].astype(float)<br><br><br>def stats(daily_ret, years):<br>    equity = (1 + daily_ret).cumprod()<br>    cagr = equity.iloc[-1] ** (1 \/ years) - 1<br>    drawdown = (equity \/ equity.cummax() - 1).min()<br>    vol = daily_ret.std() * np.sqrt(252)<br>    return equity.iloc[-1], cagr, drawdown, vol<br><br><br>ticker, start, end = sys.argv[1:4]<br>close = get_eod(ticker, start, end)<br>sma = close.rolling(200).mean()<br><br>df = pd.DataFrame({\"close\": close, \"sma200\": sma}).dropna()<br>df[\"ret\"] = df[\"close\"].pct_change().fillna(0)<br>df[\"in_market\"] = (df[\"close\"] &gt; df[\"sma200\"]).astype(int).shift(1).fillna(0)<br>switches = df[\"in_market\"].diff().abs().fillna(0)<br>df[\"strategy\"] = df[\"in_market\"] * df[\"ret\"] - switches * FEE<br><br>years = (df.index[-1] - df.index[0]).days \/ 365.25<br>print(f\"{ticker}: {df.index[0].date()} to {df.index[-1].date()}, {len(df)} days, {years:.1f} years\")<br>print(f\"Switches in or out: {int(switches.sum())}, time invested: {df['in_market'].mean():.1%}\\n\")<br><br>rows = []<br>for name, col in [(\"Buy and hold\", \"ret\"), (\"SMA200 filter\", \"strategy\")]:<br>    final, cagr, dd, vol = stats(df[col], years)<br>    rows.append({\"Strategy\": name, \"Growth of $1\": round(final, 2), \"CAGR\": f\"{cagr:.2%}\",<br>                 \"Max drawdown\": f\"{dd:.2%}\", \"Volatility\": f\"{vol:.2%}\"})<br>print(pd.DataFrame(rows).to_string(index=False), \"\\n\")<br><br># The same comparison inside each major sell-off and recovery<br>periods = {<br>    \"2000-2002 dot-com bust\": (\"2000-03-24\", \"2002-10-09\"),<br>    \"2007-2009 financial crisis\": (\"2007-10-09\", \"2009-03-09\"),<br>    \"2020 Covid crash\": (\"2020-02-19\", \"2020-03-23\"),<br>    \"2020 Covid rebound\": (\"2020-03-23\", \"2020-08-31\"),<br>    \"2022 bear market\": (\"2022-01-03\", \"2022-10-12\"),<br>    \"2025 tariff sell-off\": (\"2025-02-19\", \"2025-04-08\"),<br>}<br>rows = []<br>for name, (a, b) in periods.items():<br>    p = df.loc[a:b]<br>    rows.append({\"Period\": name,<br>                 \"Buy and hold\": f\"{(1 + p['ret'].iloc[1:]).prod() - 1:.1%}\",<br>                 \"SMA200 filter\": f\"{(1 + p['strategy'].iloc[1:]).prod() - 1:.1%}\"})<br>print(pd.DataFrame(rows).to_string(index=False))<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p class=\"wp-block-paragraph\">Run with python sma200_filter.py SPY.US 1993-01-29 2026-11-06:<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code class=\"\">SPY.US: 1993-11-11 to 2026-11-06, 8303 days, 33.0 years<br>Switches in or out: 213, time invested: 77.4%<br><br>     Strategy  Growth of $1   CAGR Max drawdown Volatility<br> Buy and hold         28.44 10.68%      -55.19%     18.69%<br>SMA200 filter         12.02  7.83%      -30.24%     12.15%<br><br>                    Period Buy and hold SMA200 filter<br>    2000-2002 dot-com bust       -47.5%        -24.3%<br>2007-2009 financial crisis       -55.2%        -15.1%<br>          2020 Covid crash       -33.7%        -17.8%<br>        2020 Covid rebound        57.4%         17.2%<br>          2022 bear market       -24.5%        -14.1%<br>      2025 tariff sell-off       -18.8%         -9.7%<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<h2 id=\"h-s-amp-p-500-200-day-moving-average-results\" class=\"wp-block-heading\">S&amp;P 500 200-day moving average results<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><\/th><th>Buy and hold<\/th><th>200-day SMA filter<\/th><\/tr><\/thead><tbody><tr><td>Growth of $1, Nov 1993 to Nov 2026<\/td><td>$28.44<\/td><td>$12.02<\/td><\/tr><tr><td>Annual return (CAGR)<\/td><td>10.68%<\/td><td>7.83%<\/td><\/tr><tr><td>Maximum drawdown<\/td><td>-55.19%<\/td><td>-30.24%<\/td><\/tr><tr><td>Annual volatility<\/td><td>18.69%<\/td><td>12.15%<\/td><\/tr><tr><td>Time invested<\/td><td>100%<\/td><td>77.4%<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1650\" height=\"1125\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/spy-sma200-filter-vs-buy-and-hold.png\" alt=\"SPY growth of $1 and drawdowns for the S&amp;P 500 200-day moving average filter and buy and hold\" class=\"wp-image-7179\" srcset=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/spy-sma200-filter-vs-buy-and-hold.png 1650w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/spy-sma200-filter-vs-buy-and-hold-300x205.png 300w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/spy-sma200-filter-vs-buy-and-hold-1024x698.png 1024w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/spy-sma200-filter-vs-buy-and-hold-768x524.png 768w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/spy-sma200-filter-vs-buy-and-hold-1536x1047.png 1536w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/spy-sma200-filter-vs-buy-and-hold-60x41.png 60w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/spy-sma200-filter-vs-buy-and-hold-150x102.png 150w\" sizes=\"auto, (max-width: 1650px) 100vw, 1650px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The filter did what it was designed to do in long declines. In the 2007-2009 financial crisis it lost 15.1% while the S&amp;P 500 lost 55.2%, and in the 2000-2002 bust it lost 24.3% against 47.5%. Its volatility was about a third lower over the whole period.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It also missed a large part of the rebounds. After the Covid low on March 23, 2020, SPY rose 57.4% by the end of August, while the filter gained 17.2%, because the price had to climb back above its 200-day average before the strategy bought again. Over 33 years, the filter ended with less than half of the buy and hold result. Late re-entries like this one, the switching fees and cash that earned nothing all contributed to the gap.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The 213 switches also matter. Of the 107 periods in the market, 77 lasted 20 trading days or less, and so did 89 of the 106 periods in cash. Those short spells came from the price crossing the average back and forth, and each crossing paid the 0.1% fee.<\/p>\n\n\n\n<h2 id=\"h-the-weekly-daily-and-hourly-sma200-rules\" class=\"wp-block-heading\">The weekly, daily and hourly SMA200 rules<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The 2023 edition of this article described a stricter set of rules on HSPX.LSE, HSBC&#8217;s S&amp;P 500 ETF listed in London:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Trade only while the daily SMA200 is above the weekly SMA200.<\/li>\n\n\n\n<li>Buy when the hourly SMA200 crosses above the daily SMA200.<\/li>\n\n\n\n<li>Sell when the hourly SMA200 crosses below the daily SMA200.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Hourly data from EODHD APIs for HSPX.LSE starts in late 2020, which gives six years to test the rules. The script below uses the last completed daily and weekly averages for each hourly bar, so no hour uses data from later in the same day. All three averages use raw closes, because the hourly data has no adjusted close. The results are therefore price returns, without dividends.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code class=\"\">import os<br>import sys<br>from datetime import datetime, timezone<br><br>import pandas as pd<br>import requests<br><br>API_KEY = os.environ.get(\"EODHD_API_KEY\", \"demo\")<br>BASE = \"https:\/\/eodhd.com\/api\"<br><br><br>def get(path, **params):<br>    resp = requests.get(f\"{BASE}\/{path}\", params={\"api_token\": API_KEY, \"fmt\": \"json\", **params}, timeout=60)<br>    resp.raise_for_status()<br>    return resp.json()<br><br><br>def eod(ticker, period, start, end):<br>    df = pd.DataFrame(get(f\"eod\/{ticker}\", period=period, **{\"from\": start, \"to\": end}))<br>    return df.set_index(pd.to_datetime(df[\"date\"]))[\"close\"].astype(float)<br><br><br>def hourly(ticker, start, end):<br>    # Intraday timestamps are in UTC<br>    ts = lambda d: int(datetime.fromisoformat(d).replace(tzinfo=timezone.utc).timestamp())<br>    df = pd.DataFrame(get(f\"intraday\/{ticker}\", interval=\"1h\", **{\"from\": ts(start), \"to\": ts(end)}))<br>    df = df[df[\"close\"] &gt; 0]<br>    return df.set_index(pd.to_datetime(df[\"datetime\"]))[\"close\"].astype(float)<br><br><br>ticker, start, end = sys.argv[1:4]<br>weekly_sma = eod(ticker, \"w\", \"2010-01-01\", end).rolling(200).mean()<br>daily_sma = eod(ticker, \"d\", \"2019-01-01\", end).rolling(200).mean()<br>h = hourly(ticker, start, end)<br><br>df = pd.DataFrame({\"close\": h, \"hourly_sma\": h.rolling(200).mean()})<br>day = df.index.normalize()<br># Last completed day and week before each hourly bar<br>df[\"daily_sma\"] = daily_sma.shift(1).reindex(day, method=\"ffill\").values<br>df[\"weekly_sma\"] = weekly_sma.shift(1).reindex(day, method=\"ffill\").values<br>df = df.dropna()<br><br>regime = df[\"daily_sma\"] &gt; df[\"weekly_sma\"]<br>above = df[\"hourly_sma\"] &gt; df[\"daily_sma\"]<br>cross_up = above &amp; ~above.shift(1, fill_value=True)<br>cross_down = ~above &amp; above.shift(1, fill_value=False)<br><br>trades, entry = [], None<br>for t, row in df.iterrows():<br>    if entry is None and cross_up[t] and regime[t]:<br>        entry = (t, row[\"close\"])<br>    elif entry is not None and cross_down[t]:<br>        trades.append({\"entry\": entry[0], \"exit\": t, \"entry_price\": entry[1], \"exit_price\": row[\"close\"]})<br>        entry = None<br>if entry is not None:<br>    last = df.index[-1]<br>    trades.append({\"entry\": entry[0], \"exit\": last, \"entry_price\": entry[1],<br>                   \"exit_price\": df[\"close\"].iloc[-1], \"open\": True})<br><br>tr = pd.DataFrame(trades)<br>tr[\"return\"] = tr[\"exit_price\"] \/ tr[\"entry_price\"] - 1<br>tr[\"days\"] = (tr[\"exit\"] - tr[\"entry\"]).dt.days<br>closed = tr[tr.get(\"open\", pd.Series(False, index=tr.index)).fillna(False) == False]<br><br>print(f\"{ticker} hourly bars: {df.index[0]} to {df.index[-1]}, {len(df)} bars\")<br>print(f\"Hours with daily SMA200 above weekly SMA200: {regime.mean():.1%}\")<br>print(f\"Trades: {len(tr)} ({len(closed)} closed)\")<br>print(f\"Winning closed trades: {(closed['return'] &gt; 0).sum()} of {len(closed)} ({(closed['return'] &gt; 0).mean():.0%})\")<br>print(f\"Average closed trade: {closed['return'].mean():.2%}, median holding: {closed['days'].median():.0f} days\")<br>print(f\"Strategy, compounded: {(1 + tr['return']).prod() - 1:.1%}\")<br>print(f\"Buy and hold, same hours: {df['close'].iloc[-1] \/ df['close'].iloc[0] - 1:.1%}\\n\")<br>print(tr[[\"entry\", \"exit\", \"entry_price\", \"exit_price\", \"return\", \"days\"]].to_string(index=False,<br>      formatters={\"return\": \"{:.2%}\".format, \"entry_price\": \"{:.2f}\".format, \"exit_price\": \"{:.2f}\".format}))<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p class=\"wp-block-paragraph\">Run with python three_timeframe.py HSPX.LSE 2020-06-01 2026-11-07:<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code class=\"\">HSPX.LSE hourly bars: 2020-11-11 08:00:00 to 2026-11-06 16:30:00, 13887 bars<br>Hours with daily SMA200 above weekly SMA200: 100.0%<br>Trades: 8 (7 closed)<br>Winning closed trades: 2 of 7 (29%)<br>Average closed trade: 1.91%, median holding: 49 days<br>Strategy, compounded: 16.9%<br>Buy and hold, same hours: 107.3%<br><br>              entry                exit entry_price exit_price return  days<br>2022-03-01 14:00:00 2022-03-02 08:00:00     3279.13    3257.50 -0.66%     0<br>2022-03-29 10:00:00 2022-05-18 07:00:00     3533.80    3309.93 -6.34%    49<br>2022-08-15 11:00:00 2022-10-18 12:00:00     3544.20    3346.20 -5.59%    64<br>2022-11-14 14:00:00 2022-12-13 16:00:00     3421.40    3299.80 -3.55%    29<br>2023-02-13 11:00:00 2023-03-21 08:00:00     3418.60    3259.62 -4.65%    35<br>2023-05-30 15:00:00 2025-03-21 14:00:00     3429.00    4388.83 27.99%   660<br>2025-07-15 13:00:00 2026-04-07 09:00:00     4746.20    5038.21  6.15%   265<br>2026-04-17 11:00:00 2026-11-06 16:30:00     5274.40    5619.20  6.54%   203<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1650\" height=\"825\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/hspx-three-timeframe-sma200-trades.png\" alt=\"HSPX.LSE hourly close with the hourly, daily and weekly SMA200 and the periods in a trade\" class=\"wp-image-7180\" srcset=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/hspx-three-timeframe-sma200-trades.png 1650w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/hspx-three-timeframe-sma200-trades-300x150.png 300w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/hspx-three-timeframe-sma200-trades-1024x512.png 1024w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/hspx-three-timeframe-sma200-trades-768x384.png 768w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/hspx-three-timeframe-sma200-trades-1536x768.png 1536w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/hspx-three-timeframe-sma200-trades-60x30.png 60w, https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2026\/11\/hspx-three-timeframe-sma200-trades-150x75.png 150w\" sizes=\"auto, (max-width: 1650px) 100vw, 1650px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The results show three things:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The weekly filter never applied. The daily SMA200 stayed above the weekly SMA200 in every hour of the test, so the first rule didn&#8217;t change a single trade.<\/li>\n\n\n\n<li>The rules missed the 2021 rise. The hourly average was already above the daily average when the test started, and the strategy waits for a crossing before buying, so the first trade came in March 2022.<\/li>\n\n\n\n<li>2022 and early 2023 produced five losing trades in a row, as the hourly average crossed the daily average back and forth. One long trade from May 2023 to March 2025, with a 27.99% gain, made up for them.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The 2023 article described these rules as tested over many years, with a 99% success rate in one trader&#8217;s last 100 trades. Over this six-year window, with EODHD data and the rules as written, 2 of 7 closed trades were profitable, and the ETF&#8217;s price change over the same hours was more than six times as large.<\/p>\n\n\n\n<h2 id=\"h-getting-the-data-with-the-eodhd-python-library\" class=\"wp-block-heading\">Getting the data with the eodhd Python library<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The scripts above call the API with requests. The official eodhd library (version 1.0.32 at the time of writing) also returns daily, weekly and hourly bars, through the interval argument:<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code class=\"\">import os<br><br>from eodhd import APIClient<br><br>api = APIClient(os.environ[\"EODHD_API_KEY\"])<br>df_daily = api.get_historical_data(symbol=\"HSPX.LSE\", interval=\"d\",<br>                                   iso8601_start=\"2019-01-01\", iso8601_end=\"2026-11-06\")<br>df_weekly = api.get_historical_data(symbol=\"HSPX.LSE\", interval=\"w\",<br>                                    iso8601_start=\"2010-01-01\", iso8601_end=\"2026-11-06\")<br>df_hourly = api.get_historical_data(symbol=\"HSPX.LSE\", interval=\"1h\",<br>                                    iso8601_start=\"2021-01-01\", iso8601_end=\"2026-11-06\")<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p class=\"wp-block-paragraph\">The price columns come back with the object data type, so convert them with astype(float) before calculating averages.<\/p>\n\n\n\n<h2 id=\"h-where-the-s-amp-p-500-200-day-moving-average-strategy-breaks\" class=\"wp-block-heading\">Where the S&amp;P 500 200-day moving average strategy breaks<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The results above depend on several choices. Check each one before using any version of the strategy:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Rebounds after crashes. The filter re-enters only after the price is back above a slow average, so it buys late after V-shaped recoveries. From March to August 2020, SPY rose 57.4% and the filter 17.2%.<\/li>\n\n\n\n<li>Sideways markets. When the price stays close to the average, every small move triggers a trade. That happened in 2022 and early 2023 for the hourly rules, and 77 of the daily filter&#8217;s 107 periods in the market lasted 20 trading days or less.<\/li>\n\n\n\n<li>Cash return. This test assumes cash earns nothing. A money market fund or Treasury bills would have added return during the 22.6% of the time the filter was out of the market.<\/li>\n\n\n\n<li>Costs and taxes. The test charges 0.1% per switch. In a taxable account, selling 100 times or more in 33 years also realizes gains that buy and hold would have deferred.<\/li>\n\n\n\n<li>One market and one period. The S&amp;P 500 rose strongly over most of this sample. A market or period with longer, deeper declines could give a different result, so test the filter on the indices you actually hold.<\/li>\n<\/ul>\n\n\n\n<h2 id=\"h-conclusion\" class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The S&amp;P 500 200-day moving average works as a risk filter, not as a way to beat the index. Over 33 years of SPY data, it reduced the maximum drawdown from 55.19% to 30.24% and the volatility by about a third, at the cost of roughly three percentage points of annual return. The stricter weekly, daily and hourly rules from the 2023 edition returned 16.9% over six years against a 107.3% price change for holding the ETF.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Whether the trade-off is worth it depends on how much a deep drawdown matters to you. The scripts in this guide let you test it on any ticker, period and fee level with EODHD data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For the endpoints used here, see the <a href=\"https:\/\/eodhd.com\/financial-apis\/api-for-historical-data-and-volumes\" target=\"_blank\" rel=\"noreferrer noopener\">End-of-Day Historical Data API documentation<\/a> and the <a href=\"https:\/\/eodhd.com\/financial-apis\/intraday-historical-data-api\" target=\"_blank\" rel=\"noreferrer noopener\">Intraday Historical Data API documentation<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This article is for educational purposes and is not financial advice.<\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" target=\"_blank\" rel=\"noopener\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<h2 id=\"h-faqs\" class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Q: What is the 200-day moving average of the S&amp;P 500?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is the average of the S&amp;P 500&#8217;s last 200 daily closing prices, about ten months of trading. Investors use it as a long-term trend line: the trend is usually described as up while the index trades above it and down while it trades below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Q: Does the 200-day moving average strategy beat buy and hold?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not in this test. From November 1993 to November 2026, the filter on SPY returned 7.83% a year against 10.68% for buy and hold. It did reduce the maximum drawdown from 55.19% to 30.24%.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Q: What happens when the S&amp;P 500 crosses below its 200-day moving average?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The filter sells and moves to cash. In this test, that protected the strategy during long declines such as 2008, but many crossings reversed within weeks: 77 of the 107 periods in the market lasted 20 trading days or less, and each switch paid the 0.1% fee.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Q: How many trades does a 200-day moving average strategy make?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On SPY from 1993 to 2026, the filter switched in or out of the market 213 times, and was invested 77.4% of the time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Q: Can I use the 200-day moving average on hourly data?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, the average can be calculated on any interval. The hourly version from the 2023 edition of this article, tested from November 2020 to November 2026, won 2 of 7 closed trades and returned 16.9%, against a 107.3% price change for holding the ETF.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The S&amp;P 500 200-day moving average strategy holds the index while its price is above the average of the last 200 daily closes, and moves to cash when the price falls below it. Tested on SPY from November 1993 to November 2026 with EODHD data, it cut the maximum drawdown from 55.19% to 30.24%, but [&hellip;]<\/p>\n","protected":false},"author":36,"featured_media":1918,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[42,59],"tags":[],"coding-language":[],"ready-to-go-solution":[],"qualification":[],"financial-apis-category":[],"financial-apis-manuals":[],"class_list":["post-7183","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stocks-data-analysis-examples","category-technical-analysis-examples","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.9 (Yoast SEO v26.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>S&amp;P 500 200 Day Moving Average Strategy: 33-Year Backtest<\/title>\n<meta name=\"description\" content=\"Does the S&amp;P 500 200-day moving average beat buy and hold? A 33-year Python backtest on SPY, plus the original hourly SMA200 rules.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"S&amp;P 500 200-Day Moving Average Strategy: A 33-Year Backtest in Python\" \/>\n<meta property=\"og:description\" content=\"Does the S&amp;P 500 200-day moving average beat buy and hold? A 33-year Python backtest on SPY, plus the original hourly SMA200 rules.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\" \/>\n<meta property=\"og:site_name\" content=\"Financial Academy\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/eodhistoricaldata\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-05T20:41:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-10T06:44:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"980\" \/>\n\t<meta property=\"og:image:height\" content=\"490\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Kevin Meneses Gonz\u00e1lez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:site\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kevin Meneses Gonz\u00e1lez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\"},\"author\":{\"name\":\"Kevin Meneses Gonz\u00e1lez\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/f085666760ee7f148d1923a296cf3fe3\"},\"headline\":\"S&amp;P 500 200-Day Moving Average Strategy: A 33-Year Backtest in Python\",\"datePublished\":\"2023-09-05T20:41:10+00:00\",\"dateModified\":\"2026-11-10T06:44:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\"},\"wordCount\":1721,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg\",\"articleSection\":[\"Stocks Data Analysis Examples\",\"Technical Analysis Examples\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\",\"name\":\"S&P 500 200 Day Moving Average Strategy: 33-Year Backtest\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg\",\"datePublished\":\"2023-09-05T20:41:10+00:00\",\"dateModified\":\"2026-11-10T06:44:00+00:00\",\"description\":\"Does the S&P 500 200-day moving average beat buy and hold? A 33-year Python backtest on SPY, plus the original hourly SMA200 rules.\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg\",\"width\":7000,\"height\":3500,\"caption\":\"S&amp;P 500 US Stock market exchange index. Financial trading investment concept.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"S&amp;P 500 200-Day Moving Average Strategy: A 33-Year Backtest in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"name\":\"Financial APIs Academy | EODHD\",\"description\":\"Financial Stock Market Academy\",\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\",\"name\":\"EODHD (EOD Historical Data)\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"width\":159,\"height\":82,\"caption\":\"EODHD (EOD Historical Data)\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/eodhistoricaldata\",\"https:\/\/x.com\/EOD_data\",\"https:\/\/www.reddit.com\/r\/EODHistoricalData\/\",\"https:\/\/eod-historical-data.medium.com\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/f085666760ee7f148d1923a296cf3fe3\",\"name\":\"Kevin Meneses Gonz\u00e1lez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/19dee2010941996b1cce342ad66f6964baa6eac898570992e3cddc1b00143a79?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/19dee2010941996b1cce342ad66f6964baa6eac898570992e3cddc1b00143a79?s=96&d=mm&r=g\",\"caption\":\"Kevin Meneses Gonz\u00e1lez\"},\"description\":\"Kevin Meneses Gonz\u00e1lez is a CRM consultant and technical content creator focused on Python, AI, and financial data. He writes practical tutorials on using APIs and automation to analyze markets and build investment research tools.\",\"sameAs\":[\"https:\/\/kevinmeneses.com\/en\",\"https:\/\/www.linkedin.com\/in\/kevin-meneses-gonzalez\/\",\"https:\/\/www.youtube.com\/@pythonia6131\"],\"url\":\"https:\/\/eodhd.com\/financial-academy\/author\/kevinmeneses\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"S&P 500 200 Day Moving Average Strategy: 33-Year Backtest","description":"Does the S&P 500 200-day moving average beat buy and hold? A 33-year Python backtest on SPY, plus the original hourly SMA200 rules.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy","og_locale":"en_US","og_type":"article","og_title":"S&amp;P 500 200-Day Moving Average Strategy: A 33-Year Backtest in Python","og_description":"Does the S&P 500 200-day moving average beat buy and hold? A 33-year Python backtest on SPY, plus the original hourly SMA200 rules.","og_url":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2023-09-05T20:41:10+00:00","article_modified_time":"2026-11-10T06:44:00+00:00","og_image":[{"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","width":980,"height":490,"type":"image\/jpeg"}],"author":"Kevin Meneses Gonz\u00e1lez","twitter_card":"summary_large_image","twitter_creator":"@EOD_data","twitter_site":"@EOD_data","twitter_misc":{"Written by":"Kevin Meneses Gonz\u00e1lez","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy"},"author":{"name":"Kevin Meneses Gonz\u00e1lez","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/f085666760ee7f148d1923a296cf3fe3"},"headline":"S&amp;P 500 200-Day Moving Average Strategy: A 33-Year Backtest in Python","datePublished":"2023-09-05T20:41:10+00:00","dateModified":"2026-11-10T06:44:00+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy"},"wordCount":1721,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","articleSection":["Stocks Data Analysis Examples","Technical Analysis Examples"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy","url":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy","name":"S&P 500 200 Day Moving Average Strategy: 33-Year Backtest","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","datePublished":"2023-09-05T20:41:10+00:00","dateModified":"2026-11-10T06:44:00+00:00","description":"Does the S&P 500 200-day moving average beat buy and hold? A 33-year Python backtest on SPY, plus the original hourly SMA200 rules.","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#primaryimage","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","width":7000,"height":3500,"caption":"S&amp;P 500 US Stock market exchange index. Financial trading investment concept."},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/technical-analysis-examples\/sp-500-sma200-trading-strategy#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"S&amp;P 500 200-Day Moving Average Strategy: A 33-Year Backtest in Python"}]},{"@type":"WebSite","@id":"https:\/\/eodhd.com\/financial-academy\/#website","url":"https:\/\/eodhd.com\/financial-academy\/","name":"Financial APIs Academy | EODHD","description":"Financial Stock Market Academy","publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/eodhd.com\/financial-academy\/#organization","name":"EODHD (EOD Historical Data)","url":"https:\/\/eodhd.com\/financial-academy\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","width":159,"height":82,"caption":"EODHD (EOD Historical Data)"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/eodhistoricaldata","https:\/\/x.com\/EOD_data","https:\/\/www.reddit.com\/r\/EODHistoricalData\/","https:\/\/eod-historical-data.medium.com\/"]},{"@type":"Person","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/f085666760ee7f148d1923a296cf3fe3","name":"Kevin Meneses Gonz\u00e1lez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/19dee2010941996b1cce342ad66f6964baa6eac898570992e3cddc1b00143a79?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/19dee2010941996b1cce342ad66f6964baa6eac898570992e3cddc1b00143a79?s=96&d=mm&r=g","caption":"Kevin Meneses Gonz\u00e1lez"},"description":"Kevin Meneses Gonz\u00e1lez is a CRM consultant and technical content creator focused on Python, AI, and financial data. He writes practical tutorials on using APIs and automation to analyze markets and build investment research tools.","sameAs":["https:\/\/kevinmeneses.com\/en","https:\/\/www.linkedin.com\/in\/kevin-meneses-gonzalez\/","https:\/\/www.youtube.com\/@pythonia6131"],"url":"https:\/\/eodhd.com\/financial-academy\/author\/kevinmeneses"}]}},"jetpack_featured_media_url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_444970118-1.jpeg","jetpack_shortlink":"https:\/\/wp.me\/pdOdVT-1RR","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/7183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/comments?post=7183"}],"version-history":[{"count":3,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/7183\/revisions"}],"predecessor-version":[{"id":7189,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/7183\/revisions\/7189"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media\/1918"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=7183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=7183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=7183"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=7183"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=7183"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=7183"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=7183"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=7183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}