In the bootcamp lesson "Using the Output of the Consolidator" the subject is mentioned. I guess this is more a reference to there being no mechanism in QC to hedge a position but surely I can write a backtest (or live strategy) where I go long and short on the same instrument at the same time right?
Arthur Asenheimer
I can't think of a situation in which it would make sense to be long and short on the same instrument at the same time. Profits and losses always neutralize each other and in the end only additional fees remain.Â
Perhaps you can provide a specific example where this approach would make sense?
And btw, hedging has nothing to do with being long and short on the same instrument at the same time.Â
Brad Hubbard
Here's the entire quote.
"Going long is denoted by ordering a positive number, and short a negative one. QC does not support hedging (long and short at the same time)."
So I guess by your definition that's a bit misleading?
I wouldn't be doing the bootcamp (and probably wouldn't need any assistance) if I had fifty years in the industry so please bear with me.
What I'm referring to is if you wanted to set a buy limit order (aplogies if this is not the right term, see above) and a sell limit order both close to the current price. The idea is for only one to be triggered of course but I believe it is conceivable that both could get triggered and you could be in both positions at the same time until one of the stops is hit. That's what I'm talking about and hopefully I am just missing the obvious way of simulating that in a backtest.
Thanks for your time, I do appreciate it as a noob.
Â
Â
Arthur Asenheimer
Hi Brad,Â
you're right. The definition is a bit misleading. Here is a better one from Investopedia:Â
"A hedge is an investment that is made with the intention of reducing the risk of adverse price movements in an asset. Normally, a hedge consists of taking an offsetting or opposite position in a related security."
If I understand you correctly, then you don't really want to have both positions at the same time, you only see the risk that this can happen due to market fluctuations.Â
But you can handle that well with OCO orders.Â
As far as I know, QC/LEAN does not offer OCO orders out of the box, but you can create it yourself by monitoring the order events in OnOrderEvent() and immediately canceling the other order as soon as one has been (partially) filled.Â
There is a helpful demo on GitHub on the subject of order tickets --> OrderTicketDemoAlgorithm
I hope this helps.Â
Brad Hubbard
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!