In the mean reversion course it was said that if I use the raw portfolio data I would be getting the weights in shares and if I use the log prices in the cointegration test I would get the weights in cash value. Weirdly I get better performance using the raw price data vs log price data. I’m not sure why. I don’t think I can use share or regular forex fractionally. Therefore, I could never buy 1.5 of a particular stock. Kindly let me know if there is something wrong with my logic.
Hello Jenny,
Could you gives us the exact unit and section you reference to help you out, please?
Besides, fractional sharing is completely possible in forex. In stocks, you have to find a broker which provides fractional shrares. For example, Interactive Brokers provides fractional shares. But be cautious about it and always backtest your strategy with transaction costs, so you can have a good idea about how well your strategy might perform in the future.
Thanks a lot
Jose Carlos
Mean Reversion Strategies In Python: What is Hedge Ratio?
I emailed you at blueshift twice. I have yet to get a responce where i sent my private code.
You have also yet to comment on the fact that my performance is lower with the log and rebalancing using the ratios of cash value between assets in my porfolio vs rebalancing using the same ratio calculations.
This is not right according to your theory in the class indicated above.Kindly reply to the email sent to you from me the title is "Johansen cointegration weights." I also sent one before that called "Crypto Mean Reversion".
In the mean reversion course it was said that if I use the raw portfolio data I would be getting the weights in shares and if I use the log prices in the cointegration test I would get the weights in cash value. Weirdly I get better performance using the raw price data vs log price data. I’m not sure why.
Regressing on prices gives the hedge ratio or relationship in terms of quantity and regression log prices gives the relationship in terms of the dollar amount to hedge. Both these methods of computation are based on historical data and the performance is evaluated on unseen data. Therefore, the performance would vary.
I don’t think I can use share or regular forex fractionally. Therefore, I could never buy 1.5 of a particular stock. Kindly let me know if there is something wrong with my logic.If you can't use the fractions, you need to go to the nearest whole number. In this case, you can buy 15 of a particular stock and 10 of the other instead of 1.5 and 1.
Thanks
Dont just speak for speaking sake think before you comment. "Therefore, the performance would vary.
"Im not supposed to get a better performance using the hedge ratio as cash value ratio between assets vs without the log of the prices.
If i use log prices with the frst one should do better than second with just raw data
order_target_percent(i, (j/Total)) vs order_target_percent(i, j)
BUT THIS IS NOT HAPPENING.
Please take your time to comprehend what Im saying.
There are two methods to determine the hedge ratio.
- Number of shares
If you regress the raw prices, then the hedge ratio is the number of shares to hedge. For example, if you have two assets A & B. And you regress the prices and get the hedge ratio of 2. Then the equation becomes B = hedge ratio * A. That is, B = 2 * A. You need to buy 1 share of asset A for every 2 shares of asset B.
Since you want to place the order for the number of shares the correct method to use would be
order_target(asset_symbol, number_of_shares)
Reference link for the method: https://blueshift.quantinsti.com/docs/placingtrades/#:~:text=order_target(asset%2C%20quantity%2C%20limit_price)
- Dollar Value
In the second method, if you regress the log prices, then the hedge ratio would be dollar value to hedge. Continuing the same example of assets A & B. If after regressing the log prices of A & B, you get the hedge ratio of 2. Then the equation is the same, B = 2 * A. But here if you buy $100 worth of asset A, then you need to buy $200 worth of asset B.
You can use order_target_percent method here for it.
order_target_percent(asset_A, 0.33)
order_target_percent(asset_B, 0.66)
Using raw prices and log prices are two different methods of computing hedge ratios and applying them. The dollar value method would require frequent rebalancing to maintain the hedge ratio of the dollar value. Whereas if you hedge the number of shares, then frequent rebalancing is not required as the number of shares are same. This could be the reason why the performance is deviating.
Note: It is not very clear from your question why you would expect the second method of log prices to work better than the first method of raw prices. As these are very two different methods with different usages.
I hope this helps.
Thanks
Do you see any use of log of the price here?
https://blog.quantinsti.com/kalman-filter-techniques-statistical-arbitrage-china-futures-market-python/?_gl=1*1fi1jg8*_ga*NDEwNjg4MTU0LjE2NTMwNjkxNjk.*_ga_SXP1W7WL9G*MTY1NTIzMTE2My4zNi4xLjE2NTUyMzEzNDUuMA..
Hello Jenny,
In the "Data Mining" section code, you find the following:
data = pd.read_csv('all_contracts.csv',index_col='tradeDate')
And, in the beginning of the article, you will find the following comment:
"The daily trading prices of the main contract are accessed through UQER's API."
This dataframe "data" is later used in the "find_cointegrated_pairs" function. This function uses these data to compute the cointegration test. The function doesn't change the raw prices to log prices, either.
Consequently, there is no use of log prices here. The author uses the raw prices.
As well as Ishan commented, the backtesting performance might vary depending on which type of data you use. Neither the use of log prices or raw prices is better. Than depends on the trader and what specifically want for his trading strategy.
I hope this helps,
Thanks and regards,
Jose Carlos
For example, consider a portfolio of
GLD and GDX formed with the
hedge ratio -1.63 as:
+ ? * GLD ? * GDX.
Can you answer this please?
Thanks.
Hello Jenny,
Hedge ratio describes the amount of instrument GDX to purchase or sell for every unit of instrument GLD.
The cointegrating equation can be presented in two ways:
- spread = GLD - hedge_ratio * GDX
- GLD = +hedge_ratio * GDX + spread
Where the hedge ratio can be a negative or positive value. If you see, the two questions are the same, it is just a change on which variable goes at the left or right side.
If someone tells you that the hedge ratio is -1.63, then the equation goes like this:
GLD = -1.63 * GDX + spread, or
spread = GLD +1.63 * GDX
Do you understand?
It's just a change of left to right hand side or viceversa.
I hope this helps,
Thanks and regards,
José Carlos