Тёмный

Coding an Options Trading Algorithm in Python - Code Along 

TradeOptionsWithMe
Подписаться 67 тыс.
Просмотров 68 тыс.
50% 1

In this video, we're going to code an options trading algorithm inside of the QuantConnect platform using Python. Feel free to code along.
Create a Free QuantConnect Account: www.quantconne...
(This is a referral link.)
There is a minor mistake at 10:25. The VIXRank indicator is not correctly normalized. Removing all the [:-1] from the self.rank calculation fixes this. This does not affect the performance over the backtested time-frame.
Clone the Algorithm from this video here: www.quantconne...
Mentioned Videos:
How to evaluate your trading algorithms: • Evaluating Trading Str...
Coding a stock trading bot in Python: • How to Code a Trading ...
Algorithmic Trading Playlist: • Algorithmic Trading
My Favorite Broker: tradeoptionswi...
Follow us on:
Facebook: / tradeoptionswithme
Twitter: / louis_options
Pinterest: / louistradeoptionswithme
Instagram: / tradeoptionswithme

Опубликовано:

 

30 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 93   
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
If you want to learn algorithmic trading, check out this free course that I created here on RU-vid: ru-vid.com/group/PLtqRgJ_TIq8Y6YG8G-ETIFW_36mvxMLad
@mikealfandre
@mikealfandre 3 года назад
This video was awesome. I would definitely be interested in another more in-depth options trading algorithm
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Awesome! Thanks for the feedback.
@TradeOptionsWithMe
@TradeOptionsWithMe 4 года назад
Create a Free QuantConnect Account here: www.quantconnect.com/?ref=towm
@leu2304
@leu2304 4 года назад
Man you channel is a pure gold! Thank you so much!
@mike12nv
@mike12nv 3 года назад
This is great stuff. Would you be able to create one for selling puts?
@SamS-yn7ff
@SamS-yn7ff 3 года назад
Amazing tutorial. Thank you for creating and sharing. Looking forward for tutorial on multi-leg option strategy.
@7Forest7
@7Forest7 3 года назад
Ditto
@abhinasneupane2392
@abhinasneupane2392 3 года назад
Wow amazing video, being waiting for this type of content forever. Is it possible to make video of selling options? Ty in advance
@danube466
@danube466 Год назад
I would love to see a multi leg option strategy..But perhaps also selling VOL option spreads in HIGH IV environments.
@tudatostrader
@tudatostrader Год назад
Insanely good video. Please continue.
@jiaminzhu406
@jiaminzhu406 4 года назад
Wow. Is there a way to let it place live order in my broker (interactive broker)? I want to try it first to execute my exit strategy, namely calculating price and placing limit order to take profit. I always want to use code to manage my exits.
@TradeOptionsWithMe
@TradeOptionsWithMe 4 года назад
Yes, QuantConnect also allows you to trade through interactive brokers. After you are finished developing and backtesting your algorithm, you can click on “live trading”. Then you have to link your IB account (or other supported broker account). But make sure to first extensively test your algorithm and start small if you are new to this. Getting to know the QuantConnect API can take some time.
@jiaminzhu406
@jiaminzhu406 4 года назад
@@TradeOptionsWithMe Cool. I have just opened up an account. I would prefer a different approach. I would just first use the API to get the portfolio data and submit live orders that close the position when certain conditions are met. I assume once the account is connected to Interactive Broker, the API can get the data of my portfolio (cash balance, positions etc), right?
@TradeOptionsWithMe
@TradeOptionsWithMe 4 года назад
Yes, besides the available data on QuantConnect, the API also allows you to request portfolio data from a connected account.
@markopollo2868
@markopollo2868 3 года назад
One strategy to explore could be an equity trend following strategy with an options overlay. The trend following protects against a protracted bear market (2008) while the options component protects against a short snap like COVID. Would be even better if it had another target like TLT to “rebalance” with like a 60/40 portfolio - potentially converting options windfalls into equity and treasury “rebalance” purchases.
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Thanks for the suggestion. I'll keep this in mind for future videos.
@wenceslasletexier1126
@wenceslasletexier1126 3 года назад
Hi, your video is very good. Is it possible one day you'll code an algo for crypto using python? Thank you very much for this lesson!
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Yes definitely! I am currently working on a complete algorithmic trading video course series. In it, I will also cover crypto trading. You can check it out under my Playlists. I’ll add more videos about every 2 weeks.
@NdudePYTC
@NdudePYTC 2 года назад
Hi Louis! I tried cloning your algo on quant connect, but it does not work anymore. Are you planning on updating this algo? Thanks!
@TradeOptionsWithMe
@TradeOptionsWithMe 2 года назад
You have to remove the CBOE import statement. Somehow it doesn’t work anymore if you leave that import statement. Let me know if you still have any problems after this.
@SaarimTheDream
@SaarimTheDream 2 года назад
@@TradeOptionsWithMe Now that VIX is no longer. What would you suggest using. I tried to swaping in VXX and VXZ they both didnt work.
@willberger96
@willberger96 2 года назад
Thank you Lois! So helpful! Would love for you to do more options trading strategies.
@willberger96
@willberger96 2 года назад
Louis, thanks for another great lesson! Your videos are the best!
@ciherraiz
@ciherraiz 3 года назад
Thanks for options trading videos. Is self.OTM variable a approach for delta greek value?
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Yeah kind of. You can also access the Greeks directly, however, currently QC does not support the Greeks when using the OptionChainProvider, so you would have to subscribe to a lot more data which would lead to a much less efficient algorithm.
@mislavsagovac2003
@mislavsagovac2003 3 года назад
Is self.contract.ID.Date same as self.contract.Expiry.date or self.contract.Expiry?
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Thanks for the question. This might vary from the context but in this video self.contract is an options symbol object and for that you can't use .Expiry since this is not a valid attribute of such an object.
@fancynaij2945
@fancynaij2945 3 года назад
Great tutorial. I would like to build an options strategy that selects strike prices using greeks. What would be an efficient way to do so?
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Thanks. Currently, the best way I know is to set an option filter in the initialize method, and then iterate through option chain objects in the OnData or trade method. You also have to set a pricing model in the initialize method. For an example of a short iron condor strategy that uses Greeks for strike selection, you could check out this algorithm: www.quantconnect.com/terminal/processCache/?request=embedded_backtest_09c31d03871eb85947719f228da256d4.html&?ref=towm (it isn't very well polished though) Note that this still isn't very efficient since options data is still minutely and it has to make a huge number of calculations. But I hope this helps.
@fancynaij2945
@fancynaij2945 3 года назад
@@TradeOptionsWithMe Thanks!
@xnoxgene7997
@xnoxgene7997 2 года назад
May I ask why the return is 53.86% which means net profit should be ~54k but it showed only 17.56k?
@EHoser1
@EHoser1 Год назад
Good video, thanks. There seems to be many ways to trade options at QC. Yours seems most efficient. The examples I've seen there are nothing like this. Plus it took me about a day and a half to find the Liquidate method. All of their examples seem to only open option positions and never close them. I tried selling long options or buying short ones back but they remain open and get assigned. Is there any way to find out when their options data starts for a given underlying?
@justinong4521
@justinong4521 9 месяцев назад
at 14:00 you mention that we return the BuyPut function because it takes a whole iteration for the algorithm to process the data. Does this mean that if for example today, the volatility crosses the predetermined threshold, we only buy the put contracts tomorrow?
@dominikhavel2674
@dominikhavel2674 3 года назад
hello my script doesn't work. It says this: Algorithm.Initialize() Error: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ./cache/algorithm/main.pyc. AlgorithmPythonWrapper(): ModuleNotFoundError : No module named 'QuantConnect.Data.Custom.CBOE'; 'QuantConnect.Data.Custom' is not a package at from QuantConnect.Data.Custom.CBOE import * Could they change the module name or something? I read the documentation and it also says the path is QuantConnect.Data.Custom.CBOE
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
You should b able to just remove that import statement and then it should work. Let me know if it doesn’t.
@dominikhavel2674
@dominikhavel2674 3 года назад
@@TradeOptionsWithMe It does! Thanks
@accountantguy2
@accountantguy2 7 месяцев назад
This video was excellent! You said to let you know if we would like to see a more advanced options trading video with multiple legs. That would be awesome!
@domenicobezuidenhout1587
@domenicobezuidenhout1587 3 года назад
For some reason when I run your copied code it will not leave the analyzing stage, otherwise fantastic and informative thank you! subbed
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Sometimes it gets hung up. Have you tried reloading the page?
@domenicobezuidenhout1587
@domenicobezuidenhout1587 3 года назад
@@TradeOptionsWithMe thank you for your fast response!! It’s ok Jared informed me it was an outage. Thanks!
@SamS-yn7ff
@SamS-yn7ff Год назад
Thank you for great lesson. Still waiting and looking forward for tutorial on multi-leg option strategy. May I request for it again?
@JonT-cw3co
@JonT-cw3co Год назад
Does OptionChainProvider now support greeks?
@flochforster22
@flochforster22 3 года назад
Hello! I wanted to ask why you got one option contract for every 90 shares of the underlying. I thought one option contract covers 100 shares
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Yes, that’s true. But you can vary the ratio depending on how aggressive you want your hedge to be.
@flochforster22
@flochforster22 3 года назад
@@TradeOptionsWithMe So the lower the option_alloc parameter is, the more extra options I'm buying which means I'm hedged to a larger extent at the cost of the extra premium? Thank you for your quick response.
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Yes, that’s correct
@oyepublic7293
@oyepublic7293 Год назад
grt work brother
@Dean-zi5bj
@Dean-zi5bj Год назад
Thank you bro
@willspeight610
@willspeight610 3 года назад
Hello quick question does this take in yo account the PDT rule
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Great question. This algorithm does not take the PDT rule into account. So if you have less than $25’000, you should adjust the algorithm.
@abhinasneupane2392
@abhinasneupane2392 3 года назад
I believe Pdt rule only apples to stock but not derivatives ( options) . That being you can buy and sell as many options as possible in single day without violating pdt rule even if you have less than 25k . Not an financial advice , plz do you own research.
@tb795
@tb795 2 года назад
I like your videos a lot. But the code in this one does not compile for me. I get the following error: "No module named QuantConnect.Data.Custom.CBOE"
@mananparmar9676
@mananparmar9676 Год назад
hey can you please give me your mail id?
@Themoneygurus
@Themoneygurus 3 года назад
This is great thanks, I have a quick question, my quant connect is completely unresponsive on backtest requests. It just doesn't let me push the button, have I done something wrong?
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Have you tried reloading the page?
@rgmmelo
@rgmmelo 3 года назад
Nice job! Your videos are helping me more than the Boot Camp lessons. If you allow me I have a question about which solution I didn't find in the documentation. Sometimes you use Action() in the code block on Schedule Events sometimes you don't use it. What is the difference?
@chrisl4211
@chrisl4211 2 года назад
No module named 'QuantConnect.Data.Custom.CBOE'?
@TradeOptionsWithMe
@TradeOptionsWithMe 2 года назад
Just remove that import statement
@braymo1911
@braymo1911 3 года назад
Idk if this is a dumb question or not, but when you set the cash to 100,000, would I have to change it to whatever amount I actually have?
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
You only set the cash balance for backtesting purposes. When you deploy it with real money, the algorithm will just fetch your actual account balance from your broker account.
@garrisonwhipple1289
@garrisonwhipple1289 3 года назад
you gave the wrong video link on the quant connect bootcamp video for this
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Thanks for the comment. I just checked and couldn’t find the mistake, could you please tell me which wrong link on which lesson you are referring to?
@suppeeps5393
@suppeeps5393 3 года назад
I need this for my cryptocurrency
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
QuantConnect also supports Cryptocurrencies, so you could also create a trading algorithm for Cryptos. If the demand is high enough, I can create an example Cryptocurrency trading bot.
@georgemavimbela
@georgemavimbela 3 года назад
@@TradeOptionsWithMe an example will be great
@suppeeps5393
@suppeeps5393 3 года назад
Yes I would love to know how
@monsourdarius8304
@monsourdarius8304 3 года назад
Do you think large cap US stocks have much more algorithmic trading and are manipulated more than small cap? Or since they are much more expensive professional firms would have a harder time using algos for these stocks
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Thanks for the comment. I 100% believe that large cap stocks are traded much more by algorithmic traders than small cap stocks. I’d say there is one main reason for this, namely liquidity. Large cap stocks are much more liquid and thus easier trade-able than small cap stocks. Try executing a 100000 share order on a small cap stock without significantly impacting the market. Furthermore, there is much more data available for larger, liquid stocks.
@taiyidffd5024
@taiyidffd5024 2 года назад
I made my own trading robot and tested it on old data and found that it was 80% effective, but when I tried it on real data, I noticed that it was not working, I don’t know why, even though I use a good server with a fast speed
@TradeOptionsWithMe
@TradeOptionsWithMe 2 года назад
Thanks for the comment. Note that there is a huge difference between historical results and actual real-life results. These differences can be due to biases, errors, market changes and much more. I have two videos going over some of the potential problems when it comes to analyzing backtest results that you can check out here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-VmD2fUt8KYY.html ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-oFvYbfDOJ5c.html (this one is part of my free algo trading course) I recommend using QuantConnect since they allow you to create, backtest, and host your algos in one place: www.quantconnect.com/?ref=towm In my course, you also learn how to create algorithms using Python and their platform.
@mananparmar9676
@mananparmar9676 Год назад
hey can you please give me your mail id?
@amuzatadebayo9657
@amuzatadebayo9657 3 года назад
You are doing great. Great Video. God bless you
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Thanks!
@popitphonefidget7269
@popitphonefidget7269 3 года назад
I'm new to coding. Can this be used to trade options? After 4 hours I figured out the code. Thanks in advance
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
Thanks for the comment. Yes, this can be used to trade options. If you’re new to coding, don’t worry if this seems very complicated. I’d recommend starting off by learning a coding language such as Python before trying to write your own algorithms. Doing so will definitely cut down the time it takes to understand an algorithm such as this one.
@popitphonefidget7269
@popitphonefidget7269 3 года назад
@@TradeOptionsWithMe Amazing! Thank you for the fast response. I ran you code a few times with different times and it is inconceivable👍My problem was that due to my inexperience I don't know how I can connect a trading platform to use this code. This could be just a dumb question but I couldn't figure it out. I'm sure to check out your other content on this matter.
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
In the top right, next to the backtest button, you can click on “Go Live”. This allows you to connect your code directly to one of the supported broker platforms. But since doing so requires a server to be up and running on a constant basis, live trading comes with a monthly price.
@popitphonefidget7269
@popitphonefidget7269 3 года назад
@@TradeOptionsWithMe Thanks! What kinds of stock I should run this with? Do you have any recommendations? Have you ran this bot yourself? What kinds of results did you get? And also do you have a estimate price on running this bot. I started investing a month back so I apologize for the storm of messages. I have a few good investments but since Im still quite young my money is limited. if I start running this code with 100€ what kind of results can I expect?
@TradeOptionsWithMe
@TradeOptionsWithMe 3 года назад
No, I have not put any actual money into this bot and I wouldn’t recommend doing so. The point of this video is to show you how to get started with algorithmic trading. It’s not to show you a good bot to invest in. If you’re new to investing, I’d recommend starting very slowly and focusing on learning as much as you can before risking any significant amount. As for expectations, you could check out the following article that I recently published on my site: tradeoptionswithme.com/setting-investment-goals/
Далее
Top 3 Options Trading Strategies for Small Accounts
17:34
ТАРАКАН
00:38
Просмотров 1,3 млн
10 Algorithmic Trading Mistakes to Avoid!
14:32
Просмотров 63 тыс.
Python Options Trading Bot Interactive Brokers
26:51
Просмотров 21 тыс.
Algorithmic Trading Using Python #4 - Handling Data
18:02
Automated Options Trading Bot in Python
42:55
Просмотров 33 тыс.
Compiled Python is FAST
12:57
Просмотров 111 тыс.
What is Algorithmic Trading & How to Get Started
15:56
Просмотров 546 тыс.
How To Build A Trading Bot In Python
18:46
Просмотров 775 тыс.