{"id":66901,"date":"2020-11-23T11:00:00","date_gmt":"2020-11-23T16:00:00","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=66901"},"modified":"2022-11-21T09:46:39","modified_gmt":"2022-11-21T14:46:39","slug":"how-to-create-kalman-filter-in-python","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python\/","title":{"rendered":"How to Create Kalman Filter in Python"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If we had to explain Kalman Filter in one line, we would say that it is used to provide an accurate prediction of a variable which cannot be directly measured. In fact, one of the earliest uses of the Kalman filter was to calculate the position of the Apollo space rockets by NASA to make sure it was on the right path.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But how is it applicable in trading? Well, we can use Kalman Filter to implement&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/implementing-pairs-trading-using-kalman-filter\/\">pairs trading<\/a>, or even find arbitrage opportunities in the&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/kalman-filter-techniques-statistical-arbitrage-china-futures-market-python\/\">Futures market<\/a>. But before we start the applications of Kalman filters, let us understand how to use it. Thus, in this blog we will cover the following topics:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Statistical terms and concepts used in Kalman Filter<\/li><li>Equations in Kalman Filter<\/li><li>Pairs trading using Kalman Filter in Python<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">As such, Kalman filter can be considered a heavy topic when it comes to the use of math and statistics. Thus, we will go through a few terms before we dig into the equations. Feel free to skip this section and head directly to the equations if you wish.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"statistical-terms-and-concepts-used-in-kalman-filter\">Statistical terms and concepts used in Kalman Filter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Kalman Filter uses the concept of a&nbsp;<strong>normal distribution<\/strong>&nbsp;in its equation to give us an idea about the accuracy of the estimate. Let us step back a little and understand how we get a normal distribution of a variable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let us suppose we have a football team of ten people who are playing the nationals. As part of a standard health check-up, we measure their weights. The weights of the players are given below.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Player Number&nbsp;<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><td>5<\/td><td>6<\/td><td>7<\/td><td>8<\/td><td>9<\/td><td>10<\/td><\/tr><tr><td>Weight<\/td><td>72<\/td><td>75<\/td><td>76<\/td><td>69<\/td><td>65<\/td><td>71<\/td><td>70<\/td><td>74<\/td><td>76<\/td><td>72<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now if we calculate the average weight, ie the&nbsp;<strong>mean<\/strong>, we get the value as (Total of all player weights) \/ (Total no. of players)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">= 720\/10 = 72<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The mean is usually denoted by the Greek alphabet \u03bc. If we consider the weights as w<sub>1<\/sub>, w<sub>2<\/sub>&nbsp;respectively and the total number of players as N, we can write it as: \u03bc = (w<sub>1<\/sub>&nbsp;+ w<sub>2<\/sub>+ w<sub>3<\/sub>+ w<sub>4<\/sub>+&#8230;..+ w<sub>n<\/sub>)\/N<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Or<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-1.png\" alt=\"\" class=\"wp-image-67116 lazyload\" width=\"254\" height=\"112\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 254px; aspect-ratio: 254\/112;\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Now, on a hunch, we decide on seeing how much each player\u2019s weight varies from the mean. This can be easily calculated by subtracting the individual\u2019s weight from the mean value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, the first team player\u2019s weight varies in the following manner, (Individual player\u2019s weight) &#8211; (Mean value) = 72 &#8211; 72 = 0.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Similarly, the second player\u2019s weight varies by the following: 75 &#8211; 72 = 3. Let\u2019s update the table now.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Player Number<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><td>5<\/td><td>6<\/td><td>7<\/td><td>8<\/td><td>9<\/td><td>10<\/td><\/tr><tr><td>Weight<\/td><td>72<\/td><td>75<\/td><td>76<\/td><td>69<\/td><td>65<\/td><td>71<\/td><td>70<\/td><td>74<\/td><td>76<\/td><td>72<\/td><\/tr><tr><td>Difference from mean<\/td><td>0<\/td><td>3<\/td><td>4<\/td><td>-3<\/td><td>-7<\/td><td>-1<\/td><td>-2<\/td><td>2<\/td><td>4<\/td><td>0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now, we want to see how much the entire team\u2019s weights\u2019 varies from the mean. A simple addition of the entire team\u2019s weight difference from the mean would be 0 as shown below. Thus we square each individual\u2019s weight difference and find the average. Squaring is done to eliminate the negative sign of a score + penalise greater divergence from mean.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The updated table is as follows:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Player Number<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><td>5<\/td><td>6<\/td><td>7<\/td><td>8<\/td><td>9<\/td><td>10<\/td><\/tr><tr><td>Weight<\/td><td>72<\/td><td>75<\/td><td>76<\/td><td>69<\/td><td>65<\/td><td>71<\/td><td>70<\/td><td>74<\/td><td>76<\/td><td>72<\/td><\/tr><tr><td>Difference from mean<\/td><td>0<\/td><td>3<\/td><td>4<\/td><td>-3<\/td><td>-7<\/td><td>-1<\/td><td>-2<\/td><td>2<\/td><td>4<\/td><td>0<\/td><\/tr><tr><td>Squared difference from the mean<\/td><td>0<\/td><td>9<\/td><td>16<\/td><td>9<\/td><td>49<\/td><td>1<\/td><td>4<\/td><td>4<\/td><td>16<\/td><td>0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now if we take the average, we get the equation as,<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-2.png\" alt=\"\" class=\"wp-image-67117 lazyload\" width=\"304\" height=\"92\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-2.png 304w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-2-300x91.png 300w\" data-sizes=\"(max-width: 304px) 100vw, 304px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 304px; aspect-ratio: 304\/92;\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>variance<\/strong>&nbsp;tells us how much the weights have been spread. Since the variance is the average of the squares, we will take the square root of the variance to give us a better idea of the distribution of weights. We call this term the&nbsp;<strong>standard deviation<\/strong>&nbsp;and denote it by \u03c3.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-3.png\" alt=\"\" class=\"wp-image-67118 lazyload\" width=\"498\" height=\"117\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-3.png 498w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-3-300x70.png 300w\" data-sizes=\"(max-width: 498px) 100vw, 498px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 498px; aspect-ratio: 498\/117;\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Since standard deviation is denoted by \u03c3, the variance is denoted by \u03c3<sup>2.<\/sup><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But why do we need standard deviation? While we calculated the variance and standard deviation of one football team, maybe we could find for all the football teams in the tournament, or if we are more ambitious, we can do the same for all the football teams in the world. That would be a large dataset.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One thing to understand is that for a small dataset w used all the values, ie the entire population to compute the values. However, if it is a large dataset, we usually take a sample at random from the entire population and find the estimated values. In this case, we replace N by (N-1) to get the most accurate answer as per&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Bessel%27s_correction\" target=\"_blank\" rel=\"noreferrer noopener\">Bessel&#8217;s correction<\/a>. Of course, this introduces some error, but we will ignore it for now.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thus, the updated equation is,<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-4.png\" alt=\"\" class=\"wp-image-67119 lazyload\" width=\"379\" height=\"121\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-4.png 379w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-4-300x96.png 300w\" data-sizes=\"(max-width: 379px) 100vw, 379px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 379px; aspect-ratio: 379\/121;\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Now, looking at different researches conducted in the past, it was found that given a large dataset, most of the data was concentrated around the mean, with 68% of the entire data variables coming within one standard deviation from the mean.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This means that if we had data about millions of football players, and we got the same standard deviation and variance which we received now, we would say that the probability that the player\u2019s weight is +-3.46 from 72 kg is 68.26%. This means that 68.26% of the players\u2019 weights would be from 68.53 kg to 75.46.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Of course, for this to be right, the data should be random.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s draw a graph to understand this further. This is just a reference of how the distribution will look if we had the weights of 100 people with mean as 72 and standard deviation as 3.46.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/Histogram-of-Weight-quantInsti.png\" alt=\"\" class=\"wp-image-67120 lazyload\" width=\"688\" height=\"425\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/Histogram-of-Weight-quantInsti.png 688w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/Histogram-of-Weight-quantInsti-300x185.png 300w\" data-sizes=\"(max-width: 688px) 100vw, 688px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 688px; aspect-ratio: 688\/425;\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This shows how the weights are concentrated around the mean and tapers off towards the extremes. If we create a curve, you will find that it is shaped like a bell and thus we call it a&nbsp;<strong>bell curve<\/strong>. The&nbsp;<a href=\"https:\/\/quantra.quantinsti.com\/glossary\/Standard-Normal-Distribution\" target=\"_blank\" rel=\"noreferrer noopener\">normal distribution<\/a>&nbsp;of the weights with mean as 72 and standard deviation as 3.46 will look similar to the following diagram.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/Normal-Distribution-of-weights-quantinsti.png\" alt=\"\" class=\"wp-image-67121 lazyload\" width=\"905\" height=\"559\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/Normal-Distribution-of-weights-quantinsti.png 905w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/Normal-Distribution-of-weights-quantinsti-700x432.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/Normal-Distribution-of-weights-quantinsti-300x185.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/Normal-Distribution-of-weights-quantinsti-768x474.png 768w\" data-sizes=\"(max-width: 905px) 100vw, 905px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 905px; aspect-ratio: 905\/559;\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Normal distribution is also called a probability density function. While the derivation is quite lengthy, we have certain observations regarding the probability density function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One standard deviation contains&nbsp;<strong>68.26<\/strong>% of the population.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Two standard deviations contain&nbsp;<strong>95.44<\/strong>% of the population while three contain 99.74%.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The probability density function is given as follows,<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-5.png\" alt=\"\" class=\"wp-image-67122 lazyload\" width=\"327\" height=\"114\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-5.png 327w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/kalman-python-5-300x105.png 300w\" data-sizes=\"(max-width: 327px) 100vw, 327px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 327px; aspect-ratio: 327\/114;\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">You can find out more about probability density function in this&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/statistics-probability-distribution\/\">blog<\/a>. The reason we talked about normal distribution is that it forms an important part in Kalman filters. Let\u2019s now move on to the main topic in the next section of the Kalman filter tutorial.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Stay tuned for the next installment, in which the Rekhit will explain how to create equations in Kalman Filters.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Download the full code: <a href=\"https:\/\/blog.quantinsti.com\/kalman-filter\/\">https:\/\/blog.quantinsti.com\/kalman-filter\/<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Join QuantInsti for a tutorial on building a Kalman filter in Python! Kalman Filter uses the concept of a normal distribution.<\/p>\n","protected":false},"author":91,"featured_media":66906,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[339,343,349,338,350,341,344],"tags":[851,8778,4272,8710,8777,8445,595,1048,4271,8155],"contributors-categories":[13654],"class_list":["post-66901","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-bessels-correction","tag-kalman-filter","tag-mathematical-finance","tag-normal-distribution","tag-pairs-trading","tag-python","tag-standard-deviation","tag-statistical-arbitrage","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.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Create Kalman Filter in Python | IBKR Quant<\/title>\n<meta name=\"description\" content=\"Join QuantInsti for a tutorial on building a Kalman filter in Python! Kalman Filter uses the concept of a normal distribution.\" \/>\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\/66901\/\" \/>\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 | IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"Join QuantInsti for a tutorial on building a Kalman filter in Python! Kalman Filter uses the concept of a normal distribution.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-23T16:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T14:46:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"550\" \/>\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=\"5 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\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python\\\/\"\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\",\n\t            \"datePublished\": \"2020-11-23T16:00:00+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:46:39+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python\\\/\"\n\t            },\n\t            \"wordCount\": 1053,\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\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/11\\\/python.jpg\",\n\t            \"keywords\": [\n\t                \"Algo Trading\",\n\t                \"Bessel's Correction\",\n\t                \"Kalman filter\",\n\t                \"Mathematical Finance\",\n\t                \"normal distribution\",\n\t                \"Pairs Trading\",\n\t                \"Python\",\n\t                \"Standard Deviation\",\n\t                \"Statistical Arbitrage\",\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\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python\\\/\",\n\t            \"name\": \"How to Create Kalman Filter in Python | 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\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-create-kalman-filter-in-python\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/11\\\/python.jpg\",\n\t            \"datePublished\": \"2020-11-23T16:00:00+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:46:39+00:00\",\n\t            \"description\": \"Join QuantInsti for a tutorial on building a Kalman filter in Python! Kalman Filter uses the concept of a normal distribution.\",\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\\\/\"\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\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/11\\\/python.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/11\\\/python.jpg\",\n\t            \"width\": 900,\n\t            \"height\": 550,\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 | IBKR Quant","description":"Join QuantInsti for a tutorial on building a Kalman filter in Python! Kalman Filter uses the concept of a normal distribution.","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\/66901\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Kalman Filter in Python | IBKR Quant Blog","og_description":"Join QuantInsti for a tutorial on building a Kalman filter in Python! Kalman Filter uses the concept of a normal distribution.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python\/","og_site_name":"IBKR Campus US","article_published_time":"2020-11-23T16:00:00+00:00","article_modified_time":"2022-11-21T14:46:39+00:00","og_image":[{"width":900,"height":550,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/python.jpg","type":"image\/jpeg"}],"author":"Rekhit Pachanekar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rekhit Pachanekar","Est. reading time":"5 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\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python\/"},"author":{"name":"Rekhit Pachanekar","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/8ab08253f8958ae9552fd7d7b5697370"},"headline":"How to Create Kalman Filter in Python","datePublished":"2020-11-23T16:00:00+00:00","dateModified":"2022-11-21T14:46:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python\/"},"wordCount":1053,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/python.jpg","keywords":["Algo Trading","Bessel's Correction","Kalman filter","Mathematical Finance","normal distribution","Pairs Trading","Python","Standard Deviation","Statistical Arbitrage","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\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python\/","name":"How to Create Kalman Filter in Python | 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\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/python.jpg","datePublished":"2020-11-23T16:00:00+00:00","dateModified":"2022-11-21T14:46:39+00:00","description":"Join QuantInsti for a tutorial on building a Kalman filter in Python! Kalman Filter uses the concept of a normal distribution.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-create-kalman-filter-in-python\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/python.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/11\/python.jpg","width":900,"height":550,"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\/2020\/11\/python.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/66901","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=66901"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/66901\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/66906"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=66901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=66901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=66901"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=66901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}