{"id":84143,"date":"2021-04-16T09:47:48","date_gmt":"2021-04-16T13:47:48","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=84143"},"modified":"2022-11-21T09:47:20","modified_gmt":"2022-11-21T14:47:20","slug":"how-to-create-kalman-filter-in-python-part-vii","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/","title":{"rendered":"How to Create Kalman Filter in Python \u2013 Part VII"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><em>In the final installment of this series, Rekhit Pachanekar demonstrates how to code in Python to create a sample pairs trading script.<\/em> <em>See&nbsp;<a href=\"\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python\/\">Part I<\/a>,&nbsp;<a href=\"\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-ii\/\">Part II<\/a>&nbsp;,&nbsp;<a href=\"\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-iii\/\">Part III<\/a>,&nbsp;&nbsp;<a href=\"\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-iv\/\">Part IV<\/a>,&nbsp;<a href=\"\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-v\/\">Part V<\/a>&nbsp;and <a href=\"\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vi\/\">Part VI<\/a> of this series for details on the statistical terms and concepts used for creating Kalman Filter.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"pairs-trading-strategy\">Pairs trading strategy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In&nbsp;<a href=\"https:\/\/quantra.quantinsti.com\/glossary\/Pairs-Trading\" target=\"_blank\" rel=\"noreferrer noopener\">pairs trading<\/a>&nbsp;strategy we buy one stock and sell the other stock choosing the quantity as hedge ratio. <\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\"> \n# Use the observed values of the price to get a rolling mean and z_score<br>\nmean, cov =  kf.filter(ratio.values)<br>\ndata[&#8216;mean&#8217;] = mean.squeeze()<br>\ndata[&#8216;cov&#8217;] = cov.squeeze()<br>\ndata[&#8216;std&#8217;] = np.sqrt(data[&#8216;cov&#8217;])<br>\ndata = data.dropna()<br><br>\n\ndata[&#8216;ma&#8217;] = data[&#8216;ratio&#8217;].rolling(5).mean()<br>\ndata[&#8216;z_score&#8217;] = (data[&#8216;ma&#8217;] &#8211; data[&#8216;mean&#8217;])\/data[&#8216;std&#8217;]<br><br>\n\n# Initialise positions as zero<br>\ndata[&#8216;position_1&#8217;] = np.nan<br>\ndata[&#8216;position_2&#8217;] = np.nan<br><br>\n\n# Generate buy, sell and square off signals as: z<-1 buy, z>1 sell and -1<z<1 liquidate the position<br>\nfor i in range (data.shape[0]):<br>\n  if data[&#8216;z_score&#8217;].iloc[i] < -1:<br>\n    data[&#8216;position_1&#8217;].iloc[i] = 1<br>\n    data[&#8216;position_2&#8217;].iloc[i] = -round(data[&#8216;ratio&#8217;].iloc[i],0)<br>\n  if data[&#8216;z_score&#8217;].iloc[i] > 1:<br>\n    data[&#8216;position_1&#8217;].iloc[i] = -1<br>\n    data[&#8216;position_2&#8217;].iloc[i] = round(data[&#8216;ratio&#8217;].iloc[i],0)<br>\n  if (abs(data[&#8216;z_score&#8217;].iloc[i]) < 1) &#038; (abs(data['z_score'].iloc[i]) > 0):<br>\n    data[&#8216;position_1&#8217;].iloc[i] = 0<br>\n    data[&#8216;position_2&#8217;].iloc[i] = 0<br><br>\n    \n# Calculate returns<br>\ndata[&#8216;returns&#8217;] = ((data[&#8216;BAJAJ&#8217;]-data[&#8216;BAJAJ&#8217;].shift(1))\/data[&#8216;BAJAJ&#8217;].shift(1))*data[&#8216;position_1&#8217;].shift(1)+ ((data[&#8216;HERO&#8217;]-data[&#8216;HERO&#8217;].shift(1))\/data<br>[&#8216;HERO&#8217;].shift(1))*data[&#8216;position_2&#8217;].shift(1)<br>\ndata[&#8216;returns&#8217;].sum()\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The output is: 0.12282433836398741<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Download the full code:&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/kalman-filter\/\">https:\/\/blog.quantinsti.com\/kalman-filter\/<\/a>. You can learn more about pairs trading strategies in the&nbsp;<a href=\"https:\/\/quantra.quantinsti.com\/course\/statistical-arbitrage-trading\" target=\"_blank\" rel=\"noreferrer noopener\">statistical arbitrage<\/a>&nbsp;course on Quantra.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><small><em>All data and information provided in this article are for informational purposes only. QuantInsti\u00ae makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information in this article and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis.<\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the final installment of this series, Rekhit Pachanekar demonstrates how to code in Python to create a sample pairs trading script.<\/p>\n","protected":false},"author":91,"featured_media":25709,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[339,343,349,338,350,341,344],"tags":[851,9484,8778,9487,8920,4272,9242,8710,4659,8777,9564,9486,9482,595,9483,4580,1048,4271,9152,9565,8155],"contributors-categories":[13654],"class_list":["post-84143","post","type-post","status-publish","format-standard","has-post-thumbnail","category-data-science","category-programing-languages","category-python-development","category-ibkr-quant-news","category-quant-asia-pacific","category-quant-development","category-quant-regions","tag-algo-trading","tag-auquan_toolbox","tag-bessels-correction","tag-datetime","tag-equations-in-kalman-filter","tag-kalman-filter","tag-kalman-gain-equation","tag-mathematical-finance","tag-matplotlib","tag-normal-distribution","tag-numpy-pairs","tag-poly1d","tag-pykalman","tag-python","tag-qq-training-wheels","tag-seaborn","tag-standard-deviation","tag-statistical-arbitrage","tag-status-update-equation","tag-trading-pandas","tag-variance","contributors-categories-quantinsti"],"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v28.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Create Kalman Filter in Python \u2013 Part VII<\/title>\n<meta name=\"description\" content=\"In the final installment of this series, Rekhit Pachanekar demonstrates how to code in Python to create a sample pairs trading script.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/84143\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Kalman Filter in Python \u2013 Part VII | IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"In the final installment of this series, Rekhit Pachanekar demonstrates how to code in Python to create a sample pairs trading script.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-16T13:47:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T14:47:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/python-charts.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Rekhit Pachanekar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rekhit Pachanekar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python-part-vii\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python-part-vii\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Rekhit Pachanekar\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/8ab08253f8958ae9552fd7d7b5697370\"\n\t            },\n\t            \"headline\": \"How to Create Kalman Filter in Python \u2013 Part VII\",\n\t            \"datePublished\": \"2021-04-16T13:47:48+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:47:20+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python-part-vii\\\/\"\n\t            },\n\t            \"wordCount\": 303,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python-part-vii\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/11\\\/python-charts.jpg\",\n\t            \"keywords\": [\n\t                \"Algo Trading\",\n\t                \"auquan_toolbox\",\n\t                \"Bessel's Correction\",\n\t                \"datetime\",\n\t                \"Equations in Kalman Filter\",\n\t                \"Kalman filter\",\n\t                \"Kalman Gain equation\",\n\t                \"Mathematical Finance\",\n\t                \"Matplotlib\",\n\t                \"normal distribution\",\n\t                \"NumPy Pairs\",\n\t                \"poly1d\",\n\t                \"pykalman\",\n\t                \"Python\",\n\t                \"qq-training-wheels\",\n\t                \"Seaborn\",\n\t                \"Standard Deviation\",\n\t                \"Statistical Arbitrage\",\n\t                \"Status update equation\",\n\t                \"Trading Pandas\",\n\t                \"Variance\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Python Development\",\n\t                \"Quant\",\n\t                \"Quant Asia Pacific\",\n\t                \"Quant Development\",\n\t                \"Quant Regions\"\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python-part-vii\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python-part-vii\\\/\",\n\t            \"name\": \"How to Create Kalman Filter in Python \u2013 Part VII | IBKR Quant Blog\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python-part-vii\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python-part-vii\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/11\\\/python-charts.jpg\",\n\t            \"datePublished\": \"2021-04-16T13:47:48+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:47:20+00:00\",\n\t            \"description\": \"In the final installment of this series, Rekhit Pachanekar demonstrates how to code in Python to create a sample pairs trading script.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python-part-vii\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python-part-vii\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/11\\\/python-charts.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/11\\\/python-charts.jpg\",\n\t            \"width\": 900,\n\t            \"height\": 540,\n\t            \"caption\": \"Python\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/8ab08253f8958ae9552fd7d7b5697370\",\n\t            \"name\": \"Rekhit Pachanekar\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/rekhit\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Create Kalman Filter in Python \u2013 Part VII","description":"In the final installment of this series, Rekhit Pachanekar demonstrates how to code in Python to create a sample pairs trading script.","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:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/84143\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Kalman Filter in Python \u2013 Part VII | IBKR Quant Blog","og_description":"In the final installment of this series, Rekhit Pachanekar demonstrates how to code in Python to create a sample pairs trading script.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/","og_site_name":"IBKR Campus US","article_published_time":"2021-04-16T13:47:48+00:00","article_modified_time":"2022-11-21T14:47:20+00:00","og_image":[{"width":900,"height":540,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/python-charts.jpg","type":"image\/jpeg"}],"author":"Rekhit Pachanekar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rekhit Pachanekar","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/"},"author":{"name":"Rekhit Pachanekar","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/8ab08253f8958ae9552fd7d7b5697370"},"headline":"How to Create Kalman Filter in Python \u2013 Part VII","datePublished":"2021-04-16T13:47:48+00:00","dateModified":"2022-11-21T14:47:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/"},"wordCount":303,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/python-charts.jpg","keywords":["Algo Trading","auquan_toolbox","Bessel's Correction","datetime","Equations in Kalman Filter","Kalman filter","Kalman Gain equation","Mathematical Finance","Matplotlib","normal distribution","NumPy Pairs","poly1d","pykalman","Python","qq-training-wheels","Seaborn","Standard Deviation","Statistical Arbitrage","Status update equation","Trading Pandas","Variance"],"articleSection":["Data Science","Programming Languages","Python Development","Quant","Quant Asia Pacific","Quant Development","Quant Regions"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/","name":"How to Create Kalman Filter in Python \u2013 Part VII | IBKR Quant Blog","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/python-charts.jpg","datePublished":"2021-04-16T13:47:48+00:00","dateModified":"2022-11-21T14:47:20+00:00","description":"In the final installment of this series, Rekhit Pachanekar demonstrates how to code in Python to create a sample pairs trading script.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python-part-vii\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/python-charts.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/python-charts.jpg","width":900,"height":540,"caption":"Python"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/8ab08253f8958ae9552fd7d7b5697370","name":"Rekhit Pachanekar","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/rekhit\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/python-charts.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/84143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/91"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=84143"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/84143\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/25709"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=84143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=84143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=84143"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=84143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}