Hi and welcome to this challenge.
This is the opportunity to create the cotton bag test that lasts from scratch on your own.
And as I said before, this is an important skill that will definitely help you to define and test your
own unique trading strategies in a very efficient manner.
And actually, if you like, you can build on the Esmay back test that class.
So the general idea and the general framework is always the same.
And the contrarian strategy and its class is even more simple than the s.m a strategy.
So let's have a look at the required steps.
And first of all, you should initialize the properties, symbols start and trading costs and results.
Then, uh, next, uh, you should add to the Method getData where you retrieve and prepare the raw
data from the CSP file intraday past NSV.
And that's the simple contrarian and also a simple momentum strategy is the simplest strategy we can
think of.
So here in this example, we don't need to the method to prepare data.
So we just use the method to get data and we call get data in the thunder init method.
Then next you have to add to the method test strategy.
And, uh, that's, uh, one parameter, the window parameter.
And then you should add to plot results and also the method optimized parameter.
So we have only one parameter, the window parameter to optimize and therefore no combinations are required
here.
And that means that you don't need the product from either to it's here.
And finally, you should also add an appropriate string representation and some dark strings.
So this is the challenge here.
And if you don't want to see the solution, then you're sure to stop the video now.
All right, now, let's go on this resolution and you can find the complete back to the class here below,
or alternatively, you can also find the contact test python module in the download files.
And as always, we start here with the Thunder init method and we have the parameter symbols start and
and trading costs and we create the attributes, symbols start and trading costs.
The result was just none.
And we also call the getData method.
Then we have the Thunder Epper method with an appropriate string representation, for example, connectors
that can be described by the symbol at the start and the end date.
Then we impart the data from the CSP fired intraday past NCSA and we select the Semba then the time
period and we calculate returns.
And with this we have the required data to define and calculate the strategy.
So we don't need here the method to prepare data.
Then we have a test strategy with one parameter and the default argument one.
And we actually created the additional attribute window, which is the required, but we can do this
and then we pass yourself that window to the rolling, uh, method.
Then we determinant of select trading costs and calculate the performance of buy and hold and to the
strategy.
And finally return the absolute performance of the strategy and the underperformance.
Then next, the plot method works pretty much in the same way as in the same way back to class and finally
vía the optimize the parameter method and we have to pass Shira Toeplitz with a start and and to step
size for the window parameter.
And, uh, what we actually do here, we unpack the top layer and then we create a range object and
then we iterate over the range object and calculate this relative performance for each and every window
and upend the performance to the list results.
Then we get to the best performance and the optimal parameter so we can delete S.
And then we run and said the optimal strategy and finally we create a data frame with many results and
then the method returns the optimal parameter for windows and the best performance.
So this is the back test the class.
Thanks for watching and see you in the next lectures and sections by.