Hi QC Community,
I am using QC Algorithm framework to develop my strategy. Currently, in the AlphaModel when I call the Update() function would like to know 2 things.
1. Current Security Insight direction?
2. How long has the Insight been in that particular direction?
Are there any code snippets that someone can point me to for this?
Thanks!
Rahul Chowdhury
Hey Joel,
I'm not sure if I understood the exact nature of your issue. Please feel free to clarify if I've missed the point. But if I've understood you correctly,
The Update method under the AlphaModel interface needs to return Insight objects.
An easy way to create an Insight is by using the Insight.Price method:
insight = Insight.Price("IBM", timedelta(minutes = 20), InsightDirection.Up)
Here InsightDirection.Up is the current security Insight direction,
and timedelta is how long that Insight has been in that direction.
In general, the Insights you create depend on the strategy you are implementing.
Please let me know whether I've addressed your questions. Otherwise, please clarify further. What are you trying to achieve?
Learn more about Insights and all of its attributes here:
https://www.quantconnect.com/docs/algorithm-framework/alpha-creation#Alpha-Creation-Creating-Insights
Best,
Rahul
Joel Ong
Hi Rahul,
I am clear on how to create insights.
What I am looking out for is if there is a way for me to check the current Security insight direction? e.g. yesterday the insight is down and today I want to check the previous day insight direction. Is there a way for me to do this without creating a rolling window to store the information?
Another thing I am concern about is how long has the insight be in that particular direction?
Alexandre Catarino
Hi Joel Ong ,
QCAlgorithm doesn't have an "InsightManager" where all insights are stored.
If you just want to know the direction of the previous insight, you can assume that if the Security.Holdings.IsLong, the previous direction is InsightDirection.Up and InsightDirection.Down for Security.Holdings.IsShort.
However, since you also want to have information on the duration of the previous insights, you will have to store them. We have a helper class, InsightCollection, that can help:
class MyAlpha(AlphaModel): def __init__(self): self.insightCollection = InsightCollection() def Update(self, algorithm, slice): # Get insight that haven't expired of each symbol that is still in the universe activeInsights = self.insightCollection.GetActiveInsights(algorithm.UtcTime) insights = [] # LOGIC # Save insights for the next iteration before return them self.insightCollection.AddRange(insights) return insights
Tegster
Hi Alexandre Catarino
How can I find documentation on the helper class InsightCollection(). I've seen it mentioned in some posts and examples but I can't seem to find any documentation surrounding it.
I am currently able to generate insights that get passed to a custom portofolio construction. I can see from some posted examples by the community the possibilities of Insight Collection which could significantly help filter through insights passed in.
The Two sources of documentation I've found are
1. The Top Right documentation tab
2. quantconnect/lean/documentation
Number 2 was really a documentation directory with pages labeled Topic#, # is an ascending number. Which was just a shot in the dark but i found a lot of good docs but nothing on helper classes offered within Algorithm.Framework.Portfolio
Where can anyone find the documentation on helper class you mentioned above, InsightCollection?
Shile Wen
Hi Tegster,
The InsightCollection class can be found here. Our LEAN repo is another great place to find classes.
We have been working on our documentation, and in the future, it will be possible to search for particular classes.
Best,
Shile Wen
Tegster
Thank you Shile Wen
Joel Ong
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!