{"id":196282,"date":"2023-09-15T11:15:59","date_gmt":"2023-09-15T15:15:59","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=196282"},"modified":"2024-05-20T15:22:47","modified_gmt":"2024-05-20T19:22:47","slug":"machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/","title":{"rendered":"Machine Learning for Algorithmic Trading in Python: A Complete Guide &#8211; Part II"},"content":{"rendered":"\n<p><em>See <a href=\"\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-i\/\">Part I<\/a> for an overview.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites-for-creating-machine-learning-algorithms-for-trading-using-python\">Prerequisites for creating machine learning algorithms for trading using Python<\/h2>\n\n\n\n<p>Extensive&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/python-trading-library\/\">Python libraries&nbsp;<\/a>and frameworks make it a popular choice for machine learning tasks, enabling developers to implement and experiment with various algorithms, process and analyse data efficiently, and build predictive models.<\/p>\n\n\n\n<p>In order to create the machine learning algorithms for trading using Python, you will need the following prerequisites:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Installation of Python packages and libraries meant for machine learning<\/li>\n\n\n\n<li>Full-fledged knowledge of steps of machine learning<\/li>\n\n\n\n<li>Knowing the application models<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-a-few-packages-and-libraries\">Install a few packages and libraries<\/h3>\n\n\n\n<p>Python machine learning specifically focuses on using Python for the development and application of machine learning models.<\/p>\n\n\n\n<p>You may add one line to install the packages \u201cpip install&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/python-numpy-tutorial-installation-arrays-random-sampling\/\">numpy<\/a>\u201d You can install the necessary&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/installing-python-packages\/\">packages<\/a>&nbsp;in the Anaconda Prompt using the codes as mentioned below.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Scikit-learn for machine learning<\/li>\n\n\n\n<li>TensorFlow for deep learning<\/li>\n\n\n\n<li>Keras for deep learning<\/li>\n\n\n\n<li>PyTorch for neural networks<\/li>\n\n\n\n<li>NLTK for natural language processing<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"full-fledged-knowledge-of-steps-of-machine-learning\">Full-fledged knowledge of steps of machine learning<\/h3>\n\n\n\n<p>In addition to general Python knowledge, proficiency in Python machine learning necessitates a deeper understanding of machine learning concepts, algorithms, model evaluation, feature engineering, and data preprocessing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"knowing-the-application-models\">Knowing the application models<\/h3>\n\n\n\n<p>The primary focus of Python machine learning is the development and application of models and algorithms for tasks like classification, regression, clustering, recommendation systems, natural language processing, image recognition, and other machine learning applications.<\/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-to-use-algorithmic-trading-with-machine-learning-in-python\">How to use algorithmic trading with machine learning in Python?<\/h2>\n\n\n\n<p>Let us see the steps to doing algorithmic trading with machine learning in Python. These steps are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Problem statement<\/li>\n\n\n\n<li>Getting the data and making it usable for machine learning algorithm<\/li>\n\n\n\n<li>Creating hyperparameter<\/li>\n\n\n\n<li>Splitting the data into test and train sets<\/li>\n\n\n\n<li>Getting the best-fit parameters to create a new function<\/li>\n\n\n\n<li>Making the predictions and checking the performance<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"problem-statement\">Problem Statement<\/h3>\n\n\n\n<p>Let\u2019s start by understanding what we are aiming to do. By the end of this machine learning for algorithmic trading with Python tutorial, I will show you how to create an algorithm that can predict the closing price of a day from the previous OHLC (Open, High, Low, Close) data.<\/p>\n\n\n\n<p>I also want to monitor the prediction error along with the size of the input data.<\/p>\n\n\n\n<p>Let us import all the libraries and packages needed to build this machine-learning algorithm.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import numpy as np\nfrom sklearn.linear_model import Lasso\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.model_selection import RandomizedSearchCV as rcv\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.impute import SimpleImputer\nimport matplotlib.pyplot as plt\nfrom IPython import get_ipython<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/9ba6f86905a6ab63014153f55f2d3522#file-import_libraries_ml-py\">Import_libraries_ML.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\">GitHub<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"getting-the-data-and-making-it-usable-for-machine-learning-algorithm\">Getting the data and making it usable for machine learning algorithm<\/h3>\n\n\n\n<p>To create any algorithm, we need data to train the algorithm and then to make predictions on new unseen data. In this machine learning for algorithmic trading with Python tutorial, we will fetch the data from Yahoo.<\/p>\n\n\n\n<p>To accomplish this, we will use the data reader function from the pandas library. This function is extensively used, enabling you to get data from many online sources.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">avg_err={}\navg_train_err={}\n\n# To fetch financial data\nimport yfinance as yf\n\n# Fetch data\nAAPL_data= yf.download('AAPL', start='2005-1-1', end='2023-1-1', auto_adjust = True)\ndf = df[['Open', 'High', 'Low', 'Close']]<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/8dcaeb5aabaebaaa2f860a96a49ff91a#file-fetch_data_aapl-py\">Fetch_data_AAPL.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\">GitHub<\/a><\/p>\n\n\n\n<p>We are fetching the data of AAPL(ticker) or APPLE. This stock can be used as a proxy for the performance of the S&amp;P 500 index. We specify the year starting from which we will be pulling the data.<\/p>\n\n\n\n<p>Once the data is in, we will discard any data other than the OHLC, such as volume and adjusted Close, to create our data frame \u2018df \u2019.<\/p>\n\n\n\n<p>Now we need to make our predictions from past data, and these past features will aid the&nbsp;<a href=\"https:\/\/quantra.quantinsti.com\/course\/introduction-to-machine-learning-for-trading\">machine learning model trade<\/a>. So, let&#8217;s create new columns in the data frame that contain data with one day lag.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">df = AAPL_data[['Open', 'High', 'Low', 'Close']].copy()\ndf['open']=AAPL_data['Open'].shift(1)\ndf['high']=AAPL_data['High'].shift(1)\ndf['low']=AAPL_data['Low'].shift(1)\ndf['close']=AAPL_data['Close'].shift(1)\ndf=df.dropna()<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/be4f31b18fcc6418643a12662daa2f54#file-data_one_day_lag-py\">Data_one_day_lag.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\">GitHub<\/a><\/p>\n\n\n\n<p>Note: The capital letters are dropped for lower-case letters in the names of new columns.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"creating-hyperparameters\">Creating Hyperparameters<\/h3>\n\n\n\n<p>Although the concept of hyperparameters &nbsp;is worthy of a blog in itself, for now I will just say a few words about them. These are the parameters that the machine learning algorithm can\u2019t learn over but needs to be iterated over. We use them to see which predefined functions or parameters yield the best-fit &nbsp;function.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">imp = SimpleImputer(missing_values=np.nan, strategy='mean')\nsteps = [('imputation', imp),\n('scaler',StandardScaler()),\n('lasso',Lasso())]\npipeline =Pipeline(steps)\nparameters = {'lasso__alpha':np.arange(0.0001,10,.0001),\n'lasso__max_iter':np.random.uniform(100,100000,4)}\nreg = rcv(pipeline, parameters,cv=5)<\/pre>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/quantra-go-algo\/9233e548f91ea238e54de02fd1d9665b#file-creating_hyperparameters-py\">Creating_hyperparameters.py&nbsp;<\/a>hosted with \u2764 by&nbsp;<a href=\"https:\/\/github.com\/\">GitHub<\/a><\/p>\n\n\n\n<p>In this example, I have used Lasso regression which uses the L1 type of regularisation. This is a type of machine learning model based on regression analysis which is used to predict continuous data.<\/p>\n\n\n\n<p>This type of regularisation is very useful when you are using feature selection. It is capable of reducing the coefficient values to zero. The SimpleImputer function replaces any NaN values that can affect our predictions with mean values, as specified in the code.<\/p>\n\n\n\n<p>The \u2018steps\u2019 are a bunch of functions that are incorporated as a part of the Pipeline function. The pipeline is a very efficient tool to carry out multiple operations on the data set. Here we have also passed the Lasso function parameters along with a list of values that can be iterated over.<\/p>\n\n\n\n<p>Although I am not going into details of what exactly these parameters do, they are something worthy of digging deeper into. Finally, I called the randomised search function for performing the cross-validation.<\/p>\n\n\n\n<p>In this example, we used 5-fold cross-validation. In k-fold cross-validation, the original sample is randomly partitioned into k equal-sized subsamples. Of the k subsamples, a single subsample is retained as the validation data for testing the model, and the remaining k-1 subsamples are used as training data.<\/p>\n\n\n\n<p>The cross-validation process is then repeated k times (the folds), with each of the k subsamples used exactly once as the validation data. Cross-validation combines (averages) measures of fit (prediction error) to derive a more accurate estimate of model prediction performance.<\/p>\n\n\n\n<p>Based on the fit parameter, we decide on the best features.<\/p>\n\n\n\n<p>In the next section of the machine learning for algorithmic trading with Python tutorial, we will look at test and train sets.<\/p>\n\n\n\n<p><em>Stay tuned for Part III to learn how to split the data into test and train sets.<\/em><\/p>\n\n\n\n<p><em>Originally posted on&nbsp;<a href=\"https:\/\/blog.quantinsti.com\/trading-using-machine-learning-python\/\">QuantInsti<\/a>&nbsp;Blog.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Extensive Python libraries and frameworks make it a popular choice for machine learning tasks, enabling developers to implement and experiment with various algorithms, process and analyse data efficiently, and build predictive models.<\/p>\n","protected":false},"author":186,"featured_media":183040,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":true,"footnotes":""},"categories":[339,343,349,338,341],"tags":[851,827,852,15989,1225,595,10883,4412,924],"contributors-categories":[13654],"class_list":{"0":"post-196282","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":"tag-algo-trading","13":"tag-keras","14":"tag-machine-learning","15":"tag-nltk","16":"tag-numpy","17":"tag-python","18":"tag-pytorch","19":"tag-scikit-learn","20":"tag-tensorflow","21":"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>Machine Learning for Algorithmic Trading in Python: A Complete Guide &#8211; Part II<\/title>\n<meta name=\"description\" content=\"Extensive Python libraries and frameworks make it a popular choice for machine learning tasks, enabling developers to implement and experiment with...\" \/>\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\/196282\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Machine Learning for Algorithmic Trading in Python: A Complete Guide - Part II | IBKR Campus US\" \/>\n<meta property=\"og:description\" content=\"Extensive Python libraries and frameworks make it a popular choice for machine learning tasks, enabling developers to implement and experiment with various algorithms, process and analyse data efficiently, and build predictive models.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-15T15:15:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-20T19:22:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/python-board.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Contributor Author\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Contributor Author\" \/>\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\\\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Contributor Author\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/e823e46b42ca381080387e794318a485\"\n\t            },\n\t            \"headline\": \"Machine Learning for Algorithmic Trading in Python: A Complete Guide &#8211; Part II\",\n\t            \"datePublished\": \"2023-09-15T15:15:59+00:00\",\n\t            \"dateModified\": \"2024-05-20T19:22:47+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\\\/\"\n\t            },\n\t            \"wordCount\": 1001,\n\t            \"commentCount\": 0,\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\\\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/02\\\/python-board.jpg\",\n\t            \"keywords\": [\n\t                \"Algo Trading\",\n\t                \"Keras\",\n\t                \"Machine Learning\",\n\t                \"NLTK\",\n\t                \"NumPy\",\n\t                \"Python\",\n\t                \"PyTorch\",\n\t                \"Scikit-learn\",\n\t                \"TensorFlow\"\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            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\\\/\",\n\t            \"name\": \"Machine Learning for Algorithmic Trading in Python: A Complete Guide - Part II | IBKR Campus US\",\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\\\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/02\\\/python-board.jpg\",\n\t            \"datePublished\": \"2023-09-15T15:15:59+00:00\",\n\t            \"dateModified\": \"2024-05-20T19:22:47+00:00\",\n\t            \"description\": \"Extensive Python libraries and frameworks make it a popular choice for machine learning tasks, enabling developers to implement and experiment with various algorithms, process and analyse data efficiently, and build predictive models.\",\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\\\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\\\/\"\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\\\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/02\\\/python-board.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/02\\\/python-board.jpg\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"How to Request Market Data via the Python API\"\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\\\/e823e46b42ca381080387e794318a485\",\n\t            \"name\": \"Contributor Author\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/contributor-author\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Machine Learning for Algorithmic Trading in Python: A Complete Guide &#8211; Part II","description":"Extensive Python libraries and frameworks make it a popular choice for machine learning tasks, enabling developers to implement and experiment with...","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\/196282\/","og_locale":"en_US","og_type":"article","og_title":"Machine Learning for Algorithmic Trading in Python: A Complete Guide - Part II | IBKR Campus US","og_description":"Extensive Python libraries and frameworks make it a popular choice for machine learning tasks, enabling developers to implement and experiment with various algorithms, process and analyse data efficiently, and build predictive models.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/","og_site_name":"IBKR Campus US","article_published_time":"2023-09-15T15:15:59+00:00","article_modified_time":"2024-05-20T19:22:47+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/python-board.jpg","type":"image\/jpeg"}],"author":"Contributor Author","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Contributor Author","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/"},"author":{"name":"Contributor Author","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/e823e46b42ca381080387e794318a485"},"headline":"Machine Learning for Algorithmic Trading in Python: A Complete Guide &#8211; Part II","datePublished":"2023-09-15T15:15:59+00:00","dateModified":"2024-05-20T19:22:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/"},"wordCount":1001,"commentCount":0,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/python-board.jpg","keywords":["Algo Trading","Keras","Machine Learning","NLTK","NumPy","Python","PyTorch","Scikit-learn","TensorFlow"],"articleSection":["Data Science","Programming Languages","Python Development","Quant","Quant Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/","name":"Machine Learning for Algorithmic Trading in Python: A Complete Guide - Part II | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/python-board.jpg","datePublished":"2023-09-15T15:15:59+00:00","dateModified":"2024-05-20T19:22:47+00:00","description":"Extensive Python libraries and frameworks make it a popular choice for machine learning tasks, enabling developers to implement and experiment with various algorithms, process and analyse data efficiently, and build predictive models.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/machine-learning-for-algorithmic-trading-in-python-a-complete-guide-part-ii\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/python-board.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/python-board.jpg","width":1000,"height":563,"caption":"How to Request Market Data via the Python API"},{"@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\/e823e46b42ca381080387e794318a485","name":"Contributor Author","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/contributor-author\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/python-board.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/196282","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\/186"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=196282"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/196282\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/183040"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=196282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=196282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=196282"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=196282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}