I saw on multiple threads prior to 2020 QC had a netting of orders structure. I want to make an algorithm that can simultaneously take a long and short position on the same symbol, without flattening the position on either side - a hedge order structure.
Is there a way to change the order structure, bring two portfolios into one QC algorithm, have two Alphas not flatten each other, or anything of the sort that will allow for a hedge order structure?
Can this be done today on QC and if so how? If this cannot be done today, are there any plans to implement this in the future?
Lucas
You can use the algorithmic framework for this. See the link at the bottom.
You have to make your own PCM, as I dont think that the default ones likes it when, going long and short the same symbol. They usually just take the last sent insights of the given symbol, and execute this. I had do do this when making a pairs trading algo, and I got it to work
If you have any questions, just reach out in the same thread.
JiTrue
Thank you for your response. In simplicity, the PCM takes the Insights generated by Alphas to create Portfolio Targets.
Yes, Current default PCMs such as equal weighting does not have hedging behavior. I wrapped the strategies into Alpha models already. Can you provide a backtest of how the custom PCM would be to allow hedging?
Thanks,
Louis Szeto
Hi JiTrue
We normally hedge by options or futures, rather than the stock itself. Unlike a CFD, the stock security itself ain't a contract to provide a unique position size to do what you want to, at least on the table balance sheet.
One way was as Lucas has suggested, using a PCM with insights to handle the 2 signals (original & “hedge”). You may consider using a InsightWeightingPCM. Refer to the attached backtest as example. You may find the usage of InsightCollection in here.
Another way would be using a dictionary to store each order, such that you can calculate the quantity needed to repurchase after the hedge ends.
Best
Louis
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Non Compete
How do you hold a short and long position for the same symbol in a single algorithm? For example if we do:
We end up with a quantity and absolute quantity of 5 because the negative order sells some of first order instead of opening a new short position. Is there a way around this? For example is there a way to get a “totalQuantity” as 15 and a “shortQuantity” and “longQuantity”? Also, will the brokerage do something similar and actually cancel out some of your long position if you short? Then you need different brokerage accounts to hold different positions on the same security?
Louis Szeto
Hi Non Compete
It is not possible to hold both long and short position of the same security according to numerous regulations. LEAN also does not provide this functionality. Instead, you might consider using derivatives like options, futures & CFDs to archieve the same purpose. Most institutions are also using temporary future/option positions as overnight sepculation risk hedge.
Best
Louis
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
JiTrue
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!