{"id":1940,"date":"2023-09-08T14:31:53","date_gmt":"2023-09-08T14:31:53","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=1940"},"modified":"2025-02-05T13:15:56","modified_gmt":"2025-02-05T13:15:56","slug":"backtesting-trading-strategies-using-python-pandas","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas","title":{"rendered":"Backtesting Trading Strategies using Python Pandas"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\" id=\"h-using-python-pandas-to-backtest-algorithmic-trading-strategies\">Using Python Pandas to backtest algorithmic trading strategies<\/h3>\n\n\n\n<p>There are so many trading strategies and candlestick patterns out there, but the question is \u2014 how do you measure the&nbsp;performance? This is where a&nbsp;financial&nbsp;data APIs like the one by EODHD are really helpful. You can simulate how a strategy or candlestick pattern would&nbsp;perform&nbsp;using&nbsp;historical&nbsp;data. I wanted to develop a backtesting&nbsp;tool&nbsp;using the data science Pandas library for Python. I\u2019ve created a proof of concept for it, and it\u2019s working well. I will talk you through the thought&nbsp;process&nbsp;I went through while creating it.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-will-we-need\">What will we need?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The EODHD <a href=\"https:\/\/eodhd.com\/financial-apis\/python-financial-libraries-and-code-samples\/#EODHD_APIs_Python_Financial_Library_by_Michael_Whittle\" target=\"_blank\" rel=\"noreferrer noopener\">official Python library<\/a>.<\/li>\n\n\n\n<li>Trading data converted into a Pandas dataframe (<strong>date<\/strong>, <strong>open<\/strong>, <strong>high<\/strong>, <strong>close<\/strong>, <strong>low<\/strong>, <strong>volume<\/strong>)<\/li>\n\n\n\n<li>Configurable test settings (<strong>balance_base<\/strong>, <strong>account_balance<\/strong>, <strong>buy_order_quote<\/strong>)<\/li>\n\n\n\n<li>Apply our buy and sell signals in some form to our data (<strong>set_buy_signals<\/strong>, <strong>set_sell_signals<\/strong>)<\/li>\n\n\n\n<li>We will need to be able to iterate through our data (in this case our Pandas dataframe)<\/li>\n\n\n\n<li>Log the outcome of each completed order<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-building-up-the-code\">Building up the code<\/h2>\n\n\n\n<p>To start off I&#8217;m going to create a &#8220;<strong style=\"font-size: 18px\">pandas-bt.py<\/strong>&#8221; file and import the &#8220;<strong style=\"font-size: 18px\"><a style=\"font-size: 18px\" href=\"https:\/\/github.com\/EodHistoricalData\/EODHD-APIs-Python-Financial-Library\">eodhd<\/a><\/strong>&#8221; library. You may or may not already have the &#8220;<strong style=\"font-size: 18px\"><a style=\"font-size: 18px\" href=\"https:\/\/github.com\/EodHistoricalData\/EODHD-APIs-Python-Financial-Library\">eodhd<\/a><\/strong>&#8221; library installed. I would recommend reinstalling it anyway, which will carry out an upgrade to the latest version if necessary.<\/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 lang=\"python\" class=\"language-python\">% python3 -m pip install eodhd -U<\/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>The starter code will look like this:<\/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 lang=\"python\" class=\"language-python\"># pandas-bt.py\n\nimport sys\nimport pandas as pd\nfrom eodhd import APIClient\n\n\ndef get_ohlc_data() -&gt; pd.DataFrame:\n    \"\"\"Return a DataFrame of OHLC data\"\"\"\n\n    api = APIClient(\"<strong>&lt;Your_API_Key&gt;<\/strong>\")\n    df = api.get_historical_data(symbol=\"HSPX.LSE\", interval=\"d\", iso8601_start=\"2020-01-01\", iso8601_end=\"2023-09-08\")\n    df.drop(columns=[\"symbol\", \"interval\", \"close\"], inplace=True)\n    df.rename(columns={\"adjusted_close\": \"close\"}, inplace=True)\n    print(df)\n\n    return pd.DataFrame([], columns=[\"date\", \"open\", \"high\", \"low\", \"close\"])\n\n\ndef main() -&gt; int:\n    \"\"\"Backtest a strategy using pandas\"\"\"\n\n    df = get_ohlc_data()\n    print(df)\n\n    return 0\n\n\nif __name__ == '__main__':\n    sys.exit(main())\n<\/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=\"812\" height=\"506\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-08-at-12.05.59.png\" alt=\"\" class=\"wp-image-1946\"\/><\/figure>\n\n\n\n<p>929 days of S&amp;P 500 data should be enough.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-trading-strategy\">Trading strategy<\/h2>\n\n\n\n<p>This will work with any trading strategy or candlestick pattern. All we need to do is add a new feature called &#8220;<strong>buy_signal<\/strong>&#8221; with a 1 on a buy signal otherwise a 0. We will do the same for &#8220;<strong>sell_signal<\/strong>&#8220;.<\/p>\n\n\n\n<p>For the purposes of this demonstration I&#8217;m going to use a EMA12\/EMA26 crossover strategy.<\/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 lang=\"python\" class=\"language-python\">def get_ohlc_data() -&gt; pd.DataFrame:\n    \"\"\"Return a DataFrame of OHLC data\"\"\"\n\n    api = APIClient(\"<strong>&lt;Your_API_Key&gt;<\/strong>\")\n    df = api.get_historical_data(symbol=\"HSPX.LSE\", interval=\"d\", iso8601_start=\"2020-01-01\", iso8601_end=\"2023-09-08\")\n    df.drop(columns=[\"symbol\", \"interval\", \"close\"], inplace=True)\n    df.rename(columns={\"adjusted_close\": \"close\"}, inplace=True)\n\n    return df\n\n\ndef main() -&gt; int:\n    \"\"\"Backtest a strategy using pandas\"\"\"\n\n    df = get_ohlc_data()\n\n    df[\"ema12\"] = df[\"close\"].ewm(span=12, adjust=False).mean()\n    df[\"ema26\"] = df[\"close\"].ewm(span=26, adjust=False).mean()\n\n    df[\"ema12gtema26\"] = df[\"ema12\"] &gt; df[\"ema26\"]\n    df[\"buy_signal\"] = df[\"ema12gtema26\"].ne(df[\"ema12gtema26\"].shift())\n    df.loc[df[\"ema12gtema26\"] == False, \"buy_signal\"] = False  # noqa: E712\n    df[\"buy_signal\"] = df[\"buy_signal\"].astype(int)\n\n    df[\"ema12ltema26\"] = df[\"ema12\"] &lt; df[\"ema26\"]\n    df[\"sell_signal\"] = df[\"ema12ltema26\"].ne(df[\"ema12ltema26\"].shift())\n    df.loc[df[\"ema12ltema26\"] == False, \"sell_signal\"] = False  # noqa: E712\n    df[\"sell_signal\"] = df[\"sell_signal\"].astype(int)\n\n    df.drop(columns=[\"ema12\", \"ema26\", \"ema12gtema26\", \"ema12ltema26\"], inplace=True)\n\n    print(df)\n    return 0\n<\/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=\"1164\" height=\"422\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-08-at-13.27.20.png\" alt=\"\" class=\"wp-image-1949\"\/><\/figure>\n\n\n\n<p>What we have now is an OHLC dataset for the S&amp;P 500 daily with the &#8220;<strong>buy_signal<\/strong>&#8221; set to 1 when the EMA12 crosses above the EMA26, and a &#8220;<strong>sell_signal<\/strong>&#8221; when the EMA12 crosses below the EMA26.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-backtesting-the-strategy\">Backtesting the strategy<\/h2>\n\n\n\n<p>We now want to iterate through the dataset and simulate orders.<\/p>\n\n\n\n<p>Add this code instead of the &#8220;<strong>print(df)<\/strong>&#8221; line, above the &#8220;<strong>return 0<\/strong>&#8220;.<\/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 lang=\"python\" class=\"language-python\">    balance_base = 0\n    account_balance = 1000\n    buy_order_quote = 1000\n    is_order_open = False\n    orders = []\n    sell_value = 0\n\n    for index, row in df.iterrows():\n        if row[\"buy_signal\"] and is_order_open == 0:\n            is_order_open = 1\n\n            if sell_value &lt; 1000 and sell_value &gt; 0:\n                buy_order_quote = sell_value\n            else:\n                buy_order_quote = 1000\n\n            buy_amount = buy_order_quote \/ row[\"close\"]\n            balance_base += buy_amount\n            account_balance += sell_value\n\n            order = {\n                \"timestamp\": index,\n                \"account_balance\": account_balance,\n                \"buy_order_quote\": buy_order_quote,\n                \"buy_order_base\": buy_amount\n            }\n\n            account_balance -= buy_order_quote\n\n        if row[\"sell_signal\"] and is_order_open == 1:\n            is_order_open = 0\n\n            sell_value = buy_amount * row[\"close\"]\n            balance_base -= buy_amount\n\n            order[\"sell_order_quote\"] = sell_value\n            order[\"profit\"] = order[\"sell_order_quote\"] - order[\"buy_order_quote\"]\n            order[\"margin\"] = (order[\"profit\"] \/ order[\"buy_order_quote\"]) * 100\n\n            orders.append(order)\n        print(index)\n\n    df_orders = pd.DataFrame(orders)\n    print(df_orders)\n<\/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>&#8220;<strong>balance_base<\/strong>&#8221; is the quantity of the stock we have at the beginning of the simulation, which in this case is 0.<\/p>\n\n\n\n<p>&#8220;<strong>account_balance<\/strong>&#8221; is the quote currency we are starting with for the simulation, in this case \u00a31000.<\/p>\n\n\n\n<p>&#8220;<strong>buy_order_quote<\/strong>&#8221; is the requested size of the order, in this case \u00a31000. If the account balance is less than \u00a31000, then the order will be whatever is available.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1472\" height=\"534\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/Screenshot-2023-09-08-at-13.57.53.png\" alt=\"\" class=\"wp-image-1951\"\/><\/figure>\n\n\n\n<p>This analysis shows that if we traded every EMA12\/EMA26 crossover from January 3rd, 2020, until September 16th, 2023, we would start with \u00a31000 and have \u00a31212.40 at the end, resulting in a&nbsp;21.24% return&nbsp;over 2.75 years. While this&nbsp;performance&nbsp;isn&#8217;t extraordinary, it&#8217;s reasonable.<\/p>\n\n\n\n<p>Please note this doesn&#8217;t factor in exchange fees. For more&nbsp;accurate results, consider applying applicable fees. The point is, you can apply any&nbsp;strategy&nbsp;and see how it would&nbsp;perform&nbsp;over the same period. Once you have a&nbsp;winning formula, give it a go!<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Python Pandas to backtest algorithmic trading strategies There are so many trading strategies and candlestick patterns out there, but the question is \u2014 how do you measure the&nbsp;performance? This is where a&nbsp;financial&nbsp;data APIs like the one by EODHD are really helpful. You can simulate how a strategy or candlestick pattern would&nbsp;perform&nbsp;using&nbsp;historical&nbsp;data. I wanted to [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":1941,"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":[65,59,61],"tags":[],"coding-language":[30],"ready-to-go-solution":[56],"qualification":[31,32],"financial-apis-category":[34,36],"financial-apis-manuals":[47,40],"class_list":["post-1940","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backtesting-strategies-examples","category-technical-analysis-examples","category-trading-indicators-implimentations","coding-language-python","ready-to-go-solution-eodhd-python-financial-library","qualification-experienced","qualification-guru","financial-apis-category-crypto-market-prices","financial-apis-category-stock-market-prices","financial-apis-manuals-exchanges-data","financial-apis-manuals-technical-indicators","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>Backtesting Trading Strategies with Python Pandas: A Comprehensive Guide | EODHD APIs Academy<\/title>\n<meta name=\"description\" content=\"Learn how to backtest trading strategies with Python and Pandas. Explore a proof of concept for a backtesting framework and improve your trading results\" \/>\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\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Backtesting Trading Strategies using Python Pandas\" \/>\n<meta property=\"og:description\" content=\"Learn how to backtest trading strategies with Python and Pandas. Explore a proof of concept for a backtesting framework and improve your trading results\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas\" \/>\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-08T14:31:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-05T13:15:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_538465094-e1725368266508.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"980\" \/>\n\t<meta property=\"og:image:height\" content=\"647\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Whittle\" \/>\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=\"Michael Whittle\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas\"},\"author\":{\"name\":\"Michael Whittle\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/50784c270b6267df5969514d80d510ad\"},\"headline\":\"Backtesting Trading Strategies using Python Pandas\",\"datePublished\":\"2023-09-08T14:31:53+00:00\",\"dateModified\":\"2025-02-05T13:15:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas\"},\"wordCount\":545,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_538465094-e1725368266508.jpeg\",\"articleSection\":[\"Backtesting Strategies Examples\",\"Technical Analysis Examples\",\"Trading Indicators Implimentations\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas\",\"name\":\"Backtesting Trading Strategies with Python Pandas: A Comprehensive Guide | EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_538465094-e1725368266508.jpeg\",\"datePublished\":\"2023-09-08T14:31:53+00:00\",\"dateModified\":\"2025-02-05T13:15:56+00:00\",\"description\":\"Learn how to backtest trading strategies with Python and Pandas. Explore a proof of concept for a backtesting framework and improve your trading results\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#primaryimage\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_538465094-e1725368266508.jpeg\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_538465094-e1725368266508.jpeg\",\"width\":1800,\"height\":1188,\"caption\":\"Business concept. On the quotes chart there are puzzles with the inscription - trading algorithm testing\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Backtesting Trading Strategies using Python Pandas\"}]},{\"@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\/50784c270b6267df5969514d80d510ad\",\"name\":\"Michael Whittle\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g\",\"caption\":\"Michael Whittle\"},\"description\":\"Solution architect, developer, and analyst with over 20+ years experience (TOP author on Medium).\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/author\/michaelwhittle\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Backtesting Trading Strategies with Python Pandas: A Comprehensive Guide | EODHD APIs Academy","description":"Learn how to backtest trading strategies with Python and Pandas. Explore a proof of concept for a backtesting framework and improve your trading results","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\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas","og_locale":"en_US","og_type":"article","og_title":"Backtesting Trading Strategies using Python Pandas","og_description":"Learn how to backtest trading strategies with Python and Pandas. Explore a proof of concept for a backtesting framework and improve your trading results","og_url":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2023-09-08T14:31:53+00:00","article_modified_time":"2025-02-05T13:15:56+00:00","og_image":[{"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_538465094-e1725368266508.jpeg","width":980,"height":647,"type":"image\/jpeg"}],"author":"Michael Whittle","twitter_card":"summary_large_image","twitter_creator":"@EOD_data","twitter_site":"@EOD_data","twitter_misc":{"Written by":"Michael Whittle","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas"},"author":{"name":"Michael Whittle","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/50784c270b6267df5969514d80d510ad"},"headline":"Backtesting Trading Strategies using Python Pandas","datePublished":"2023-09-08T14:31:53+00:00","dateModified":"2025-02-05T13:15:56+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas"},"wordCount":545,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_538465094-e1725368266508.jpeg","articleSection":["Backtesting Strategies Examples","Technical Analysis Examples","Trading Indicators Implimentations"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas","url":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas","name":"Backtesting Trading Strategies with Python Pandas: A Comprehensive Guide | EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_538465094-e1725368266508.jpeg","datePublished":"2023-09-08T14:31:53+00:00","dateModified":"2025-02-05T13:15:56+00:00","description":"Learn how to backtest trading strategies with Python and Pandas. Explore a proof of concept for a backtesting framework and improve your trading results","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#primaryimage","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_538465094-e1725368266508.jpeg","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_538465094-e1725368266508.jpeg","width":1800,"height":1188,"caption":"Business concept. On the quotes chart there are puzzles with the inscription - trading algorithm testing"},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/backtesting-trading-strategies-using-python-pandas#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"Backtesting Trading Strategies using Python Pandas"}]},{"@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\/50784c270b6267df5969514d80d510ad","name":"Michael Whittle","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5076af85c7ee0445454257247cad4970ae8cf5d7d4940d2b32c521f51c0a0f5a?s=96&d=mm&r=g","caption":"Michael Whittle"},"description":"Solution architect, developer, and analyst with over 20+ years experience (TOP author on Medium).","url":"https:\/\/eodhd.com\/financial-academy\/author\/michaelwhittle"}]}},"jetpack_featured_media_url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/09\/AdobeStock_538465094-e1725368266508.jpeg","jetpack_shortlink":"https:\/\/wp.me\/pdOdVT-vi","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1940","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\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/comments?post=1940"}],"version-history":[{"count":14,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1940\/revisions"}],"predecessor-version":[{"id":6280,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1940\/revisions\/6280"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media\/1941"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=1940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=1940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=1940"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=1940"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=1940"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=1940"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=1940"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=1940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}