Hi there,
I am currently porting some of my projects from cTrader to lean and so far its going well.
Except that my most promising project uses hedging. I know that its probably not on your timeline as stated here
I am willing to have a look at providing some implementation for that, but could use some pointers.
Where would I start? I could probably drop something in there that uses specific symbols or drop a field in the symbol class that identifies the position and then look at that field in the brokerage somewhere. But i would prefer a more general way that has a chance to work with backtesting.
Any thoughts?
Douglas Stridsberg
When you say "hedging", what exactly do you mean?
If you mean simply holding offsetting positions in other, correlated assets then that's of course something you can do.
Maybe there's a way to take the mechanics of what you need and turn them into something that works with the current functionality of QuantConnect?
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.
Mirco Kahle
I need to hold long and short positions in one asset at the same time.
When I use a hedging account with LEAN it will open a new position in the opposite direction when I use Liquidate().
Currently I am trying to add a new method that takes a symbol parameter and a long/short enum and actually closes all positions that match the parameters. I think that should work with my brokerage, but I have no clue how to support that in backtesting.
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.
Jared Broad
Hey Mirco! Thank you for the offer. It is a lot of work but if you're up for it we can help guide the design! =)
Positions would need to be recorded separately instead of being placed into a single decimal Quantity field. This would need some sort of array of Position objects stored in the security. The positions would need to be referenced somehow so we could flag them as closed. Perhaps when people place orders they can flag which position they'd like them to apply against.
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.
Mirco Kahle
I had a look into this and think I'll continue to run my hedged algorithm via cTrader for now :'(
But switch to LEAN with the other two algorithms that dont rely on hedging :)
From what I found I think the best chance of plunging hedged support in would be to create some kind of "HedgedForex" security. Then one would implement an ISecurityPortfolioModel. For that to work you would need to modify Order and maybe OrderEvent to keep your Short position that is opened further and Long position that gets closed apart.
The second possibility I see, and at least to me more interesting, is to shove a layer between events and holdings/securities that aggregates to positions and from there to holdings.
I sadly lack the time to implement either possibility at the moment, maybe in a few months.
But if anyone wants to pick this up, I'll sure contribute some lines.
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.
Jared Broad
Thank you for looking into it Mirco. It is not an easy task sadly. For the hedging algorithms - could you run two instances of LEAN which communicate with each other? Or ignore the Portfolio.Quantity field and manage your own portfolio?
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.
Mirco Kahle
Hey Jared, thanks for your feedback :)
running my own portfolio would not do much. I run a hedged account on OANDA, then i open a long position. Then, after some time, i liquidate it via LEAN. From the LEAN side it looks like i dont have any holdings. But the account on the OANDA side suddenly has two positions, the original long position and a short position from the liquidate() call with the same volume. There is no way to actually close both positions afaik.
But I actually could run two instances on two separate (non hedged) accounts. It would limit my volume, but that might not be a problem... hm, I would have to balance my equity over the two accounts somehow, maybe OANDA has an API for that or i need to implement an alert and do it manually. Backtesting wont work of course, but I think this could be an viable alternative nonetheless, will investigate in a bit, thanks for the idea.
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!