ChatGPT Trading bot in Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this video was brought to you by chainmetrix.com your provider of Bitcoin on chain data on this website you can find 200 plus on chain metrics for example the number of addresses with 100 plus Bitcoins please find 20 discount promo code and Link in the description below and welcome to my YouTube channel today I'm going to show you how to use chargpt to build your own trading board in Python we are going to use backtrader.pui Library which will help us to build the bot that's a quite famous library for the python to do the back testing of your trading strategies and also to do live Trading first of all let's ask a chatbot if she knows about back trade do you know what is that trader.py yes and as we can see she knows about this framework she knows that it's open source back testing and trading framework for the python which is awesome right so now let's try to get some trading strategy right could you please create trainings strategy in Python by using back trader dot pi to trade apples stock based on um five years historical data let's see what will be the answer sure here's an example of simple trading strategy implemented in Python using back trader library to trade Apple stock based in five years historical data okay so we're getting SMA period 20 I think it's quite uh very very simple moving average strategy but let's see maybe that's the one we need right maybe that's the the profitable one anyway so the the the the the the main thing is that we're getting the code and we can we can keep improving it I see the first Improvement which we need to do straight away is to change the Yahoo finance data source because that's uh data source was depreciated and it's not available right now and probably open AI doesn't know about it because it was disconnected from the internet in 2021 but let's see um your Finance is not available anymore do you have other options for historical data source for Apple stock let's see oh you see that she knows that Yahoo finance is no longer available but she's still providing it right um okay so and she's providing some other options where we can get a financial historical data which is Alpha Vantage condo and IEX Cloud thread I I know the quando it's quite popular source of the data so let's let's ask to change the code could you please change the data source to candle and and that's it right that should be enough for now is a good option for historical thank you very much but why you're not using it uh from the beginning right why we should ask okay to use quandal back trader you'll need to install quandal Library okay we can do it later right but as of now that's the code we're getting mactrader data time import quando so we need to have API key but I think we can generate it I'll show you how to do that but let's see right so it's it's very simple uh trading strategy it's just using of uh 20 SMA and as soon as we're crossing it um up then we are buying a lot of stock and when we are crossing this SMA down then we are we are selling the stock it's very simple strategy but that's not the quite a big profitability is not our Target to the first Target for for today right we just want to see how we can uh build how we can build the strategies okay so as of now I see that we can use that we are getting uh the code okay which is okay now we need to have API key we need API key to get the external historical data from quando right so quando should know who we are so we should authorize before grabbing the data from quando so let's see how we can get that so let's go to search for Quando and what we see is that quando is recently was acquired by NASDAQ and now it's that uh nasdaq.com okay so which is fine for us right as soon as it will provide us the historical data with and so let's try uh we need to sign up and we just putting our first name let's put uh GPT master right and then personal account then we putting our the master uh at gmail.com email then we put our um the country and why we want to use like for saying I'm not sure right and yeah let's go next and we are confirming that we are not robot we're confirming privacy policy and create account and let's wait let's see awesome as a result you should get your API key straight away you copy it here and you can use it for uh for your strategy later on okay now we have everything now we need to uh to run this code let's do it run our code we will use Visual Studio code ID if you don't have it just go to the Microsoft website or just press VC code in your Google browser and you will get the first link visual studio called code.visualstudio.com that's what you need to go in here downloading and that's your IDE that's the kind of notepad way you can type your your code and run it run it there I already have it so um uh I just created the empty folder and let's create just empty file let's call it main.pi you can call it whatever you like just end it with the dot Pi just to let Visual Studio understand that that's the Pi Pi python script and here we are that's the our editor so let's go to our uh let's get our uh trading strategy copied going here paste it then we're going to the our financial uh data source which is NASDAQ we've copying our API key going back in code we have this quondal API config API key which is removing uh it and posting what we have okay now our code is ready to be run but let me show you how to do it in a easier and nicer way so you see now we can just run the python script but let me show you how you do it properly going to the extension uh and you're typing here Python and you're getting python extension just press install and just wait a bit and you will get all required things to run your code easily you see now you have this play button in your Visual Studio which is very easy so you're typing your code and you just press the play button okay let's press the play button what we're getting we're getting that uh back trade uh library is not available right okay so we need to install it but before installing I would create probably the um virtual environment which is a good way of doing things you're creating your virtual environment so whatever python libraries you're installing it will be located in one place you're not installing it for everyone for all the projects so you're just deploying it for your own project uh python free VNV and that's use chat GPT EnV kind of environment and here we are we have uh environments so so let's see um to activate the environment we can just press not press but time being activated so now we have our environment we can see what kind of extensions do we have you can type pipe freeze and you see that you don't have any extensions deployed yet so what we see with we need uh back trader so we'll be uh pip install bug Trader the trader you see um now we have back trader installed um and they're suggesting us to update the people as well okay let's do that uh people install upgrade okay now everything should be working fine you need to change The Interpreter for the python right because we created in Virtual environment inside the version environment we have our own python but this play button currently executing like the the over like the general python which is installed in the computer so let's just change the path we're just going here and typing like this uh chart character and then we're just changing it to the this interpreter to the one which is in in inside of the virtual environment right and uh now should be should be fine for from the back trader perspective so back trader is okay now it's saying that quandal is not available be install Commando now we have quondal installed almost okay done now let's play again and let's see what will be the result strategy working fine but we need to add some visuals right we need some um chart and how it's progressing and what's the profitability of the trade let's go and ask uh charge APD assistant to add this into the python code please and the lighting of the strategy results police also add um broker position uh before and after the trade things strategy run and add initial cash position to thousand USD Okay so we should get the updated code now uh let's see that nothing else changed so we are importing back trader data time condo our strategy API key is still the same we could provide our API key right and then the code will be updated but we can change it by ourselves um so we're still using the same one SMA 20 period broker cash Set uh 1000 we are getting data from quondal and uh we are Let's see we should add something okay now we have this extra output which is will show the our starting position and uh at the end we'll show the final portfolio position okay now some explanation which we don't really need uh let's try and copy this updated code we'll go to visual studio we'll um I think I'll post it here now we need to update our API key again the copy it here going back to visual studio copy and paste API key let's see the rest should be okay and let's try to execute let's see now we have some results but we have one more exception it's Matlab Library missed okay doing it again BP install not leave done it should be fine now so let's do the final run and here we are that's our result and surprise surprise we have some profit which is almost 50 percent profitability as you remember we had thousand dollars in the beginning and we have 1574 dollars at the end which is almost 50 profitability which is amazing in my perspective I didn't expect that charging PT will manage to do any profitable strategies but here we have like 50 which is probably not the pass which we expected it's not thousand dollars but still now if you want to use this strategy is our live trading board we need to connect it with our own broker account to do that we can use the backtrader.py documentation we can go to the the website which is back trader.com and we can see uh we can go to the documentation and here we can find live trading options we can try we can connect it with the Interactive Broker or or on the so you can try to change the code by yourself or you can leave in the comment section that you are interested about that and I can make a separate video of how to make a live trading bot based on the trading strategy which was created today uh but for now I think we've done our task we saw that uh child GPT can generate trading strategy in the python uh using the backtrader.py library and showed profitability which is amazing and I think that's it for for this video thank you very much for your attention hit the like if the video was useful for you subscribe to the channel and see you in the next video thank you foreign
Info
Channel: QuantTrader
Views: 20,503
Rating: undefined out of 5
Keywords: chatgpt, chat gpt, openai, trading bot, trading strategy, python, backtesting, trading, chatgpt trading bot, chat gpt trading bot, chat gpt trading, chatgpt trading
Id: -1B2cxSjeGw
Channel Id: undefined
Length: 15min 59sec (959 seconds)
Published: Sat Jan 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.