your tester on 18.18 is it possible to show in more detail and expanded the code how to calculate optimization parameters in several columns at the same time TP, SL, TStop , TStep??? this is the only and so important and the explanation is available! YOU ARE THE BEST !
Thanks a lot Algovibes for an excellent presentation! How can I get the number of buys and sells that is suggested? Actually how many times the position goes from 0 to 1 or vice versa?
Welcome mate! Just browse the Python for Finance / Cryptobot playlist and look for SMA videos. I have covered basically everything around it including this one. Thanks and cheers!
If I want to use it for an actual trading, do I just need to add a line of code to "create_order" in the definition of strategy? I'm very new to this area and your videos are excellent learning materials!
df is only defined locally (within the strategy function) so I see no problem here. But you can actually name it whatever you like in case you find this disturbing.
@@Algovibes You mentioned it was a copy, which suggests the original can still be retrieved. I just wonder how you would retrieve the original given the code you showed in Line 2?
@@markk4203 Yes, the original can still be retrieved with the globally defined variable df (e.g. print(df)). The changes to the data frame are only applied locally (within the function).
do you have any more video on optimization ??? You have touched on an IMPORTANT TOPIC, optimization takes hours in the metatrader if you do it with a small step, stoploss, takeprofit, trailing, why so long, do you think? Maybe because of the built-in genetic algorithms?
I am confused why in the performance function the buy and hold return changes when you change the SMA inputs. Isn't that a buy and hold over the same horizon independent of the SMA strategy? How are those related? Thanks
Just due to the fact that some returns are getting cut off when the SMA changes as with a longer or shorter SMA period more oder less rows are getting dropped when applying the dropna function.
@@Algovibes i think i see. So just the entry and exit positions are adjusted by the SMA used. I wonder if it's better to start the buy at t0 since the entry assumption is purely based on the SMA signal which a buy n hold strategy would completely ignore
@@kptrzk9398 You can do that but if you do so you would have to go back t0 - SMA period for calculating the SMA strategy returns to really compare those strategies. We are basically doing that here and just cutting off the SMA period. I don't really see a benefit of not doing the cut off.
import matplotlib as mpl color = 'white' mpl.rcParams['text.color'] = color mpl.rcParams['axes.labelcolor'] = color mpl.rcParams['xtick.color'] = color mpl.rcParams['ytick.color'] = color Source: stackoverflow.com/questions/48958208/how-do-you-change-the-default-font-color-for-all-text-in-matplotlib
Thanks a ton Sahila, already got a lot of that stuff covered. Be invited to check out my Python for Finance playlist and the cryptobot playlist (and the Machine Learning playlist as well). Let me know if you need anything else and I am happy to cover that in future videos!
@@Algovibes Thanks again. Just wondering, I notice that your notebook has the timer (showed as -----100%------) when you run a cell, how do you enable it?
Hey there, you have by far the most interesting yt channel out there for this topic! I am also getting into Python atm. I would have one question. Is it also possible to test „all“ possible combinations instead of just adding the value „5“ on both sides? I mean when I would have 1,2,3 and 11,12,13 That I am not just testing 1-11 2-12 3-13 But also 1-12 1-13 2-11 2-13 3-11 3-12 How would that look like? Thanks in advance :) Greetings from Augsburg
Hi Philipp, If you have found out how to do this, could you share the code pls? I am also getting into Python atm and struggling to solve this. Thanks in advance.
Aren't the realtime averages different than what's displayed on your historical charts since the future data isn't available yet? Have you tested your algorithms feeding the data in without it knowing what coming next?
Hi Algovibes, Thanks a lot for sharing these tricks that we can do using Python in real life. I have one question- can you guide me, what could be the best possible way to identify if we have a growing SMA or a falling SMA on any particular stock using python??
@@Algovibes actually the way you are back testing a strategy, I also want to back test one strategy and it requires to shortlist only those stocks which have rising SMA 200
Isn't it better to calculate edge with stratret divided by ret? Is this because of the log? EDIT: Why is the return on just holding different every time?
Ok somehow fixed it in Jupiter, but got another issue. Error in def strategy ----> 7 df['position'] = np.where(df['SMA1'] > ['SMA2'], 1, 0) ValueError: ('Lengths must match to compare', (1265,), (1,))
Whoever got that problem: Update yfinance. I had the same problem as well. There is something wrong with you SMA calculation. Please double check that. You are comparing 1265 rows to a single row right now.
Not sure if I am correct, but seems there is a minor bug in the performance function, at which after taking exponential of the cumulative log return, we need to minus 1 before the actual cumulative return is returned. Otherwise the result will be incorrect and will always be a positve number, distorting the simulation result.
It's not a bug. It's just what you want to have. If you want to have the amount where you want to multiply the invested amount with, you are taking my approach. If you want to have the actual performance (in %) you are subtracting a 1. Let me just give you an example: 1999-01-22 NaN 1999-01-25 1.104763 1999-01-26 1.019049 This is the return series using no -1 subtraction. To calculate your gain you just take the 1.019... and multiply it with your invested amount -> that's your "end" capital. But if you want to tell someone how much profit you made you say "Hey I made" 1.019... - 1-> 1.9% win" Makes sense to you?
@@Algovibes Ok this makes sense. My comment was based on the fact that I was trying to derive the actual PnL, and therefore I need to -1. Thanks for prompt sharing ! :)
the dataframe will be erased after turning off the computer and how to save the received stock date to the database on your computer so that later you can quickly load and process ?
@@Algovibes Thanks! And everything is very simple, in this video you saved quotes to a dataframe in IDE, so I asked how to save quotes to a database on my computer maybe SQL or maybe you wrote a graphical application on PyQt5 for quick subsequent optimization of the strategy. And records in the database of optimization results.
No doubt the best youtube channel for python Algo trading , very practical and concise , good job
Thank you for your kind words my friend :-)
Great video, can you please tell me what IDE are you using in this video?
Thanks.
Thanks for watching and your comment :-)
I am using Jupyter Notebook.
your tester on 18.18 is it possible to show in more detail and expanded the code how to calculate optimization parameters in several columns at the same time TP, SL, TStop , TStep???
this is the only and so important and the explanation is available! YOU ARE THE BEST !
Thank you my friend ❤️ Also thanks for the suggestion!
Thanks a lot Algovibes for an excellent presentation! How can I get the number of buys and sells that is suggested?
Actually how many times the position goes from 0 to 1 or vice versa?
Welcome mate! Just browse the Python for Finance / Cryptobot playlist and look for SMA videos. I have covered basically everything around it including this one. Thanks and cheers!
Didi I get it right that one can get hold of the actual script becoming a Tier-2 Channel member?
Meanwhile it's Tier-3. Looking forward to welcome you as a channel member! :-)
Thanks!
Thanks Buddy ☺️
Really appreciate these videos. Thank you. How did you get dark mode with Jupyter Notebook?
Thank you mate. It's the Monokai theme from Jupyter themes.
If I want to use it for an actual trading, do I just need to add a line of code to "create_order" in the definition of strategy? I'm very new to this area and your videos are excellent learning materials!
Thank you mate. Well can you elaborate where in this video I am using create_order? :D
You made a copy of the dataframe in Line 2 of strategy(). How would you call that original df, now, after naming the copy df as well?
df is only defined locally (within the strategy function) so I see no problem here. But you can actually name it whatever you like in case you find this disturbing.
@@Algovibes You mentioned it was a copy, which suggests the original can still be retrieved. I just wonder how you would retrieve the original given the code you showed in Line 2?
(bump)
@@markk4203 Yes, the original can still be retrieved with the globally defined variable df (e.g. print(df)). The changes to the data frame are only applied locally (within the function).
do you have any more video on optimization ??? You have touched on an IMPORTANT TOPIC, optimization takes hours in the metatrader if you do it with a small step, stoploss, takeprofit, trailing, why so long, do you think? Maybe because of the built-in genetic algorithms?
Pretty straightforward: I didn't work with Metatrader yet. Any suggestions what in particular you would be interested in?
@Algovibes Any chance to create a grid strategy with python?
Pretty cool idea. Not on my list right now but might indeed be an interesting thing to code.
I am confused why in the performance function the buy and hold return changes when you change the SMA inputs. Isn't that a buy and hold over the same horizon independent of the SMA strategy? How are those related? Thanks
Just due to the fact that some returns are getting cut off when the SMA changes as with a longer or shorter SMA period more oder less rows are getting dropped when applying the dropna function.
@@Algovibes i think i see. So just the entry and exit positions are adjusted by the SMA used. I wonder if it's better to start the buy at t0 since the entry assumption is purely based on the SMA signal which a buy n hold strategy would completely ignore
@@kptrzk9398 You can do that but if you do so you would have to go back t0 - SMA period for calculating the SMA strategy returns to really compare those strategies. We are basically doing that here and just cutting off the SMA period. I don't really see a benefit of not doing the cut off.
One other question: how would you change color of the tick labels to stand out against the black background? Thanks!
import matplotlib as mpl
color = 'white'
mpl.rcParams['text.color'] = color
mpl.rcParams['axes.labelcolor'] = color
mpl.rcParams['xtick.color'] = color
mpl.rcParams['ytick.color'] = color
Source: stackoverflow.com/questions/48958208/how-do-you-change-the-default-font-color-for-all-text-in-matplotlib
Great video. Could you make machine learning video for similar optimisation?
Thanks a ton Sahila,
already got a lot of that stuff covered. Be invited to check out my Python for Finance playlist and the cryptobot playlist (and the Machine Learning playlist as well). Let me know if you need anything else and I am happy to cover that in future videos!
Thanks alot. Especially the part where you present different MA pairs. Really appreciate it.
Appreciate your comment! Credits for this one should go to Deepak Kanungo (Referenced in the video description).
@@Algovibes Thanks again. Just wondering, I notice that your notebook has the timer (showed as -----100%------) when you run a cell, how do you enable it?
Hey there, you have by far the most interesting yt channel out there for this topic!
I am also getting into Python atm.
I would have one question.
Is it also possible to test „all“ possible combinations instead of just adding the value „5“ on both sides?
I mean when I would have 1,2,3 and 11,12,13
That I am not just testing
1-11
2-12
3-13
But also
1-12
1-13
2-11
2-13
3-11
3-12
How would that look like?
Thanks in advance :)
Greetings from Augsburg
Hi buddy,
thanks a lot for your comment. Yep that's indeed an interesting question!
I would probably solve it with a nested logic.
Hi Philipp,
If you have found out how to do this, could you share the code pls? I am also getting into Python atm and struggling to solve this. Thanks in advance.
You have used ML for optimization strategies ???
Played around with different ML stuff but wouldn't say I was "using" it for the purpose of optimization.
Aren't the realtime averages different than what's displayed on your historical charts since the future data isn't available yet? Have you tested your algorithms feeding the data in without it knowing what coming next?
Hi man, that is covered in e.g. my cryptobot playlist. Be kindly invited to check that out.
Hi Algovibes,
Thanks a lot for sharing these tricks that we can do using Python in real life.
I have one question- can you guide me, what could be the best possible way to identify if we have a growing SMA or a falling SMA on any particular stock using python??
Hi man,
welcome! :-)
Can you elaborate on why do you want to check that?
@@Algovibes actually the way you are back testing a strategy, I also want to back test one strategy and it requires to shortlist only those stocks which have rising SMA 200
Isn't it better to calculate edge with stratret divided by ret? Is this because of the log? EDIT: Why is the return on just holding different every time?
Return differs because of dropping another number of rows due to the rolling function. Hope this is answering your question!
Great work!!! I didn't understand why buy and hold returns are changing.
I figure out! It's because dropna after rolling method.
Thanks for watching and your comment mate, you figured it out perfectly :-)
Good afternoon. Please tell me why the 1 day timeframe was downloaded? and how to change your code to download 5 minutes
Hi buddy,
Covered other time intervals here:
ruclips.net/video/BhOdgrxWi5c/видео.html
Great video ...
Bravo from Morocco
Thank you my friend :-)
Greetings to Morocco 🇲🇦
Great video! However, when I include the drop NA I get different results than if I do the returns calculations in excel.
Thanks a lot man. That's because when dropping the NaN row, you will also delete the row containing the return of that particular day.
Thank you for the vid, I never tought about this ideia of multiplying the condition column * percentage change, good job !
Greetings from Brazil
No credits to me! I recently found this in an algorithmic trading course. The reference is in the video description! (Deepak Kanungo)
Btw Greetings back to 🇧🇷:)
Thank you for that video, but having problem with yfinance data downloading ''json.decoder.JSONDecodeError:'' Any thoughts how to fix it?
Ok somehow fixed it in Jupiter, but got another issue.
Error in def strategy
----> 7 df['position'] = np.where(df['SMA1'] > ['SMA2'], 1, 0)
ValueError: ('Lengths must match to compare', (1265,), (1,))
Whoever got that problem: Update yfinance. I had the same problem as well.
There is something wrong with you SMA calculation. Please double check that. You are comparing 1265 rows to a single row right now.
Not sure if I am correct, but seems there is a minor bug in the performance function, at which after taking exponential of the cumulative log return, we need to minus 1 before the actual cumulative return is returned. Otherwise the result will be incorrect and will always be a positve number, distorting the simulation result.
It's not a bug. It's just what you want to have. If you want to have the amount where you want to multiply the invested amount with, you are taking my approach. If you want to have the actual performance (in %) you are subtracting a 1.
Let me just give you an example:
1999-01-22 NaN
1999-01-25 1.104763
1999-01-26 1.019049
This is the return series using no -1 subtraction. To calculate your gain you just take the 1.019... and multiply it with your invested amount -> that's your "end" capital.
But if you want to tell someone how much profit you made you say "Hey I made" 1.019... - 1-> 1.9% win"
Makes sense to you?
@@Algovibes Ok this makes sense. My comment was based on the fact that I was trying to derive the actual PnL, and therefore I need to -1. Thanks for prompt sharing ! :)
the dataframe will be erased after turning off the computer and how to save the received stock date to the database on your computer so that later you can quickly load and process ?
Can you elaborate? I don't see the coherence with the content in this video. Maybe I am getting you wrong.
@@Algovibes Thanks! And everything is very simple, in this video you saved quotes to a dataframe in IDE, so I asked how to save quotes to a database on my computer maybe SQL or maybe you wrote a graphical application on PyQt5 for quick subsequent optimization of the strategy. And records in the database of optimization results.
Thanks bro ,can u plz make one vedio on STC indicator ......i search all around but I cannot find out ...plz make one
Thanks for watching and your comment :-) Appreciate it!
Noted that but have some other stuff planned beforehand.
@@Algovibes ok
Great as always! :)
Thank you my friend!
clear, understandable, amazing videos from Algovibes , thx you very much
Thank you my mate! :-)
Thanks for the video, can you publish the source code?
Thanks for watching :-)
Source code will be published once I set up a website for that.
hello video is not clear. please upload in higher resolution. currently it is 360p. thanks
The Video is uploaded in HD but is still processing. It is unfortunate but there is nothing I can do about it. Please check again in some hours.
Watching in 480 now and totally legible.
interested combine and OPTIMIZE !!! TP, SL, TStop , TStep at the same time in one table as in this video 18 min 18 sec
Is this for spot trading or futures trading?