Live Algorithmic Trading using Python | A Live Trade Demo on Interactive Brokers Platform

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone um thank you for watching this video in this video i'm going to demonstrate step by step how to do live algorithmic trading using python through interactive brokers and the concentrating tool package here's the agenda of this video first we are going to set up the environment for both interactive brokers or ib and concentrating 2 or qt2 both are free and easy to install next we will write an event driven strategy in python and configure it for live trade then we are ready to do live trading this step includes live monitoring logging and tick data recording three components that are very important to algo trading um but before we start name it slowly needs disclaimer basically it says use it at your own risk because it actually trades do not use real money unless you know what you are doing okay now let's get started first step let's set up the trading environment ivy offers free trial accounts just google interactive brokers free trial and follow the sign up process ib also offers unconditional free paper trading accounts conditional on that you have a real money account in this video i'm using the paper trading account now when you log into ib tws or the trader workstation you will see something like this your window might not look exactly like mine and don't worry because we are going to focus on only three windows here the nvpo code window here in the middle left and order in the trace window at the bottom left if you don't have them just go to the menu on file new window quote details that's the code window and all the management orders in the trace now to turn on the api just go here file global configuration apis settings and turn on the enable activex and socketed clients and toggle off the read-only api because we are going to place some orders last but not least um make sure that on top right here there's this line highlighted in red saying that this is not the real money account that's it for ib now to install qt2 i already published it on paper so simply open a command window and type in pip install code trading 2 or lower cases this will install the package then go to github web page in the examples folder we're going to download some files the first is the live engine wpy just click it click the low button right click save as and remove the txt extension and save it on your local drive we'll do the same for we will download the config live dot example and the instrument mantle a meta dot yammer and two sample strategies in the strategy folder after that your local drive should look something like this three files here and the two files in the strategy folder and we are done with the setup um let's move on to coding sample strategies with a favorite python editor here i'm using the jetbrain pycharm the first strategy is called order per interval strategy it is the simplest strategy i can come up with yes it had all the basic elements to be quantified as an event driven strategy eventually roughly speaking means every price transaction or marketing use is an event and your strategy reacts to it according to some rules here on tick function reacts to the tick data in the places market orders every antics defined by the tick trigger threshold once it accumulates enough text it will place the order and the set ticks back to zero to restart accounting there are a couple of ways to define an interval the first and most intuitive one is the tick bar for example the one minute bar you have one by nine thirty uh the next one at nine thirty one and so on uh the other choice is tick bar the logic behind is to treat uh one tick as one piece of information and one bar contains the same amount of information therefore you will have more bars during the market open in the market close while less bars during lunch time here i use the tick bar it's easy to switch the to the time bar by checking the timestamps one night i want to point out here is the print statement it prints out what this strategy sees so every time the pre this print shows up it means the strategy sees this tick data and reacts on it please remember this because we are going to inspect it in live trading the other important thing is logger it records important messages we want to know when we replay the market here i record tick number which is expected to be the tick threshold and the last trade price which is expected to be close to the market order fuel price just briefly go through the other um the other strategy called moving average course it is a classic strategy that uses an expression moving average when it buys when price crosses moving average from below and shorts it with crosses from above i'm not going into the details it demonstrates the use of limited order and the importance of logging for example to trace all the corner cases i want to also quickly show you the config.yaml file it controls all the strategies parameters here i set the initial state to force or not active so it's not going to trade right away until you turn it on manually and we will see how to do it in live trade and i've also set the tick mark threshold to 100 the symbol is e-mini futures because it trades out after hours the config file is a very simple here but you will appreciate it more after you have a dozen of strategies and each has a dozen of parameters now we are ready to live trade and generate some pnl's this can be either an agreeable or frustrating experience depending on what color you see on your pianos to live trade open a command window and type in python live engine wpy it will connect automatically to the broker and pop up this control panel it consists of two parts on top it has start strategy stop strategy and some other buttons and at the bottom a group of tabbed windows such as strategy window all the window etc look at the strategy window we have two strategies strategy one is the moving average and the strategy two is the tick interval they are both inactive right now and if you recall it's because we set active to force in the config file if this is the first time you use qd2 it's a good idea to do some sanity check to ensure that the system is properly set up imagine this tws window is what uses and this control window is what the algo sees the purpose of sanity check is to make sure these two windows are in sync record that in the strategy we added a print statement to later strategy print out what it sees let's select the order um interval strategy and click the start strategy button and it should immediately speed up the tick data like here to do the check drag the command window side by side with the nbo code window and compare what you see in the code window and whether the strategy sees in a prenup then we unlock the tdis and drag the code window in the middle and set the for example the bit size 22 23 26 and 8 as you can see they change order field they change together if this is also what uh the case for you congratulations your system is properly set up now it is the time to just sit back and let the computer trade for you to monitor if the angles are doing the right thing recorded our tick interval strategy sends out market order when it accumulates every 100 ticks so let's wait for it to reach 100 and watch if it actually sends out an order or not here we have 94 99 100. order filled and ordered let's say now that's this order here and you can actually see in the control panel that's this order short one node and the cell er eu mini and we traded at six o'clock 601 and that's this field order order failed oh actually we have another order it's a 602 and this is 602 here i will stop monitoring because this is a rather simple strategy and i want to show you something important uh they are the log files in the log folder and tick five in a tick folder while the computers trade for you it simultaneously records the logs and the tick data autofilled in a log file you can check the market conditions for example if you search the order by interval here you will see that if the order is placed at the tick um 101 and the price is 34.71 the dick file records market data for example here is the yes futures you see the bridge size is 46 loads 46 north and down to 8 nodes suggesting less interest from other side so more so more likely the price will move down if this was a tape this used to be known as tape reading i also noticed some people asking for injured data to do practice well here you have it auto failed and i would argue that this is probably better in some sense than buying from data vendors because it may not be the most accurate one but it's more pertinent to you because it is what your strategies actually observe or receive under your trading constraints after all not everyone collocates her strategies with direct market access that's all for this video to sum up in this video we set up the trading environment wrote a trading strategy and a live trade needs strategy we actually spend more time on setting up the environment and writing strategy then monitoring the live trade this is like the movie industry you write a script shoot a movie and by the time it hits the screen your work is pretty much down the next step for you is to write your own strategy and back test it before live training i hope you find this video useful to help you get started please feel free to leave your comments or suggestions below if you like this video please give it a thumbs up thank you very much for watching see you next time
Info
Channel: Letian Wang
Views: 9,062
Rating: 4.9337015 out of 5
Keywords: algorithmic trading, quantitative trading, trading strategies, trading system, automatic trading, trading platform, quantitative research, python, python for finance, python for trading, how to, trading bots, interactive brokers
Id: CrsrTxqiXNY
Channel Id: undefined
Length: 15min 31sec (931 seconds)
Published: Sat Aug 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.