Backtesting Rayner Teos 1689% Bollinger Bands Trading Strategy in Python [Part I]

  Рет қаралды 57,789

Algovibes

Algovibes

Күн бұрын

Пікірлер: 141
@OneIdeaTooMany
@OneIdeaTooMany 2 жыл бұрын
I have to say that I'm more interested in the python coding than whether this strategy works. I've written bots for metatrader, indicators for trading view and write python/C++ for work but I do like the way you structure your code. very straightforward. thanks for sharing!
@Algovibes
@Algovibes 2 жыл бұрын
Same for me! Appreciate your comment man :-)
@Tryndamereization
@Tryndamereization 2 жыл бұрын
Agree. Great structure of code
@Kr3m3rsVids
@Kr3m3rsVids 2 жыл бұрын
Very educational, looking forward to part 2! Thanks!
@Algovibes
@Algovibes 2 жыл бұрын
Thank you very much man. Part 2 coming this or next week!
@olivierdefosse5956
@olivierdefosse5956 2 жыл бұрын
just amazing! Above all, don't stop... I love it
@Algovibes
@Algovibes 2 жыл бұрын
Thanks Olivier, I won't stop, no worries 😄
@CryptoWizards
@CryptoWizards 2 жыл бұрын
Awesome video - am going to try this now and post a vid on my channel. Big shoutout to you.
@Algovibes
@Algovibes 2 жыл бұрын
Nice, thank you mate :-)
@walterweyers6619
@walterweyers6619 2 жыл бұрын
Waiting for part 2. Great work. Very informative!
@gmmg3220
@gmmg3220 2 жыл бұрын
Waw. Part 2 please.And again amazing episode 👏
@Algovibes
@Algovibes 2 жыл бұрын
Thank you very much :-)
@GenNextAnalyst
@GenNextAnalyst 2 жыл бұрын
very clear and structured tutorial! Thanks man!
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a lot for watching :-) Happy to read that!
@PaulanerStudios
@PaulanerStudios 2 жыл бұрын
was working on something exactly like this just a couple days ago. Just slightly different and also did a hyperparameter search to find a better parametrization for my specific strategy. Currently livetesting it.
@waynetrain8650
@waynetrain8650 2 жыл бұрын
I suggest doing Walk Forward Optimization, to not overfit, if u didn't already think about that. Would love to hear your results!
@PaulanerStudios
@PaulanerStudios 2 жыл бұрын
@@waynetrain8650 yeah already did that...
@Algovibes
@Algovibes 2 жыл бұрын
Hey man, thanks a lot for sharing. Would be quite interested in your insights as well!
@PaulanerStudios
@PaulanerStudios 2 жыл бұрын
@@Algovibes I use exponential moving averages on the lows and highs instead of simple ones. The window size on the lows and highs, aswell as the timeframe (the interval a candle represents in a chart) are really the only parameters that I searched on. For the hyperparameter search I vectorized as best as I could and threaded everything so the code is a little more extensive but quiet fast. Backtesting an entire year in 0.1s something like that. Livetesting currently on the FTX API using max volume of the last 10 orders in the orderbook as a price heuristic. This just sorta makes sure that when I'd actually close a trade at market price the heuristic would most likely underestimate that.
@SnoopFix
@SnoopFix 2 жыл бұрын
Great Video! Informative and Understandable, even for me as a C++ user. I am fairly new to Trading with bots and can't help but be annoyed by the quantity of trades in such 'deeply conditioned' strategies. Imagine only trading
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a lot for your comment man. Would love to be proficient in C++ !
@itayhilel2168
@itayhilel2168 2 жыл бұрын
Very interesting, waiting for part 2
@Algovibes
@Algovibes 2 жыл бұрын
Thanks mate, coming probably this or next week!
@agustinkashiraja401
@agustinkashiraja401 2 жыл бұрын
THAKS! FANTASTIC! WAINTING FOR BACKTESTING!
@Algovibes
@Algovibes 2 жыл бұрын
Hi man, thanks a lot for your comment. Video will probably come within the next couple of days.
@ÜmitKirenci
@ÜmitKirenci 2 жыл бұрын
Yess, new video :) 👍
@davidburcham7951
@davidburcham7951 2 жыл бұрын
Great! Now I dont have to do the Btesting on some strat ,(that I do not have much faith in) that wanna-b trader rip off from someone. I write my strats on Tradingview here in the states. I really like pinescript (user friendly) and they have a great community! This will be interesting so keep up the great work!
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a lot David!
@ordinarygg
@ordinarygg 2 жыл бұрын
Also do not include wicks in backtesting, because you just literally will miss liquidity to fill. I'm a profitable 1-year bot trader and could say, the final structure you will have: -> bots -> collecting trades system + worker who syncs order info -> dashboard API that provides aggregation about your trades including fees calculation, also balance tracking of your reinvest and withdrawals. I don't use anything that is related to chart drawing -> MarketMaker could draw any chart, so your strategy should use intra-day intra-hour intra-second, or global strategies that could survive long term on any market. You just need to realize there are a lot of players in the market and all these indicators should be used from a different angle than retail strategy does, just saying. If you automate what retail does -> you will lose in 90% of cases. Money and risk management is a key -> you could use even a 50 cent coin flip for desicion to buy or sell, results will blow your mind)
@yadsasusi3977
@yadsasusi3977 2 жыл бұрын
Hi, I am interested in algotrading, can you just provide me some resources and guidance to start learning this. It will be very helpful
@Algovibes
@Algovibes 2 жыл бұрын
​@@yadsasusi3977 you are already in the very right place! Be kindly invited to check out my stuff- in specific the Python for Finance playlist and the cryptobot playlist as well. @Yaroslav: Good inputs, thanks a lot! I agree on some points , yet disagree on some. By the way: I would also take your comment seriously without the "profitable trader" claim.
@ordinarygg
@ordinarygg 2 жыл бұрын
@@Algovibes If you are interested we can collaborate I will show you my system in some live stream or could make a video, whatever) would be helpful for your viewers. "profitable trader" agree that sounds a bit selfish)) long road to stable passive income
@akashjariwala5354
@akashjariwala5354 2 жыл бұрын
Wow... thats amazing... would you mind sharing show doc or guiding me?
@rje4242
@rje4242 2 жыл бұрын
backtesting is a great topic, worth the membership :)
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a bunch for being an Algovibes channel member! :-)
@Daniel-fv1ff
@Daniel-fv1ff 2 жыл бұрын
Great video, very interesting
@Algovibes
@Algovibes 2 жыл бұрын
Thanks mate :-)
@HarryLi
@HarryLi 2 жыл бұрын
Hi, thanks for this video and it’s informative in many ways. However I found that there is some forward looking issue in the code. E.g. 10:16 you are setting the buy price at 3% below “today” (current row)’s close price. And in reality a person can’t exactly know current day’s close price hence this buy price is not set correctly. It actually should be yesterday’s close price with a 3% reduction. And it tells us another issue of Buy signal setting. Buy signal should check today’s low against previous day’s close, instead of today’s close against previous day’s Low.
@2k10clarky
@2k10clarky 2 жыл бұрын
I've been bitten by the forward looking issue, it can make you think you have the strat to end all strats :) when in fact you have pure garbage
@Algovibes
@Algovibes 2 жыл бұрын
In general you are right, in this specific case not. At the end of day X I know that my Close is above the SMA and also the Close crosses the lower BB. If that's the case I am placing a Buy limit order on 97% of Day Xs Close price (I can do that because I am placing the order once the market closes). I am checking now if on the next day my buy limit order would have gone through. If it's going through it is being executed with 97% of the close price. There is no look ahead bias. It seems like a look-ahead bias only because I am using this information but as I don't have intraday data that's the only way to find out if the Buy limit order would have gone through. Look-ahead bias would be e.g.: I am buying (market order) when todays close is above yesterdays close and I am buying on todays close price. I cannot take today's close price as I only have the information when the market closes and need to take the next days open price instead.
@2k10clarky
@2k10clarky 2 жыл бұрын
@@Algovibes Make sense. I'll be specific my look ahead bias was using the BB from the current candle close price on a 5 min strat. Needless to say a big wick would change it and is unknowable in real time. As soon as I changed it to previous candle close all alpha was lost :-/ Would be really great if you had a discord to discuss this stuff in depth as its pretty much a lone persuit creating trading bots.
@rupindersingh1312
@rupindersingh1312 2 жыл бұрын
Awesome dude 😎
@Algovibes
@Algovibes 2 жыл бұрын
Happy that you like it man!
@ByteM3N0w
@ByteM3N0w 2 жыл бұрын
Great work!
@Algovibes
@Algovibes 2 жыл бұрын
Thanks :-)
@loryo80
@loryo80 2 жыл бұрын
Thank You for this video, very instructif ass usuel
@Algovibes
@Algovibes 2 жыл бұрын
Thanks for your feedback man, that's great to read!
@larrybird3729
@larrybird3729 2 жыл бұрын
From my experience as a quant any code that forecasts into the future can be problematic , its not when you first do it, its more when you add more code and forget about it then one day you run a back-test and this innocent snippet of code synergises into a filter that takes out all the bad trades and gives you false hope on a system that does not work, its better to simulate everything like your trading in real time that includes fees and any type of slippage or spread But thanks for sharing keep it up
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a lot Larry for sharing your thoughts. Agree with your statement btw.
@ahmetbinatlioglu8848
@ahmetbinatlioglu8848 2 жыл бұрын
Great video bro
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a lot mate
@rraul
@rraul 2 жыл бұрын
I love this content. Keep up!
@rraul
@rraul 2 жыл бұрын
I did the backtest in brazilians stocks, not profitable. But i really appreciate this video. You Motivates me to keep up learning Python. I would suggest you to make a video testing if any strategy is statistically significant or not. Steps to verify a strategy, whatever it be. Thanks
@Algovibes
@Algovibes 2 жыл бұрын
Good to know, thanks a lot for sharing rraul!
@scottphillips8117
@scottphillips8117 2 жыл бұрын
This strategy is implicily overfitted. A long only "buy the dip" strategy will work in a long running and powerful bull market, even if the strategy sucks. To know if the rules describe noise or signal you'd have to test it over a longer period including bear markets. Suggest the long running Japanese equity bear. Otherwise your backtest is a fig leaf and almost certainly forward results don't match historical. Not saying it is garbage just that a backtest on a long only strategy in a period where long only strategies have crushed tells you literally nothing about future performance.
@Algovibes
@Algovibes 2 жыл бұрын
Hi Scott, really appreciate sharing your thoughts!
@flyaway3629
@flyaway3629 2 жыл бұрын
Scott you're a true G! When it comes to BB strategies, the Holy Grail system is the way to go
@adulting_wellatleasttry3575
@adulting_wellatleasttry3575 2 жыл бұрын
Was using bits of your code trying to make a strategy and used your part to filter the dataframe for matching buys and sells, and noticed that it might be the case on some stock that first entry is sell rather than buy, so from the looks of it, it turns to a short seller rather than a buy first and sell later. Might be I miseed something.
@Algovibes
@Algovibes 2 жыл бұрын
Shouldn't happen. Can you go through it again please?
@Crazy1793
@Crazy1793 2 жыл бұрын
8:30 - 9:20(ish) are you sure it's not s forward looking biased? They way you explained it made it really seemed like it. Because you said that you check the next day closing price
@Algovibes
@Algovibes 2 жыл бұрын
It isn‘t. I am only checking if the buy limit order would have gone through. If the low is equal or below 97% of the prior close the order would have been executed so I can consider it.
@luclonjon2232
@luclonjon2232 2 жыл бұрын
Hi, great content as usual! Would such a strategy apply on crypto trading ?
@Algovibes
@Algovibes 2 жыл бұрын
Will probably test that out in the future. Stay tuned ;-)
@luclonjon2232
@luclonjon2232 2 жыл бұрын
@@Algovibes Actually I've tried implementing the indicators on BTCUSDT and ETHUSDT already (couldn't wait sry lol). But it seems like we're getting very few buying signals, where would it be coming from ? i.e. I've been trying over 2000 day / 1 day per row periodization and got 3 buying signals... I'd be glad to have your insight on this. Thx again for the content!
@theemperor1143
@theemperor1143 2 жыл бұрын
Can you explain to us how to program a strategy based on multiple time frame?
@Algovibes
@Algovibes 2 жыл бұрын
I think I covered it here: kzbin.info/www/bejne/fnOUdH-wZb9khLs or here: kzbin.info/www/bejne/rIi5i6uflsaHedU Please let me know if you are missing something. Happy to include that in future videos.
@revenge9431
@revenge9431 2 жыл бұрын
Yo whats up How did u get ur jupyter notebook dark theme? U can show?
@Algovibes
@Algovibes 2 жыл бұрын
Hi man, here you are: stackoverflow.com/questions/46510192/change-the-theme-in-jupyter-notebook ;) Thanks a lot for watching!
@revenge9431
@revenge9431 2 жыл бұрын
@@Algovibes your the man thanks!
@mr.gk5
@mr.gk5 2 жыл бұрын
Very nice please do win rate calculation in part 2
@Algovibes
@Algovibes 2 жыл бұрын
Thanks mate, I included win rate in part 2 - just released it. Let me know below the video what you think about it: kzbin.info/www/bejne/mmW6mIJ_p8esa7M
@santhoshdasari7
@santhoshdasari7 2 жыл бұрын
Thanks a lot for sharing…
@Algovibes
@Algovibes 2 жыл бұрын
Thanks for watching!
@ranunculusrouge1272
@ranunculusrouge1272 2 жыл бұрын
Hey, love your videos. Have you ever thought about writing a flash loan bot?
@Algovibes
@Algovibes 2 жыл бұрын
Thanks a lot, no not yet.
@tams5695
@tams5695 2 жыл бұрын
In which video do you explain how to download all the libraries for binance and papas? Thanks
@Algovibes
@Algovibes 2 жыл бұрын
There nothing magic about it, just install them with pip. I usually show the installation command when I first use the library. For binance e.g. that would be: kzbin.info/www/bejne/lXq5YqSciLWDras
@tams5695
@tams5695 2 жыл бұрын
@@Algovibes thanks 🤙
@Mr.Flo.Official
@Mr.Flo.Official 2 жыл бұрын
What GUI are you using for python code?
@Algovibes
@Algovibes 2 жыл бұрын
Using Jupyter Notebook here.
@Mr.Flo.Official
@Mr.Flo.Official 2 жыл бұрын
@@Algovibes thank you.
@leewsimpson1
@leewsimpson1 2 жыл бұрын
So explain again how we get to 1689% ?
@ventiladorbueno1846
@ventiladorbueno1846 2 жыл бұрын
Thank you
@Algovibes
@Algovibes 2 жыл бұрын
Thanks for watching! :-)
@riccardoronco627
@riccardoronco627 2 жыл бұрын
there is one MAJOR issue: when you calculate the LIMIT order to buy, you use AdjCloses to get your 3% limit order. That is correct. However, you compare this price with a NON ADJUSTED Low. With the passing of time, dividends will impact on closes but not on your lows. So you have to adjust the LOWS with the same FACTOR used for AdjClose. If you fail to do that, this backtest will trigger not all the trades that could have happened in reality. Attention!
@CAGB-cx4xe
@CAGB-cx4xe 2 жыл бұрын
what is your favorite indicator?
@Algovibes
@Algovibes 2 жыл бұрын
The ones that are working over long Backtesting (and Validation) periods ;-)
@goldenhany5248
@goldenhany5248 2 жыл бұрын
thanks for your video ... can i apply this in a real account ?
@Algovibes
@Algovibes 2 жыл бұрын
Well I didn't test that in the real market yet but I am planning to test that on cryptos in the upcoming weeks and probably make a video about it so stay tuned!
@EricNeilson_
@EricNeilson_ 2 жыл бұрын
I can't get the yf to download the data. I keep getting this note: - MSFT: No data found for this date range, symbol may be delisted
@EricNeilson_
@EricNeilson_ 2 жыл бұрын
every ticker.
@EricNeilson_
@EricNeilson_ 2 жыл бұрын
@@stanvanillo9831 I did search, thanks for your useless feedback
@Algovibes
@Algovibes 2 жыл бұрын
@Barney Gumble That's quite rude. Please just be kind - will bring you far in life, I guarantee! Besides that: Can you elaborate on your problem? Did you update yfinance? Did you somehow deviate from the code? Does it also happen when you are pulling a single stock?
@arpanmaji
@arpanmaji 2 жыл бұрын
"Import ta" How get that module?
@Algovibes
@Algovibes 2 жыл бұрын
pip install ta
@sasuke1234ization
@sasuke1234ization 2 жыл бұрын
would love to see the same method but on binance.
@Algovibes
@Algovibes 2 жыл бұрын
Thx for your suggestion!
@sweealamak628
@sweealamak628 2 жыл бұрын
I've got my own algo ready but in excel format. Was wondering whether to code a recognised pattern as a class with functions to calculate a successful buy/sell indication but it turns out it is more straightforward just adding a new column directly to the pandas dataframe. I come from old school C++ programming, python pandas is truly amazing. Awesome coding! 👍
@Algovibes
@Algovibes 2 жыл бұрын
Hey man, that's awesome. C++ knowledge is an asset! Appreciate your comment. And yes you can do both: Doing a vectorized approach or use a simple loop logic. Both is fine. Got using loops in my older videos as well if you are interested in that.
@sweealamak628
@sweealamak628 2 жыл бұрын
@@Algovibes Thanks for replying. I suppose looping has been the traditional way of repeating the same function on different input variables but that is single threaded limited by CPU speed. Your vector method is so much faster taking advantage of multithreading! I'm slowly pouring through your vids now 👍
@freddurst4420
@freddurst4420 2 жыл бұрын
it doesn't seem like this strat will make the return as claimed, but not sure of back testing params
@Algovibes
@Algovibes 2 жыл бұрын
Let's see in the next part! ;-)
@shinderaju123
@shinderaju123 2 жыл бұрын
I want to learn Python and want to create my own strategy with BB and RSI
@gglendormi
@gglendormi 2 жыл бұрын
What is adjusted close ?
@Algovibes
@Algovibes 2 жыл бұрын
I think I explained that in one of my age old vids: kzbin.info/www/bejne/bKLFhX6qg6ibapo Pls check that out and let me know if that is clarifying!
@billychan4788
@billychan4788 2 жыл бұрын
is it legal to use it on the real market?
@Algovibes
@Algovibes 2 жыл бұрын
Why shouldn't it?
@MansourAlAkeel
@MansourAlAkeel 2 жыл бұрын
report of profit and loss, including broker fees is not very clear. Can be improved by using an existing back testing framework with some visual presentation
@Algovibes
@Algovibes 2 жыл бұрын
Hi Mansour, thx a lot for your comment. Sure, could be added. Go ahead and do that ;-) I have shown how to do that in previous videos.
@theresalwaysanotherway3996
@theresalwaysanotherway3996 2 жыл бұрын
the real question is, does it beat the market?
@stanislavyackon1887
@stanislavyackon1887 2 жыл бұрын
it beats trader
@Algovibes
@Algovibes 2 жыл бұрын
Probably the most important one!
@xxGamerKidx
@xxGamerKidx 2 жыл бұрын
So are using a backtest library like backtrader or zipline or is this strictly back testing using imports only ?
@Algovibes
@Algovibes 2 жыл бұрын
In this one I don't use a backtesting lib, no. But I am pretty sure the 97% buying order part would be quite painful to add at least with Backtrader.
@shinderaju123
@shinderaju123 2 жыл бұрын
Sir great video but 97% concept not clear pls guide
@Algovibes
@Algovibes 2 жыл бұрын
Just checking if the limit buy order would have gone through. Doing that by checking if the next days low was hitting 97% of the priors close. With that I know that the limit order would have been placed.
@knightofLotus
@knightofLotus 2 жыл бұрын
mmm I don't understand what should mean 1689% in your title...
@Algovibes
@Algovibes 2 жыл бұрын
Did you check the referenced video? Then you know! 😛
@lez075
@lez075 2 жыл бұрын
1689% = Multiplying your investmente by 17.89x, if you invest $1000, you get $17890 ($16890 neto)
@knightofLotus
@knightofLotus 2 жыл бұрын
@@lez075 thank you! now I undesrtand! :)
@luisnegrao5951
@luisnegrao5951 2 жыл бұрын
You are not taking into consideration any kind of trading fees wich makes the strategy look better tthan what it actualy looks like. Anyway great content!
@ghaithalmasri3039
@ghaithalmasri3039 2 жыл бұрын
how would u implement trading fees into a backtest?
@Algovibes
@Algovibes 2 жыл бұрын
By simply adding an amount of x from the profit. It isn't a huge deal and I already did that in a lot of my videos.
@luisnegrao5951
@luisnegrao5951 2 жыл бұрын
@@ghaithalmasri3039 In order to do so you would need to look on an exchange to see what fees they charge. Kucoin for example charges 0.1% which does not seem a lot but realy eat at the profits specialy when you make a small trade since it charges the fee when you buy and when you sell
@luisnegrao5951
@luisnegrao5951 2 жыл бұрын
@@Algovibes I have been into algo trading for some time and i found that it makes a resonable Diference. Maybe i didnt notice on the other videos. I can give you a git link if you are interested um cheking out. The catch is that i coded it with nodejs
@ghaithalmasri3039
@ghaithalmasri3039 2 жыл бұрын
@@luisnegrao5951 found a way to implement it and im actually surprised at how much it reduced my profits. And thats only 0.04% on each trade.
@andreainvernizzi8510
@andreainvernizzi8510 2 жыл бұрын
Rayner Teo is just an income youtuber who doesn't know jack about trading and capital markets. YT is his source of income, not trading.
@ahmadieb
@ahmadieb 2 жыл бұрын
peeking biased does not work
@Algovibes
@Algovibes 2 жыл бұрын
Can you elaborate?
@fate5624
@fate5624 2 жыл бұрын
LOL jemand deutsches
@Algovibes
@Algovibes 2 жыл бұрын
🤫 Bleibt unter uns, ok?
@letsgobrandon2044
@letsgobrandon2044 2 жыл бұрын
I think the tables will turn for the worst with your channel. A lot make that mistake. What this means is that the content you make free will not be profitable. Wanting us to pay for the profitable code. Just like the rest now brother
@Algovibes
@Algovibes 2 жыл бұрын
Nah, I am just giving people the option to get access to the code. The written code is the exact same thing as the presented code. I would never claim to sell "profitable" code. That being said: You could consider becoming a supporter of the channel :-) Would be happy to welcome you!
@sohailchouhan7844
@sohailchouhan7844 2 жыл бұрын
Hey brother great effort, can you tell me how to contact you.
@Algovibes
@Algovibes 2 жыл бұрын
Thanks mate, how can I help?
@luismanuelzuccolo1438
@luismanuelzuccolo1438 2 жыл бұрын
Buy conditions has a value of the future "df.Low.shift(-1)". This doesn' t' work in a live environment
@theafricanquant501
@theafricanquant501 2 жыл бұрын
You are right...but its still okay to use it in Backtesting...just to see if a trade would have been taking.
@Algovibes
@Algovibes 2 жыл бұрын
Hi Luis, did you listen to what I said in the video? 😛
@Help_Me_xBro
@Help_Me_xBro 2 жыл бұрын
Waiting for part 2. Great work. Very informative!
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
I Gave My Terrible Trading Bot $10,000 to Trade Stocks
16:05
Coding with Lewis
Рет қаралды 547 М.
Mean Reversion Trading Strategy Using Python
39:03
Computer Science (compsci112358)
Рет қаралды 18 М.
Where Does Bad Code Come From?
42:21
Molly Rocket
Рет қаралды 213 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН