What "isues" are you having with the Johansen cointegration code? Whats the error and the date time of the error in the backtest?
Also waiting on the other code in question the Engle Grander pair trading strategy sent to you on 28 Jun at 18:22. I tested it again and it works fine. You said you "Your code has been checked. It really looks great. " Kindly show the performance before and after you made the changes you suggested.
Hello Jane,
The reason I said your code looks great is that you have developed a very complex code on your own. That's something valuable.
What I meant by issues, is that we're having problems running your code in the blueshift platform. I'll review the new code you sent and come back to you at the earliest.
Thanks,
José Carlos
Thank you, Namaste.
Hello Jane,
Could you please send your code through a google drive link and share it through here?
This will help us to get quicker to your code.
Thanks,
José Carlos
Johansen Cointegration
https://drive.google.com/file/d/1BVN7vnOKZIpVYXuTHZ_i_16GUPoUQ2vQ/view?usp=sharing
Engle Granger Cointegration
https://drive.google.com/file/d/1BUS_bdukUfJ0lGQeuMZbEHse75Rk7JMt/view?usp=sharing
I shared it with
quantra@quantinsti.com
I hope thats alright.
Hello Jane,
Could you please share access to your 2 files?
Google is requesting me access. Please make your code public so we can have access to your scripts.
Thanks,
José Carlos
Done.
Thanks, Jane,
We'll get back to you at the earliest,
Thanks
José Carlos
Thanks.
You may want to speak with Mr Ghosh im 100% sure he can solve these issues.
Done!
Still waiting.
Both codes has general access meaning anyone with the link can get it. And both codes work and I have the proof.
The Johansen Cointegration uses raw price data and weights in share amounts. It shows the concept works but the issue for this code is that when I try! To use logs of the raw price data and ratios of weights which would look like this order_target_percent(i, (j/Total)) j values here arnt ever more than 1 or less than -1. SO! my question to you for this code is why is it doing so poorly? Run the code again using line 282 and 299 instead of 286 and 296 and use line 190 to transform the raw price to logs. Youll see the issue Im having.
Thanks in advance for your time and diligence.
Your "deeper" explaination on Mr Shash's is very poor.
Do this entire responce over with the scientific approach. So like any good experiment use a controled variable(hedge ratio and assets used) and independnt variable(going long and short) and we observe the dependent variable or outcome(backtest performance(sharpe ratio Max Drawdown).
Please do not change the hedge ratio for each situation.
Also your totals are using negative numbers and this seems very wrong.
You should use totals = abs( 1 + hedge_ratio.iloc[-1])
For example lets say you have 2 values -6 and 3 and you want to use these two values as a ratio.
Using your logic you would get -6/-3 and 3/-3 this is very wrong.
The correct answer would be
-6/9 and 3/9
or
-2/3 and 1/3
Please take your time and think about these issues. Do not simply rattle of theory without proper practicale application and thought. Critical thinking is vital to solve the issues faced. Everything you put here I will test and show you the outcome and Im sure this wont be easy but with the right attitude and application of resources we can work through this and arrive at the right answer.
Lets focus on the Engle Granger Code From this point due to the new performance from the correction I made "stock_data.long_exit[-1]:" to the Johansen Cointegration code.
Hi Jane,
You are right in using absolute values. With respect to a difference in performance, can I suggest (if you haven't already) you can run a full backtest in blueshift and then conduct a thorough analysis on the orders placed and filled.
One reason there is a difference in performance could be that the amount of capital can limit the number of orders which can be filled. If you have Apple and Google (priced at $100+) as your assets and your capital is kept at $1000, you will be able to buy a few stocks. In comparison, if your capital is $1 million, you will be able to buy more and hence your performance will be different. But that was just my opinion and if you have already known this, my apologies for sounding repetitive.
I think at this point you are able to understand and figure out why a strategy can have different results. This could be due to a change in the quant method used, or certain factors such as raw or log. Kudos to that. Now you can focus on the strategy which is giving you a good performance (based on metrics such as returns, max drawdown, shape ratio etc.) and check if there is room for optimisation.
I hope this helps and you can always start a new thread if you run into any roadblocks on your way to creating a winning strategy. Thanks.
On your course you say that I need to use log prices to create a spread that rebalances and gives weights in cash value. ATM THIS IS NOT HAPPENING.
I am using raw prices and rebalancing and using a calculation for weights that is expecting or uses cash value!
Therefore this should not work the way it’s working.
When I use log prices it performs terribly. I’m asking why is this. The code is from your own blog and your theory is from your own mean reversion course.
This should be simple for you the teachers and creators of the course.
I appreciate all the help and back and forth we have even though we may not always see eye to eye.
I respectfully wait your response/correspondence.
Questions:
- Did you make the changes to your raw-prices-based strategy hedge ratios based on what I explained to you previously (examples 1 and 2? Even though you might have good results, that doesn't mean the strategy is well written. Please check that.
Answer: Yes
- Did you make the changes to your log-prices-based strategy hedge ratios based on what I explained previously in examples 3 and 4 (and corrected by you)? Please try that in order to see your results change for the better.
Answer:Yes.
They were both terrible, can you kindly use the code I sent and make the changes to see them for yourself? Or before you send suggestions to me you can check them out on your own backtesting platform? This will save time and I know you may not want to help me code directly but Im just trying to understand what you are teaching in your course in practice efficiently.
I just want to say thanks again for all the help and cooperation.