Hi,
Regarding insight generation, I understand that sending a positive order(100 for example) should generate an Up direction insight, while sending a negative order(-100 for example) should generate a Down direction insight, but what if I'm sending orders through SetHoldings()?
For example, what if on day 1, I send an order using SetHoldings("SPY", 1.00), and on day 2 I send another order through SetHoldings("SPY", 0.50)? The first order should generate an Up insight, and just to clarify, is the second order supposed to generate a Down insight since half of the holdings are being liquidated?
When using SetHoldings(), there can also be some cases where the algorithm might add positions and in other cases liquidate positions, depending on where price has moved; how do you generate insights for a case like that?
Thanks!
Derek Melchin
Hi Vncne,
Insights aren't automatically created when placing orders. Instead, we need to manually create them. If we want to emit insights for each trade we place, first we determine the weight of our portfolio to allocate.
weight = random.random() * 2 - 1 # `weight` is in the interval [-1, 1) quantity = self.CalculateOrderQuantity(self.symbol, weight) self.MarketOrder(self.symbol, quantity)
We can then generate insights with the appropriate direction
if weight < 0: direction = InsightDirection.Down elif weight == 0: direction = InsightDirection.Flat else: direction = InsightDirection.Up insight = Insight.Price(self.symbol, timedelta(days=1), direction, weight = abs(weight)) self.EmitInsights(insight)
In general, insights signal which direction we think the market will be moving over some period in the future. When generating insights with the snippet above, we specify the `weight` to signal how much of the portfolio should be at stake.
See the attached backtest for reference.
Best,
Derek Melchin
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.
Vncne
Hi Derek,
I'm aware that we have to manually create our insight before sending orders.
I guess to rephrase my question, I'm not sure what insight direction to give to some of my orders when using SetHoldings(). When going long, we would give our insight an Up direction, while going short we would give it a Down direction. What if we're merely reducing our position? If we're starting with 100 shares and send an order to liquidate 50 shares, what insight direction do I give that order? I'm not liquidating the entire position, so I figured that wouldn't be a Flat insight, but I'm not shorting or necessarily expecting the price to go down, so I'm not sure if it's a Down insight either.
Derek Melchin
Hi Vncne,
If we are holding a positive number of shares for a security, we should have an active insight with an upward direction. When we have a negative number of shares (short), the insight should have a downward direction.
Therefore,
> If we're starting with 100 shares and send an order to liquidate 50 shares, what insight direction do I give that order?
Up
Best,
Derek Melchin
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.
Vncne
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!