{"id":4079,"date":"2023-12-01T14:36:01","date_gmt":"2023-12-01T14:36:01","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=4079"},"modified":"2025-02-05T11:49:51","modified_gmt":"2025-02-05T11:49:51","slug":"combining-the-forces-of-ai-python-for-better-stock-trading","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading","title":{"rendered":"Combining the Forces of AI + Python for Better Stock Trading"},"content":{"rendered":"\n<p>As we navigate the world of trading, a fundamental truth stands out &#8211; experience is the best teacher. This axiom, playing an integral role in human learning, holds equal importance in the realm of machines. Imagine an algorithm that learns from experience, adapting and evolving with each encounter comes reinforcement learning.<\/p>\n\n\n\n<p>The idea of crafting a bot for trading has long fascinated researchers and enthusiasts alike. There are diverse methods to train models for effective decision-making in the evolving landscape of real-time market conditions. Entrusting an algorithm to make decisions on your behalf is an important decision that demands thorough research and a wealth of data. EODHD APIs provides a vast and real-time dataset that serves as the backbone for applications in reinforcement learning.<\/p>\n\n\n\n<p>In this article, we will embark on a journey to bring a trading bot to life using the power of machine learning. We&#8217;ll explore how the principles of reinforcement learning can be harnessed to create an intelligent trading companion.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Importing the Necessary Libraries<\/strong><\/h2>\n\n\n\n<p>In this step, we&#8217;re getting the tools we need and bringing them into play for the exciting adventure ahead. These packages are quite a diverse bunch, and let&#8217;s take a moment to understand why we&#8217;ve got each of them on board:<\/p>\n\n\n\n<p><strong>eodhd:<\/strong><\/p>\n\n\n\n<p>The official <a href=\"https:\/\/eodhd.com\/financial-apis\/python-financial-libraries-and-code-samples\" target=\"_blank\" rel=\"noreferrer noopener\">Python library of EODHD<\/a> which provides an easy and programmatic way to access the APIs of EODHD seamlessly.<\/p>\n\n\n\n<p><strong>TensorFlow:<\/strong><\/p>\n\n\n\n<p>TensorFlow is a machine learning library used for building and training neural networks, making it ideal for tasks like deep learning, natural language processing, and computer vision.<\/p>\n\n\n\n<p><strong>Stable Baselines3:<\/strong><\/p>\n\n\n\n<p>Stable Baselines3 provides robust implementations of reinforcement learning algorithms in Python. A2C, included in this library, is an algorithm commonly used for solving sequential decision-making problems.<\/p>\n\n\n\n<p><strong>Gym and Gymnasium:<\/strong><\/p>\n\n\n\n<p>OpenAI Gym is a toolkit for developing and comparing reinforcement learning algorithms, offering a range of environments.<\/p>\n\n\n\n<p><strong>Gym Anytrading:<\/strong><\/p>\n\n\n\n<p>Gym Anytrading is an extension of OpenAI Gym tailored for reinforcement learning in financial trading environments, facilitating the development and testing of algorithms in the context of algorithmic trading.<\/p>\n\n\n\n<p><strong>Processing Libraries (NumPy, Pandas, Matplotlib):<\/strong><\/p>\n\n\n\n<p>NumPy enables efficient numerical operations with support for multi-dimensional arrays, while Pandas simplifies data manipulation through its DataFrame structures. Matplotlib is a versatile plotting library for creating visualizations.&nbsp;<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-cbb09c067d6a3354c4386a1935885ef8\"><code lang=\"python\" class=\"language-python\">import gymnasium as gym\nimport gym_anytrading\n\n# Stable baselines - rl stuff\nfrom stable_baselines3.common.vec_env import DummyVecEnv\nfrom stable_baselines3 import A2C\n\n# Processing libraries\nimport numpy as np\n\nimport pandas as pd\nfrom matplotlib import pyplot as plt\n\nfrom eodhd import APIClient<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<h2 class=\"wp-block-heading\" id=\"a9f4\"><strong>API Key Activation<\/strong><\/h2>\n\n\n\n<p id=\"c710\">It is essential to register the EODHD API key with the package in order to use its functions. If you don\u2019t have an EODHD API key, firstly head over to their&nbsp;<a href=\"https:\/\/eodhd.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">website<\/a>, then finish the&nbsp;<a href=\"https:\/\/eodhd.com\/register\" target=\"_blank\" rel=\"noreferrer noopener\">registration<\/a>&nbsp;process to create an EODHD account, and finally navigate to the <a href=\"https:\/\/eodhd.com\/cp\/dashboard\" target=\"_blank\" rel=\"noreferrer noopener\">Dashboard<\/a> where you will find your secret EODHD API key. It is important to ensure that this secret API key is not revealed to anyone. You can activate the API key by following this code:<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\"># API KEY ACTIVATION\n\napi_key = '&lt;YOUR API KEY&gt;'\nclient = APIClient(api_key)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p id=\"fd3d\">The code is pretty simple. In the first line, we are storing the secret EODHD API key into the&nbsp;api_key&nbsp;and then in the second line, we are using the&nbsp;APIClient&nbsp;class provided by the&nbsp;eodhd&nbsp;package to activate the API key and stored the response in the&nbsp;client&nbsp;variable.<\/p>\n\n\n\n<p id=\"4634\">Note that you need to replace&nbsp;&lt;YOUR API KEY&gt;&nbsp;with your secret EODHD API key. Apart from directly storing the API key with text, there are other ways for better security such as utilizing environmental variables, and so on.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8568\"><strong>Extracting Historical Data<\/strong><\/h2>\n\n\n\n<p id=\"ac40\">Before heading into the extraction part, it is first essential to have some background about historical or end-of-day data. In a nutshell, historical data consists of information accumulated over a period of time. It helps in identifying patterns and trends in the data. It also assists in studying market behavior. Now, you can easily extract the historical data of Tesla using the&nbsp;eodhd&nbsp;package by following this code:<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\"># EXTRACTING HISTORICAL DATA\n\ndf = client.get_historical_data('TSLA', 'd', \"2018-11-26\",\"2023-11-24\")\ndf =  df[['open','high','low','close','volume']]\ndf.columns = ['Open','High','Low','Close','Volume']\ndf.tail()<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>The code used here is pretty straightforward. First, we are using the get_historical_data function provided by the eodhd package. This function takes the stock&#8217;s symbol, the time interval between the data points, and the starting and ending date of the dataframe. After that, we are performing some data manipulation processes to format and clean the extracted historical data. Here&#8217;s the final dataframe:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1526\" height=\"552\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-16.png\" alt=\"\" class=\"wp-image-4081\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Using the Trading Gym<\/strong><\/h2>\n\n\n\n<p>The step will create and explore the environment created using Any Trading, a combination of openai gym for trading.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-6ab27c3c9fa4116e25169cac2e444ffb\"><code lang=\"python\" class=\"language-python\">env = gym.make('stocks-v0', df=df, frame_bound=(5, len(df)-1), window_size=5)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>This action will generate the default environment. Feel free to modify any parameters, like the dataset or frame_bound, to tailor the environment to your specific preferences.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-879d59ee2b63e5e95173af693a45fa89\"><code lang=\"python\" class=\"language-python\">state = env.reset()\nenv.render()<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"560\" height=\"461\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-17.png\" alt=\"\" class=\"wp-image-4082\"\/><\/figure>\n\n\n\n<p>The output illustrates how the environment perceives the dataset.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Training and Predicting the Model<\/strong><\/h2>\n\n\n\n<p>The environment created in the previous will go into our model for training and further for real-life use cases in this step.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-bbd764813fe96725a723d05e1a50f6ca\"><code lang=\"python\" class=\"language-python\">state = env.reset()\nwhile True:\n    action = env.action_space.sample()\n    observation, reward, terminated, truncated, info = env.step(action)\n    done = terminated or truncated\n\n    # env.render()\n    if done:\n        print(\"info:\", info)\n        break\n\nplt.cla()\nenv.unwrapped.render_all()\nplt.show()<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>The process involves categorizing observations, rewards, termination status, truncation, and additional information from the data, subsequently training the model for each case. <\/p>\n\n\n\n<p>In each iteration, the model makes a random trading decision within the environment, receiving feedback in the form of observations, rewards, and the environment&#8217;s status. This loop continues until the trading episode is either terminated or truncated. <\/p>\n\n\n\n<p>Optionally, a visual representation of the trading scenario is rendered, providing a helpful display. After each episode, the relevant information is printed for evaluation. The concluding lines serve to clear the plot, render the complete trading environment, and exhibit the updated visualization. This procedure offers valuable insights into the model&#8217;s learning progress and performance within the simulated trading environment.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1326\" height=\"732\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-18.png\" alt=\"\" class=\"wp-image-4083\"\/><\/figure>\n\n\n\n<p>Short and Long positions are shown in red and green colors.As you see, the starting position of the environment is always 1.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-3b4611a78806c1d5553d6d3768f7d151\"><code lang=\"python\" class=\"language-python\">env_maker = lambda: gym.make('stocks-v0', df=df, frame_bound=(5,100), window_size=5)\nenv = DummyVecEnv([env_maker])<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>This sets up a reinforcement learning environment for stock trading through OpenAI Gym. The lambda function env_maker generates an instance of the &#8216;stocks-v0&#8217; environment, tailored with a DataFrame (df) for market data and specific time frame parameters. Utilizing the DummyVecEnv class, a vectorized environment is created and assigned to the variable env. Now, this environment is prepared for utilization in the training of reinforcement learning models.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-487741a522310d497140a0b470442b4a\"><code lang=\"python\" class=\"language-python\">model = A2C('MlpPolicy', env, verbose=1)\nmodel.learn(total_timesteps=1000000)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>An A2C (Advantage Actor-Critic) reinforcement learning model is implemented using the &#8216;MlpPolicy&#8217; on the previously configured stock trading environment. The model undergoes training for a total of one million time steps using the learn method. <\/p>\n\n\n\n<p>Following this, a new stock trading environment is established, featuring a modified time frame. The trained model then engages with this environment in a loop, making predictions and executing actions. The loop persists until the trading episode concludes, and details about the episode are printed. <\/p>\n\n\n\n<p>Lastly, a plot depicting the entire trading environment is generated and presented for visual assessment. This script serves as a foundational framework for training and assessing a reinforcement learning model tailored for stock trading.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-4f8dbffd49c23a78dd683d18c6e603af\"><code lang=\"python\" class=\"language-python\">env = gym.make('stocks-v0', df=df, frame_bound=(10,1100), window_size=5)\nobs = env.reset()\nobs = obs[0]\nwhile True:\n    obs = obs[np.newaxis, ...]\n    action, _states = model.predict(obs)\n    observation, reward, terminated, truncated, info = env.step(action)\n    if done:\n        print(\"info\", info)\n        break\n\nplt.figure(figsize=(15,6))\nplt.cla()\nenv.render_all()\nplt.show()\n\n<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1227\" height=\"565\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-19.png\" alt=\"\" class=\"wp-image-4084\"\/><\/figure>\n\n\n\n<p>The graph is the predicted outcomes for the given time frame, it can be compared with the graph we obtained in the start of the journey. It provides valuable insights into the model&#8217;s decision-making process and reveals the dynamics of the market throughout the specified time frame based on its learnings.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong>&nbsp;<\/h2>\n\n\n\n<p>The concept of entrusting decisions to someone based on their experiences and knowledge is undeniably intriguing. The exploration of AI, especially reinforcement learning in finance is a field that holds immense potential and hasn&#8217;t been fully tapped. There are extensive possibilities for it to evolve into something much more significant and impactful.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Implementation of Reinforcement learning in the field of stock trading to achieve better results<\/p>\n","protected":false},"author":18,"featured_media":4080,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[42,62],"tags":[],"coding-language":[30],"ready-to-go-solution":[56],"qualification":[31,32],"financial-apis-category":[36],"financial-apis-manuals":[39],"class_list":["post-4079","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stocks-data-analysis-examples","category-stocks-price-prediction-examples","coding-language-python","ready-to-go-solution-eodhd-python-financial-library","qualification-experienced","qualification-guru","financial-apis-category-stock-market-prices","financial-apis-manuals-end-of-day","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.9 (Yoast SEO v26.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Combining the Forces of AI + Python for Better Stock Trading | EODHD APIs Academy<\/title>\n<meta name=\"description\" content=\"Implementation of Reinforcement learning in the field of stock trading to achieve better results\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Combining the Forces of AI + Python for Better Stock Trading\" \/>\n<meta property=\"og:description\" content=\"Implementation of Reinforcement learning in the field of stock trading to achieve better results\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading\" \/>\n<meta property=\"og:site_name\" content=\"Financial Academy\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/eodhistoricaldata\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-01T14:36:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-05T11:49:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-15.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1125\" \/>\n\t<meta property=\"og:image:height\" content=\"750\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nikhil Adithyan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:site\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nikhil Adithyan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading\"},\"author\":{\"name\":\"Nikhil Adithyan\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402\"},\"headline\":\"Combining the Forces of AI + Python for Better Stock Trading\",\"datePublished\":\"2023-12-01T14:36:01+00:00\",\"dateModified\":\"2025-02-05T11:49:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading\"},\"wordCount\":1248,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-15.png\",\"articleSection\":[\"Stocks Data Analysis Examples\",\"Stocks Price Predictions Examples\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading\",\"name\":\"Combining the Forces of AI + Python for Better Stock Trading | EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-15.png\",\"datePublished\":\"2023-12-01T14:36:01+00:00\",\"dateModified\":\"2025-02-05T11:49:51+00:00\",\"description\":\"Implementation of Reinforcement learning in the field of stock trading to achieve better results\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#primaryimage\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-15.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-15.png\",\"width\":1125,\"height\":750,\"caption\":\"Combining the forces of AI + Python for Better Stock Trading\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Combining the Forces of AI + Python for Better Stock Trading\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"name\":\"Financial APIs Academy | EODHD\",\"description\":\"Financial Stock Market Academy\",\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\",\"name\":\"EODHD (EOD Historical Data)\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"width\":159,\"height\":82,\"caption\":\"EODHD (EOD Historical Data)\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/eodhistoricaldata\",\"https:\/\/x.com\/EOD_data\",\"https:\/\/www.reddit.com\/r\/EODHistoricalData\/\",\"https:\/\/eod-historical-data.medium.com\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402\",\"name\":\"Nikhil Adithyan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g\",\"caption\":\"Nikhil Adithyan\"},\"description\":\"Founder at BacktestZone | Streamlit Student Ambassador | FinTech &amp; Quantitative Finance enthusiast\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/author\/nikhiladithyan\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Combining the Forces of AI + Python for Better Stock Trading | EODHD APIs Academy","description":"Implementation of Reinforcement learning in the field of stock trading to achieve better results","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading","og_locale":"en_US","og_type":"article","og_title":"Combining the Forces of AI + Python for Better Stock Trading","og_description":"Implementation of Reinforcement learning in the field of stock trading to achieve better results","og_url":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2023-12-01T14:36:01+00:00","article_modified_time":"2025-02-05T11:49:51+00:00","og_image":[{"width":1125,"height":750,"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-15.png","type":"image\/png"}],"author":"Nikhil Adithyan","twitter_card":"summary_large_image","twitter_creator":"@EOD_data","twitter_site":"@EOD_data","twitter_misc":{"Written by":"Nikhil Adithyan","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading"},"author":{"name":"Nikhil Adithyan","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402"},"headline":"Combining the Forces of AI + Python for Better Stock Trading","datePublished":"2023-12-01T14:36:01+00:00","dateModified":"2025-02-05T11:49:51+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading"},"wordCount":1248,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-15.png","articleSection":["Stocks Data Analysis Examples","Stocks Price Predictions Examples"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading","url":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading","name":"Combining the Forces of AI + Python for Better Stock Trading | EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-15.png","datePublished":"2023-12-01T14:36:01+00:00","dateModified":"2025-02-05T11:49:51+00:00","description":"Implementation of Reinforcement learning in the field of stock trading to achieve better results","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#primaryimage","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-15.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-15.png","width":1125,"height":750,"caption":"Combining the forces of AI + Python for Better Stock Trading"},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/combining-the-forces-of-ai-python-for-better-stock-trading#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"Combining the Forces of AI + Python for Better Stock Trading"}]},{"@type":"WebSite","@id":"https:\/\/eodhd.com\/financial-academy\/#website","url":"https:\/\/eodhd.com\/financial-academy\/","name":"Financial APIs Academy | EODHD","description":"Financial Stock Market Academy","publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/eodhd.com\/financial-academy\/#organization","name":"EODHD (EOD Historical Data)","url":"https:\/\/eodhd.com\/financial-academy\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","width":159,"height":82,"caption":"EODHD (EOD Historical Data)"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/eodhistoricaldata","https:\/\/x.com\/EOD_data","https:\/\/www.reddit.com\/r\/EODHistoricalData\/","https:\/\/eod-historical-data.medium.com\/"]},{"@type":"Person","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402","name":"Nikhil Adithyan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g","caption":"Nikhil Adithyan"},"description":"Founder at BacktestZone | Streamlit Student Ambassador | FinTech &amp; Quantitative Finance enthusiast","url":"https:\/\/eodhd.com\/financial-academy\/author\/nikhiladithyan"}]}},"jetpack_featured_media_url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image-15.png","jetpack_shortlink":"https:\/\/wp.me\/pdOdVT-13N","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/4079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/comments?post=4079"}],"version-history":[{"count":13,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/4079\/revisions"}],"predecessor-version":[{"id":6234,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/4079\/revisions\/6234"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media\/4080"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=4079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=4079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=4079"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=4079"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=4079"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=4079"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=4079"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=4079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}