{"id":158343,"date":"2022-09-21T10:27:47","date_gmt":"2022-09-21T14:27:47","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=158343"},"modified":"2022-11-21T09:58:22","modified_gmt":"2022-11-21T14:58:22","slug":"using-python-lambda-function-in-trading","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/","title":{"rendered":"Using Python Lambda Function in Trading"},"content":{"rendered":"\n<p>If you are a trader who uses Python for coding the trade positions, lambda is the function you would want to explore. Lambda helps you use a function only once, and hence, avoids cluttering up the code with function definitions.<\/p>\n\n\n\n<p>In short, Python\u2019s lambda keyword lets you define a function in a single line of code and use it immediately.<\/p>\n\n\n\n<p>Let us find out more about the interesting lambda function further with this blog that covers:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>What is the lambda function in Python?<\/li><li>Why is it called the lambda function?<\/li><li>Lambda arguments and syntax<\/li><li>Difference between the conventional function and lambda function<\/li><li>When to use the lambda function?<\/li><li>How does the lambda function work?<\/li><li>Python lambda in trading<\/li><li>Benefits of lambda function in trading<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-the-lambda-function-in-python\">What is the lambda function in Python?<\/h2>\n\n\n\n<p>Coming to our main topic first, let us discuss the short and anonymous (without a name) lambda function.<\/p>\n\n\n\n<p>A lambda function also called an anonymous or inline function, is a single line of Python code that evaluates an expression. Also, a lambda function can accept any number of parameters and always returns a value.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-is-it-called-the-lambda-function\">Why is it called the lambda function?<\/h2>\n\n\n\n<p>In Python, lambda is an anonymous function and hence, is defined without a name. While normal functions are defined using the \u201cdef\u201d keyword in Python, the anonymous functions are defined using the \u201clambda\u201d keyword.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"lambda-arguments-and-syntax\">Lambda arguments and syntax<\/h2>\n\n\n\n<p>Let us see the lambda syntax below.<\/p>\n\n\n\n<p><strong>lambda num: num * num * num<\/strong><\/p>\n\n\n\n<p>The above syntax, when inserted with real values, returns the cube of a given number. The lambda function lacks a name, which is why you might see it called an anonymous function.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"difference-between-the-conventional-function-and-lambda-function\">Difference between the conventional function and lambda function<\/h2>\n\n\n\n<p>Lambda is used to construct a python function; it is an in-line function, unlike the conventional def function which allows constructing in blocks. Let\u2019s compare the syntax of the conventional function construct with the lambda function syntax to make things clear.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large img-twothird\"><img decoding=\"async\" width=\"489\" height=\"104\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/conventional-function-vs-lambda-function-quantinsti.jpg\" alt=\"\" class=\"wp-image-158371 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/conventional-function-vs-lambda-function-quantinsti.jpg 489w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/conventional-function-vs-lambda-function-quantinsti-300x64.jpg 300w\" data-sizes=\"(max-width: 489px) 100vw, 489px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 489px; aspect-ratio: 489\/104;\" \/><\/figure>\n\n\n\n<p>One can have any number of statements in the conventional def function, and it starts by giving a name to the function. On the other hand, lambda is an anonymous function. You need not provide any name to the lambda construct.<\/p>\n\n\n\n<p>Let us take simple examples to illustrate their usage.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large img-twothird\"><img decoding=\"async\" width=\"410\" height=\"114\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/Conventional-lambda-function-quantinsti.jpg\" alt=\"\" class=\"wp-image-158380 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/Conventional-lambda-function-quantinsti.jpg 410w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/09\/Conventional-lambda-function-quantinsti-300x83.jpg 300w\" data-sizes=\"(max-width: 410px) 100vw, 410px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 410px; aspect-ratio: 410\/114;\" \/><\/figure>\n\n\n\n<p>The lambda construct is more used for its convenience rather than the range of operations that can be performed using lambda. Remember the following points when you need to construct a lambda function.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Lambda is an expression and not a statement. It does not support a block of expressions.<\/li><li>Lambda is defined at the point where we need to use it and need not be named<\/li><li>Lambda does not require a return statement. It always returns something after evaluation.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"when-to-use-the-lambda-function\">When to use the lambda function?<\/h2>\n\n\n\n<p>Well, the best part about using the lambda function is that it can be used in place of any regular function that evaluates a single expression and returns a value.<\/p>\n\n\n\n<p>But, if you want your function to change a global variable, read from a file, or evaluate more than one expression, it will not work as a lambda function. In Python programming, however, the lambda function is ease for most cases.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-does-the-lambda-function-work\">How does the lambda function work?<\/h2>\n\n\n\n<p><strong>Using Lambda with Map, Filter, and Reduce functions<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"map-function\">Map function<\/h3>\n\n\n\n<p>Lambda functions are usually used in conjunction with the functions like map(), filter(), and reduce(). Let us illustrate their usage.<\/p>\n\n\n\n<p>\u200b\u200bThe map function is used to pass a function to each item in an iterable object. The map function returns a list containing all the results without modifying the original object.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>score = &#91;\n(10, 5),\n(20, 2),\n(30, 4),\n(40, 7)\n]\nresult = map(lambda x: x&#91;0] \/ x&#91;1], score)\nfor item in result:\nprint(f\"Lambda returned the answer: {item}\")<\/code><\/pre>\n\n\n\n<p>In the code above, we defined a list of tuples named score. The map function was, then, called with the lambda function as the first argument and the list as the second argument.<\/p>\n\n\n\n<p>Lambda function was written in the code to expect a tuple as an argument. It returns the value stored in element 0 of the tuple divided by the value stored in element 1.<\/p>\n\n\n\n<p>After map runs, we\u2019ll store the results in the variable result. Then, iterate through the list of results and print them. The results of division are expected to be 10 in every case.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"filter-function\">Filter function<\/h3>\n\n\n\n<p>The filter function is used to extract each element in the iterable object for which the function returns True. In this case, we will define the function using the lambda construct and apply the filter function.<\/p>\n\n\n\n<p>Let\u2019s look at how we can use filter to find even-numbered list items. To do so, we\u2019ll need to write a lambda function that\u2019s true only when the number we pass to it satisfies our conditions.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>data = &#91;1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\nresult = filter(lambda x: x % 2 == 0, data)\nprint(f\"Lambda returned the answer: {list(result)}\")<\/code><\/pre>\n\n\n\n<p>In the above code, each list item is divided by two and the remainder is checked. If the remainder is zero, we know the number is even.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"reduce-function\">Reduce function<\/h3>\n\n\n\n<p>The reduce function is a unique function which reduces the input list to a single value by calling the function provided as part of the argument. &nbsp;The reduce function by default starts from the first value of the list and passes the current output along to the next item from the list.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from functools import reduce\nscore = &#91;20, 30, 40, 50]\nresult = reduce(lambda x, y: x + y, score)\nprint(f\"Lambda returned the answer: {result}\")<\/code><\/pre>\n\n\n\n<p>In the above example, we added the list items together in the lambda expression. Reduce starts with an empty accumulator and adds the first item. It then sets the accumulator to the result of the first operation and repeats.<\/p>\n\n\n\n<p>These were some of the ways in which we can use the lambda construct.<\/p>\n\n\n\n<p><em>Stay tuned for the next installment, in which Chainika Thakar will discuss Python lambda in trading.<\/em><\/p>\n\n\n\n<p><em>Visit QuantInsti website for additional insight on this topic: <a href=\"https:\/\/blog.quantinsti.com\/using-python-lambda-function-in-trading\/\">https:\/\/blog.quantinsti.com\/using-python-lambda-function-in-trading\/<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In short, Python\u2019s lambda keyword lets you define a function in a single line of code and use it immediately.<\/p>\n","protected":false},"author":368,"featured_media":40540,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,349,338,341,352,344],"tags":[851,1006,12766,595],"contributors-categories":[13654],"class_list":{"0":"post-158343","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-python-development","10":"category-ibkr-quant-news","11":"category-quant-development","12":"category-quant-north-america","13":"category-quant-regions","14":"tag-algo-trading","15":"tag-fintech","16":"tag-lambda-function","17":"tag-python","18":"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 v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Using Python Lambda Function in Trading | IBKR Quant<\/title>\n<meta name=\"description\" content=\"In short, Python\u2019s lambda keyword lets you define a function in a single line of code and use it immediately.\" \/>\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\/158343\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Python Lambda Function in Trading | IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"In short, Python\u2019s lambda keyword lets you define a function in a single line of code and use it immediately.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-21T14:27:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T14:58:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/04\/python-programming-keyboard.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=\"Chainika Thakar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Chainika Thakar\" \/>\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\\\/using-python-lambda-function-in-trading\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-python-lambda-function-in-trading\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Chainika Thakar\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/c97b4c6a477fa019494f67cff50fcb10\"\n\t            },\n\t            \"headline\": \"Using Python Lambda Function in Trading\",\n\t            \"datePublished\": \"2022-09-21T14:27:47+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:58:22+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-python-lambda-function-in-trading\\\/\"\n\t            },\n\t            \"wordCount\": 946,\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\\\/using-python-lambda-function-in-trading\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/04\\\/python-programming-keyboard.jpg\",\n\t            \"keywords\": [\n\t                \"Algo Trading\",\n\t                \"fintech\",\n\t                \"Lambda function\",\n\t                \"Python\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Python Development\",\n\t                \"Quant\",\n\t                \"Quant Development\",\n\t                \"Quant North America\",\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\\\/using-python-lambda-function-in-trading\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-python-lambda-function-in-trading\\\/\",\n\t            \"name\": \"Using Python Lambda Function in Trading | 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\\\/using-python-lambda-function-in-trading\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/using-python-lambda-function-in-trading\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/04\\\/python-programming-keyboard.jpg\",\n\t            \"datePublished\": \"2022-09-21T14:27:47+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:58:22+00:00\",\n\t            \"description\": \"In short, Python\u2019s lambda keyword lets you define a function in a single line of code and use it immediately.\",\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\\\/using-python-lambda-function-in-trading\\\/\"\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\\\/using-python-lambda-function-in-trading\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/04\\\/python-programming-keyboard.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/04\\\/python-programming-keyboard.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\\\/c97b4c6a477fa019494f67cff50fcb10\",\n\t            \"name\": \"Chainika Thakar\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/chainikathakar\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Using Python Lambda Function in Trading | IBKR Quant","description":"In short, Python\u2019s lambda keyword lets you define a function in a single line of code and use it immediately.","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\/158343\/","og_locale":"en_US","og_type":"article","og_title":"Using Python Lambda Function in Trading | IBKR Quant Blog","og_description":"In short, Python\u2019s lambda keyword lets you define a function in a single line of code and use it immediately.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/","og_site_name":"IBKR Campus US","article_published_time":"2022-09-21T14:27:47+00:00","article_modified_time":"2022-11-21T14:58:22+00:00","og_image":[{"width":900,"height":550,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/04\/python-programming-keyboard.jpg","type":"image\/jpeg"}],"author":"Chainika Thakar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Chainika Thakar","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/"},"author":{"name":"Chainika Thakar","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/c97b4c6a477fa019494f67cff50fcb10"},"headline":"Using Python Lambda Function in Trading","datePublished":"2022-09-21T14:27:47+00:00","dateModified":"2022-11-21T14:58:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/"},"wordCount":946,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/04\/python-programming-keyboard.jpg","keywords":["Algo Trading","fintech","Lambda function","Python"],"articleSection":["Data Science","Programming Languages","Python Development","Quant","Quant Development","Quant North America","Quant Regions"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/","name":"Using Python Lambda Function in Trading | IBKR Quant Blog","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/04\/python-programming-keyboard.jpg","datePublished":"2022-09-21T14:27:47+00:00","dateModified":"2022-11-21T14:58:22+00:00","description":"In short, Python\u2019s lambda keyword lets you define a function in a single line of code and use it immediately.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/using-python-lambda-function-in-trading\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/04\/python-programming-keyboard.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/04\/python-programming-keyboard.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\/c97b4c6a477fa019494f67cff50fcb10","name":"Chainika Thakar","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/chainikathakar\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/04\/python-programming-keyboard.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/158343","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\/368"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=158343"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/158343\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/40540"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=158343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=158343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=158343"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=158343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}