Build a Bitcoin Day Trading BOT *NEW STRATEGY* in Python - 1006700

Build a Bitcoin Day Trading BOT *NEW STRATEGY* in Python - 1006700

Show Video

So, we'll start with... and then [Follow the Captions to Learn More] hello everyone I’m Ritvik Dashora and I’m back  with a new video and some new learnings in   this video we are going to make another amazing  trading strategy for our bitcoin day trading bot   just to remind you I had already made a video  on how to build a bitcoin day trading bot using   AROON oscillator technical indicator and that  bot actually generated some excess return and   had a higher sharp ratio than bitcoin you should  watch that video as well it was quite long and   it's worth watching that video for sure like you  can click on this i button to watch that video   and in this video as I already mentioned I will  be using another trading strategy now what is   this trading strategy I got a lot of comments on  YouTube and all other social medias like twitter   linkedin instagram facebook etc that I should  use engulfing as my next trading bot strategy   actually there were many more but engulfing was  the one which was mentioned the most of the times   so in this video I’m going to use a girlfriend to  make this bitcoin day trading bot and I’ll keep   on making different strategies for this for this  bot and eventually we'll come up with an amazing   strategy for the for bitcoin trading this is  another step to create a highly profitable   bitcoin day trading bot and I bet you you're  gonna love this key concept in this video the best   part is that you don't need to make an account on  binance in order to follow this video as we'll be   using paper trading simulator that we will build  ourselves so we are not spending any money today   and this gives us the liberty to take as much risk  as possible and maybe we come up with something   great so are you excited I am very much before  we start building this million dollar bitcoin   day trading bot if you're new around here on  this channel I turned you into a successful   financial programmer here I upload videos related  to trading bots using some highly valuable finance   APIs implementation of AI in finance etc etc  so if there's something you are interested in   then smash on the subscribe button and hit on the  bell icon also I offer an amazing gift to all my   subscribers I don't know it's a surprise or not  because now almost everyone knows about this gift   but yeah if you want him my new viewer then you'll  get to know about this gift in this video itself   so without spending any more time let's start so  the topics that I’ll cover today is I will briefly   talk about my last bitcoin day trading bot then  I will will get to know about the concept of   engulfing pattern we'll see what is WebSocket  client what is TA-Lib library and then I’ll   talk about our trading strategy that we are going  to use for this video which is core and satellite   investment approach if you are if you have finance  background then you would have you would know this   strategy if you don't have finance background  don't worry I’ll explain it then eventually   using everything we will create our bitcoin  day trading bot so guys this is the bitcoin   day trading bot that we created in our last video  I’ll talk about the WebSocket client and TA-Lib   very soon and then using this AROON time period  of 14 days we had created a bitcoin day trading   bot with a paper trading simulator and then  eventually we made this trading logic in which   the main concept was because the AROON oscillator  ranges from minus 100 to plus 100 so we we had   given exposure according to the AROON oscillator  number so if it's minus hundred we were short by   some amount and if it's plus hundred we were long  by some amount and this was the basic strategy if   you want to know more about this trading bot  then you should watch my last video but I will   be referring this code in this video although I’ll  explain each and everything in this video as well   but we will refer all these lines all this trading  logic in order to make our new trading bot now I   share this code with all my subscribers you'll  very soon get to know about this thing how to get   a free access of my google drive which is actually  the gift to all my subscribers the second point   is what is engulfing pattern as for investopedia  bullish engulfing pattern is a white candlestick   actually green candlestick sometimes we refer  to as black and white other time like mostly we   do refer it as red and green candlesticks so  is a green green candlestick that closes higher   than the previous days opening after opening lower  than the previous days close now if I go to the   image like this is a very good image to explain  this concept so you can see that the red candle   is being engulfed by the green candle which is  the next green candle so it represents a reverse   end trend if you know the technical analysis then  you would know that there are many indicators   that represents different things in the chart  analysis and one of them is engulfing like   bullish engulfing and bearish engulfing so  what it says is that suppose the share price   was going down like this and then we got this  pattern which is a a red candlestick and then a   green candlestick which is engulfing or covering  the entire candle I would say red candle then   in that case there is a very high possibility as  per technical analysis that the the price of the   security will start going up from this particular  point there's no guarantee for this that's why   there's I would say there's a always there  is a strategy but there's no guarantee of any   strategy so as per records and engulfing patterns  have given a very good result as especially   in emerging markets like India so that's why I  actually have got a lot of comments from India   that I should use this engulfing pattern to see  if there is some possibility to generate some   return or I would say alpha return in bitcoin  using engulfing pad so yeah this is the bullish   engulfing and the vice versa on the other hand we  have bearish engulfing in which we have a smaller   green candle and a bigger red candle which engulfs  the green candle so yeah if the share price   was going up or a price of any security was going  up like this and then we have this pattern then   there's a high possibility that it will start  going down as per the concept of engulfing so our   main focus in our trading bot is to recognize this  pattern and then create a trading logic a logic   such that we are long or short on the basis of the  type of engulfing whether it's bullish engulfing   or bearish engulfing this is the main concept of  our trading bot so next thing is what is WebSocket   client basically WebSocket client is a two-way  communication system where we don't just receive   all the information from the server but we can  also send information to that particular server   in order to execute some actions we use WebSocket  client in order to get a real-time data of any   particular security in this case a cryptocurrency  we'll be using bitcoin real-time data in this   trading bot and we'll be extracting the real-time  data through WebSocket client we can use any other   cryptocurrencies as well like dogecoin or  Litecoin or Ethereum etc. but in this case we are   considering bitcoin and similarly this TA-Lib  which is technical analysis library it is a   it is an amazing python package or I would say  the best python package for technical analysis   I have made two separate videos on WebSocket  client and TA-Lib you can click on this i button   to watch these videos because those videos were  specifically focused on the usage of WebSocket   client and tally in order to install WebSocket  client you just need to click on the link which   is in the description box and then just click here  copy this pip install web socket client and then   paste it on our platform I’m using google collab  in this video you can use any other platform such   as spider or jupyter lab or anything else but you  didn't you need to do pip install WebSocket client   in order to install it now what is pip stock sorry  what is WebSocket client as I already mentioned it   is a two-way server two-way communication system  and we will be referring to this code in order   to extract the real-time data of bitcoin from  binance and yeah as I already mentioned we are not   required to make any account on binance in order  to extract the real-time data it's absolutely   free and we don't need to do anything on binance  platform so yeah similarly for TA-Lib TA-Lib is   a library which is used for technical analysis and  it's very very difficult sometimes to install this   library in in our system that's why I specifically  made this video on TA-Lib in order to explain how   to explain in order to explain how to install this  library in different platforms such as windows   mac or google collab etc but because I’m using  google collab in this video I’m just referring to   this link which is how which is on stack overflow  which is how to install TA-Lib in google collab   and I’m just copying this and then pasting it here  for more information you should watch my video on   TA-Lib so let's dig a bit into this library so we  can see that there are different types of function   groups which are available and TA-Lib and then  in this I’m considering the pattern recognition   if you go here there are many types of pattern  recognition here like two crows three black cows   three line strike etc doji and yeah there's doji  dragonfly doji engulfing pattern so this is the   function that we are going to use in order to  make the trading strategy in this video so yeah   I have already installed the WebSocket client and  TA-Lib in my google call collab platform so our   trading strategy in this video is going to be  core and satellite investment approach and we   will use this to build our bitcoin day trading bot  what is core and satellite approach so basically   what we do is we invest some particular amount of  money into the benchmark and then we play with the   remaining amount of money and we actually we I  should say we do 80 like we do some amount of   money in passive management and the remaining  amount in active management and this is how   we try to generate some alpha so this is the  main concept is basically an investment   strategy where investors invest some amount  say 80 percent of their portfolio into indices   like S&P500 and the remaining 20 percent into  different stocks or different securities just to   follow the benchmark as much as possible and  then creating some opportunity to make alpha   return by saying alpha I’m being excess return  over benchmark so the similar strategy is going   to be used in this video as well and what  I’ll be doing here is I’ll be investing 80% of   the entire portfolio into bitcoin as soon as I  click on the run button of my trading bot and then   remaining 20% will be actively managed so how  will I use this 20 percent as I did in my   last video on bitcoin day trading bot I’ll  do the same thing here that the the core   is 80% and then 20 percent can go long or  short so if my bot suggests that it predicts   an upward trend then I will have 20% investment  in the active strategy so it will make 80 plus   20 percent to be 100% exposure of my portfolio into  bitcoin and if the outlook is negative if the bot   predicts that there is going to be a downward  trend then we will short 20 percent in the active   part of I would say management and the overall  exposure at that time will be eighty percent   minus twenty percent which is sixty percent all in  all our trading exposure on btc which is bitcoin   will range from 60 percent to 100 percent if you  are bullish we'll have the entire hundred percent   if you are bearish we'll have 60 exposure this  is the basic trading strategy for our trading bot   I’m gonna have a trade interval of one minute the  amount for this will be one thousand dollars it's   fantasy money because I’m not putting any  money right now I’ll be having a trading   simulator that we will talk about very soon and  in this video I’m considering no transaction cost   although we can update the code very easily if we  if you want to incorporate the transaction cost I   have actually made a very detailed video on making  a paper trading simulator you can watch in the you   can click on this i button to watch that video  and in that video I actually considered the trade   the transaction cost as well so just refer to that  video if you want to incorporate transaction cost   also in in order to make this trading port so the  steps that we are going to follow today is that   we will first make a socket URL using WebSocket  client and then we'll have we'll we'll make this   URL through binance I’ll tell you how to do it and  then we will provide all the required parameters   then we'll create our own paper trading simulator  platform and then after that we will be using   WebSocket client and binance platform to extract  real-time crypto data in our in this case the   real-time bitcoin data and then we'll make and  implement the trading strategy that I talked   about which is this core and satellite strategy  and then eventually we'll run the code and   get the final result and lastly we will analyze  the gains or losses it has made this is the   WebSocket streams documentation for binance and  we will be referring to this documentation to   extract the real-time bitcoin price the links  of all the websites that I have mentioned   will be in the description box so you can refer  all the links over there so let me start with   the the base URL which is this one let me copy  it and then paste it here so socket is equal to   this if I go here again let me just I should close  all these things because all these links will be   there on description box let's keep this one so  what is this okay this is my video on so yeah you   can refer to this video as well let me close this  as well yeah so the in order to make this URL we   will have to go through the base URL which  we have already pasted and then we need   ws and then stream name what is stream name  we'll see for candlesticks we will have to   refer to k line candlestick stream so yeah this  is the candlestick stream and then I’ll just copy   this and then paste it here like this the symbol  is btc usd btc usdt and then interval in this case   will be one minute now if you are a beginner in  python I don't recommend you to understand this   part like I understand how to make the socket URL  because it will be same for all the trading parts   if you if you remember I did the same thing  in order to make the bitcoin day trading bot   for my last video as well so we should like  rather than putting our efforts to understand   this part I think if we focus on how to make  this bitcoin rate rating one how to implement   the strategy that would be a better choice  so I’ll be very very quick here and then   in order to make it user friendly I will just  convert it into f string which is like this copy   and then pasting it here similarly for interval  interval is 1 m and then let's convert it into   cc and this one as interval so running the cell  socket is equal to we have our URL for the socket   perfect now the next task would be to provide all  the parameters that we will use so amount will be   1000 and I’ll have to import some libraries  as well here so import I think web socket   is not yet imported yet so  import WebSocket json and numpy   as np I think these three libraries will be  enough amount is equal to 1000 the core trade   amount will be 80% which is point eight multiplied  by one thousand and similarly the trade amount   for our alpha strategy it will be the remaining  twenty percent point two multiplied by actually   I should write it like this amount and then  amount it in the beginning core quantity will be   0 which will become 800 after the first trade  because we are investing 800 800 in our core then   so the core to trade is equal to true why  it's true because in the end sorry we have to   have our first trade so this like I’ll be making  uh if condition that if the core to trade is   if if the core to trade is true then in that case  we will buy the entire like eighty percent of   our portfolio into bitcoin if it is false then  we won't do anything so in that if condition   the end would be that go to trade is equal to  false so after that we don't buy eighty percent   of it so I’ll show you in this code the portfolio  value in the beginning is equal to zero which   will increase when we start investing in bitcoin  investment if you remember from our last video   as well investment will be the will be the list  which will track all our transactions so in the   beginning it will be plus 800 and then according  to the different engulfing patterns it will have   600 or 1000 of the trade amount so it will give  us the entire I would say order of transaction   or how our bitcoin day trading bot has invested  money into bitcoin the real time portfolio value   will be the this list will be used to get to the  actual real-time value of portfolio at that time   at that moment of time closes highs and lows I’ll  be making different lists of different closes   different highs and different lows of this one  minute interval money end is the amount of money   that is currently in my bank account like right  now I’m not using any bank account but yeah at the   beginning it is 1 000 and then eventually like in  the first trade itself because I will be investing   800 dollars and the first trade because  of the core strategy this money and will   come down to 200 and then so on so we will have  this thousand in the thousand dollars in our bank   account at times zero and then eventually  this will go up and down according to the   trades that we are making the second step is  to make our paper trading simulator I’ll be   quick in order to explain this in this video  because I’ve already mentioned it in my last   video so paper trading simulator we'll create  two functions for buy and sell in order to   simulate our buying and selling of bitcoin so  let's start with buying which is def buy and   I’ll be inputting allocated money and price as  the inputs so whenever I run this function the   quantity that will be bought will be equal to  allocated money divided by price and of course   the money end will go down after that after  buying this much amount of bitcoins money and   just to confirm you it is the bank account I would  say bank balance at that moment of time so it will   go down by quantity into price and actually we  should make all these parameters global here   so global portfolio because we'll be changing  it in this function and then another one is   money end so as our money end will go down our  portfolio should go up it will go up by quantity   now lastly we just need to investment  dot append and then allocated money   now in the first trade actually there will be  no I would say the the investment list is empty   so in that case the entire money will be appended  from the next trades actually I should add all the   last I would say transaction value so for example  in the first case I have invested 800 so the first   value in the in this investment list will be 800  and suppose in the next trade I have made a trade   of 200 in order to make the entire exposure to  be 1 000 then the investment should be 1000 so   we should add 200 plus 800 in order to have the  next one such that we track the entire total   investments of our portfolio so we'll just need  to create a basic if function here if condition   here if investment is equal to empty then then just append it and else append it and then after   that we'll have to add investment minus 1 plus is  equal to investment minus 2. simple similarly for   the sell function again it will be the same  allocated money and price global portfolio   and money end and then quantity will be equal to  allocated money divided by price money and will   be increased if we sell the portfolio because  the money will come to our bank account and then   portfolio will decrease by quantity investment append will be minus sorry minus allocated money and   then we will eventually add it as I explained  it here so this is our basic trading simulator   let's refer to the this line which is extract  information from WebSocket client as I   used this code actually I was facing some issues  on the on close thing maybe there's some bug in   their library so I’ll I’m not using this on close  here and basically I’m referring to this function   here which is presented in their documentation  so I’m using this ws is equal to WebSocket dot   socket app and this is the web the socket we  have a different socket here on open on message   on error and on close I’m just interested in on  message so if I write it like this I’ll have to   define a function called on message and if I  just go here and then copy it like this and   then paste it here if I run this and ws dot run  forever then I should have the prices of bitcoin   seconds by seconds I’ll quickly go through the  explanation of this thing because I i mentioned   this thing very in very detail in my last video  so basically we will be focusing on the value of   x if the value of x is equal to false then the  one minute interval is not close if the value of x   becomes true then in that case the that particular  candle will be close and we will considering   that candle only in order to make our strategy  so let's wait for the x value to be true so you   can see that after some time I got the value of x  equal to 2 and this will be the candle this will   be the candle that I’ll be referring to in order  to make the bitcoin day trading bot all other data   is not useful for me so I’m just focused on that  particular row so let me stop this cell here and   let's start building our trading logic I should  name this file as bitcoin trading bot engulfing   perfect so let's convert this message into json  format so json message is equal to json.loads and  

then our message secondly actually we should make  all the parameters to be global why because we'll   be changing all this parameter so I have made  it portfolio investments closes highs lows open   money and go to trade core quantity and real time  portfolio I think these are all the parameters   that I’m I’ll be referring to and because  the value of all these parameters will change   in this function will have to make it global  now in this date in this output I am actually   this there is a dictionary and then inside  this dictionary there is another dictionary and   I am only interested in this k so this is actually  going to be the relevant information for me so let   me just write it like cs which is the candlestick  to be json message and then k similarly for   in order to see if the candle is close we'll have  to refer to the value of x and then we have close   high low and open everything is here so let me  just write all this function sorry all these lists   here so candle closed is equal to cs and then x  close is equal to cs I think c yeah open and low   and high will be equal to the open will be o  low will be l and high will be h perfect now   because I’m only interested in the row in which  x value is equal to true and in that case I’ll   have to make a condition like if candle closed  which is which will be true here and just take   all the values of closes open low high etcetera  so that's why I have made some empty lists here   of for closes highs and lows so I’ll have to  append all these values to this empty list so   closes dot append close it's better to have  it in a float format and similarly for highs   highs dot append and then high lows dot append  low opens dot open and open perfect the last price   which will be considered for our transactions  will be closes and then minus ones let's   print all this thing and let's  see what do we get so closes highs   lows opens and then last price actually I  should print it in different lines perfect   let's see what happens run this cell and  then run this cell so I’ll have to wait for   the close of that particular candle  so let me just pause this video for a   moment and let's see what happens because  nothing came here and I just figured out   that I have made a mistake here so let me just  stop this thing because I have not introduced this   opens here so I’ll have to do it like this opens  and then comma an empty cell running this cell   again and then let's see if we get the data now  right in this cell and so the first output is here   so we have the closed price last close price  last high low and open for that particular candle   one minute interval and this is the last price  let's just wait for one more minute and let's see   do we get the second output as well so guys the  second output has also come and yeah so it should   work now so let me pause it now and let us delete  all this thing now and and only keep this thing   which is closest so it will keep on providing me  the the closes list for all different intervals   now let's start without trading logic if what  was that parameter I think core to trade if core to   trade is true which is like this we don't need  to write true if core to trade then buy all this   amount which is by all the amount which is 80% and  core trade amount by this code trade amount and the   price will be the last price of it and let's just  print this like that the core investment we bought   dollar the code trade amount which will be 800  all the time worth of bitcoin now this will make   our core quantity to increase so core quantity  should increase by basically the core trade   amount divided by the last price all like  quantity represents the number of bitcoins   we have bought in our core strategy  now the very important thing is   that we will have to make this as false  because we don't want to implement this   condition again and again this will be just  one time thing which will be when we start our   trading bot in the in the beginning we'll buy 800  worth of bitcoin and then after that we're just   playing with the alpha perfect so now our king  of this video the king or queen I don't know it's   that's making king or queen yeah so the the  king or queen of our video which is engulfing   is equal to TA-Lib dot let me go to this perfect  so this is exactly what I’ll have to replicate   engulfing and then pasting it here  let me check it if we are right   yeah perfect it recommends so the open in this  case will be our list of opens and highs and lows   and close now this works for the np array only  so I’ll have to convert into np arryas perfect   now the next step would be to see what is our last  engulfing value now if I go to this file actually   what it does is it provides the value of engulfing  to be minus hundred or plus hundred or zero if it   captures a bullish engulfing pattern  that it gives me plus hundred if it   if it predicts bearish engulfing then it will  give me minus hundred if none is the case   then it will give me zero and let me explain  you through yfinance or I would say yahoo   finance historical data let me pause this video  for a moment and then come back perfect so I have   actually used this yfinance library which  is which extracts data from yahoo finance from   sorry from yahoo finance for any particular  ticker it extracts historical data and I just   wanted to explain you how talib library works  here so I have pasted this here as well and then   we have got this the data for apple here and in  order to use this engulfing I pasted the same   line that we made over there and then  we can see that in the end we get this   data frame which is like this and it gives  me 0 value 100 value or minus 100 so if I   do it like this so it will give me all the  values which are 0 if I do it like this   oh sorry if I if just if I just make it like  greater than zero then it gives me dates   where the the pattern was a bullish engulfing and  if I do it like this less than zero then it gives   me up all the values which are actually bearish  engulfing so the similar thing will be happening   in our bitcoin trading bot as well and so yeah  we have to see what is the last engulfing value   which will be engulfing and then minus one now  as I mentioned in that ppt we will be having   200 dollars for also 20% of the portfolio  for our active management so the amount   will be equal to last engulfing multiply by the  trade amount for this I’ll have to go to here   multiply by trade amount divided by 100 so suppose  if the value is 100 then in that case the amount   to trade will be 100 multiplied by 200 divided by  100 which will be 200 if the value is minus 100   then the amount of trade will be minus 100 divide  multiply by 200 divided by 100 which will be   minus 200 if the value is zero then the amount  to trade will be zero so this is the basic   concept that we will use for our trading  now we'll have to see what is the   value of our portfolio value in the active  management so basically this will be a portfolio   which is right now 800 dollars actually  which is right now which consists of the core   investment and then minus core quantity multiplied  by last price now if the value of portfolio   is more than core quantity for example if we  invested the entire one thousand dollars in   in bitcoin at a a particular point of time then in  that case this portfolio value will be 1 000 minus   800 multiplied by the last price so we actually  by saying portfolio port_value actually I mean   what is the value of portfolio into the active  management now the actual trade amount has to be   amount minus port value now why is it because  if the amount is say 200 dollars in the case   of bullish engulfing we'll have to see whether  like how much amount is already invested in the   active management if it is if it is already over  there then the actual trade amount should be zero   so suppose we have the portfolio value to be equal  to 200 already like we had already invested 200 in   bitcoin which represents that we already have  one thousand dollars of investment in bitcoin   and then in that case if we get another 100  another plus 100 then this amount will become   200 amt will become 200 so we have to see  that whether we have the capability to have   another trade or not so this will be 200 if it  is already existing is 200 then the trade amount   should be zero in that case that is basically  the concept here now in case of zero engulfing   value if it is zero then the amount will be zero  but the port value will it can be something else   but we don't need to we don't want the our trading  bot to trade when the value is zero we just want   it to trade when the value is plus hundred or  minus hundred so I’ll have to make a very small   condition which is if last engulfing is equal  to zero then just keep the trade amount to be   zero and else I’m very happy with the trade amount  which we are getting over here so trade amount is   equal to trade amount now the real time portfolio  value will be equal to I would say the   money that we have in our bank account plus the  portfolio value portfolio multiply by last price   so this is the real time value for our portfolio  and it's better to print all this thing so print   the last engulfing value is last engulfing which  is this one and then recommended exposure is trade   amount which is this one if the value of engulfing  glass engulfing is equal to 0 then in that case   the trade amount will be 0 so this will become  0 in that case if it's 100 then it will be 200   if it's and actually if it's 100 then amount will  be 200 and then we'll have to see whether we have   already invested or not so we'll have to check  it if it's minus 100 then accordingly we'll have   a different value for trade amount and the real  time portfolio value is the rt portfolio value   that's it now our final trading logic will be if  trade amount is greater than zero then buy now   we are buying how much we are buying trade amount  at the price of last price and yeah I’ve written   this as well so it will write that we bought  this much amount of dollars’ worth of bitcoin   similarly if the trade amount is less than  or even equal to zero it doesn't matter if   it's equal to zero or not in that case actually I  should write it equal here as only so in in this   case if it's less than zero in this case I will  trade minus trade amount because we are selling it   and then price will be last price and similar  to that we are printing this like we sold this   much amount of trade amount because the trade  amount will be negative by the way because   we are doing this calculation here so a minus of  trade amount and then worth of bitcoin so we   will be selling at this point moment of time and  that's it so we have I think I’ve not made any   mistake here so we have written our code for the  trading bot now the only thing which is remaining   is the closing because on close is not working  properly in this python package the WebSocket   client python package so let me just do one thing  I will close it like this manually so I will run   both the cells simultaneously such that both the  transaction happen at that time so what what what   we'll be doing here is at that amount at that  moment of time we will be having some exposure to   bitcoin from 600 to 800 sorry 600 to 1000 and at  that when we stopped the trading bot at that time   we should sell all the bitcoin that we have at  that moment of time so put sell portfolio multiply   by closes minus one so this is the amount that we  need to sell and the price will be closes minus   one or last price whatever you say so let me run  this code from the beginning and let's see what   do we get do we do we get some excess return or  not I’ll have to go somewhere and then let's see   what is the outcome in hour or so so let me  pause this video and come back in some time   okay so there's some issue in buying  because it is not buying the bitcoin so   let me just pause it it should buy at this  moment of time there would be some error i think is allocated money okay I can see this so  the spelling of allocated is wrong here yes now   everything is fine now let's run this again  from here to this let's see if it if it does the   first transaction which is buying 800 worth of  bitcoin this is so great so we have done the first   investment which is score investment we bought 800  worth of bitcoin the last engulfing value was zero   so and the real-time portfolio value is one  thousand so definitely our we are currently   invested eight hundred dollars in bitcoin as soon  as we get this hundred we will be one thousand   dollars invested in bitcoin if it is minus hundred  then we will be invested six hundred dollars in   now in the bitcoin so let me just go go outside  for some time and then come back after some time   we'll see what happens with the number of  trades okay guys so I’ve come back and I   i could see there are a lot of transaction that  happened in the bot and you can see that okay so   there are many transaction that happened at this  moment of time so the first one was buying 800   worth of bitcoin and then there will be a value  of 100 or minus 100 somewhere which will be the   second transaction this is the second transaction  transaction so minus 100 it predicted a bearish   I would say pattern here so we can see that this  this price was 32 829 and then it went down a bit   so yeah it was right but at this moment of time  we would have sold 200 worth of bitcoin now at   this moment of time we will be 600 like exposed  to the bitcoin and then after some time let's   see what happened zero zero yeah we got hundred  here and the price of bitcoin at this moment of   time was eight thirty two thousand eight hundred  thirty two and the next one is thirty two thousand   eight hundred fifty two so yeah definitely and  this time also our bot has predicted a right   I would say pattern and and at this moment of time  it would have bought around 400 dollars of bitcoin   because it uh like wanted us to have a hundred  percent exposure towards bitcoin so at this point   of time we are 100 exposed to the bitcoin and we  actually made money here because of the increase   similarly after a lot of transactions like like it  was for it was run for around three hours I guess   so the ending value is fifteen dollars we made  fifteen dollars on bitcoin in that much amount of   time and then if we see money end at that we have  one thousand fifteen point six four dollars in   our bank account in the end so let's see what are  the transaction that happened which is investment   if I run this okay so there we started with  800 and then it went down to 600 and then went   up to 1000 and then 600 so there are many many  transactions that happened at this moment of time perfect this minus 15 represents our profit  because we have taken out 15 more than   invested that's why it's negative the portfolio  value should be zero yeah it is zero and let's   compare it with the benchmark which is bitcoin  if we had like bought bitcoin without having any   trading strategy there like there's  some possibility that bitcoin would have   made more money than this trading strategy but  let's see let's analyze the result because this   was the final point of our video okay so I have  I can we can see that if we had invested   all the money in bitcoin directly and have  held all the money in bitcoin without any   trading strategy we would we would have made  2.4675 percent of return in this amount of time   and our trading bot had made 1.56 percent so we  have a negative excess return here the alpha is   negative in this case but actually I’m more  focused into the sharp ratio or I would say the   risk adjusted return because if our portfolio or  our if our trading bot has reduced the risk as   well I would say by a significant amount then  having a strategy would be a better   choice so yeah our alpha is negative close to one  percent actually point nine percent so yeah so if   we in order to calculate the risk it's basically  the the standard deviation of the returns for   bitcoin it's like this for bot it should be  like this and I actually forgot to create this   list while making the bot which is real-time  portfolio value actually I had I i forgot it   all together like here I actually mentioned it  it was an empty list but I should have increased   the returns of our trading  bot in order to calculate the risk   so yeah that's a that's a small mistake from my  side I cannot calculate the risk and the sharp   ratio in this case but I’ll just uh mention it  here in the bitcoin day trading bot which I made   in my last video so we can calculate the risk  like this and the real time portfolio value   has to be like I forgot this line over there so  I forgot to append this value if you make this   trading bot just append the rt portfolio value  and the float of that value into the real-time   portfolio value list and then what you need to do  here is you just need to calculate the standard   deviation of all the risks and then in order to  calculate the sharp ratio which is basically the   risk adjusted return considering a zero percent  risk free rate which is bitcoin return divided by   bitcoin risk the sharp ratio will be like this  this was the sharp ratio that we got in our last   video and in this video there will be some  different different sharp ratio and I’m very   much confident that the the risk was I would  say the standard deviation of our bot would be   very very lower than the bitcoin I would say  actual return a standard deviation and which   should make our portfolios standard sharp ratio  to be more than the bitcoin a sharp ratio but   there's that's a that's a very small mistake from  my side but it's okay if you make this code just   just put that line in the trading bot in order  to calculate or I would say in order to analyze   the portfolio return I’m not running this code  I can't for two and a half hours or three hours   so you can just put this line for your code now  the gift to all my subscribers but before that   please mention in the comment box did you  like this approach or do did you want me to   like use any other technical indicator in future  maybe I’ll make another video covering any other   technical indicator and then eventually we'll  come up with something great after that also don't   forget to like this video and share it with your  friends and if you like my work you can tip me by   buying me just one coffee by going to this link  which is mentioned in the description box and in   the first comment you can just click on the links  if you want me to buy me a coffee in euros or usd   and just select one three or five or any number  of coffees like 100 if you like my work a lot   and then you can tip me which actually keeps  me motivated to work on my YouTube channel and   keep posting videos like this now the gift to all  my lovely subscribers is that I share my google   drive access with all my subscribers and this code  including many other codes and study materials are   saved in my google drive everything is free for  use and there is no copyright issue over there in   order to get a free access of my google drive you  just need to subscribe to my YouTube channel and   then click on the access to my google drive button  follow some steps over there and then on that   google form link just provide some basic details  and I’ll be using this email address to provide a   free access to all my lovely subscribers thank you  so much for watching this video till the end you   can click here to subscribe to my YouTube channel  and over there you can see how I use talib library   to do multiple functions and over there you can  see how I created my bitcoin trading bot in my   last video using AROON oscillator if you like  this video don't forget to hit the like button   and comment your opinion about this video and  I’ll see you in the next video thank you so much

2021-06-12 16:38

Show Video

Other news