LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
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.
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.
Alex Monk
143 Pro
,
I spent my holidays on bootcamps and learning QC - and ofcourse lots a lot of hair and the remainig is grey; this video by far has been the best big thanks to you Louis.
My main issues with QC: - I still don't know how to plot candle sticks on an examplary alpha model - say EMA crossover - Code completion and suggestion basically doesn't work for me or it's ultra slow if it wants to suggest a thing; thus forcing me to use local dev env. - In local Docker, plumming plotting and using my broker to get historical data has been chasing the rabbit hole.
Would be great if you can make video on any of these topics.
4
Shile Wen
63.5k Pro
,
Hi Alex,
If you would like OHLC candlestick plotting, it is not supported at the moment. Otherwise, please refer to this thread on plotting candlestick charts.
On the code completion, are you using Skylight? If so, please tell us your IDE and other details to see if there are ways to help us speed up the code completion. If you are using C#, please refer to this post on how to make autocomplete work using local Lean.
One thing I did notice though is that you check to exit positions that should not be long, but you never check to not enter them again if they are already invested in. I guess this must be a functionality of the framework to handle that and balance that out automatically for you according to the weight. I assume that InsightWeightingPortfolioConstructionModel will always invest 100% of the portfolio balanced on the weight of the Insights? This will mean when only one insight is given the weight will have no effect and 100% of the portfolio will be allocated? I assume this because the weight you calculated is relative to each other, but what about what is already in your portfolio?
So Many questions about so many things because I do not understand how the portfolio management will work in all these different scenarios and I struggle to find any relevant information on this. I do not say there is no documentation on this, but perhaps I do not know how/where to find it. These are things that become worrisome when one thinks about live trading. How is the portfolio synchronised with the broker account, what if a position gets opened outside the algo on your account or closed for that matter? Or errors occur?
Thanks for the comment. You are completely right in that the insight weights are automatically normalized. Furthermore, the insights of this algorithm expire within 31 days. So if we don't resend them, the positions would automatically be closed after these 31 days. That's why it is important for us to send out those insights again.
I certainly agree that it can sometimes be hard to find certain details. In my opinion, a good way to learn more (besides the documentation and forum) is the actual Lean code. For example, you can find the code for the algorithm framework here:
I certainly understand that it can be scary to live trade if you aren't completely sure how everything works. But if that's the case, I just wouldn't recommend live trading. It takes time to learn everything and get used to QC's API. Just take your time and don't rush to live trade. Besides that, make sure to very thoroughly test all your algorithms by backtesting, stress testing, and live paper trading them before you actually deploy them with real money.
I hope this helps.
3
Eben Olivier
45 Pro
,
Thanks for the feedback, surely do help
1
Emiliano Fraticelli
3.1k Pro
,
Hi! I'm adding new "fundamentals factors" to the strategy.
I've added many in the quality and scores area, I'm wondering if there are more that I haven't added yet.
There you should find a list of the currently supported fundamental data. Just note that more data doesn't always lead to better results. You could try analyzing the correlation between some of these factors with returns to filter out the useful ones.
2
Emiliano Fraticelli
3.1k Pro
,
Thanks a lot Louis,
yes I know that more data doesn't always lead to better results. I have been a Quantopian user for a long time and I used to do this kind of research in their research envionment using AlphaLens.
For the moment, to do something similar, I've upped the single "Factor" value in my algo by giving to it a very high score.
to test the impact of this "Factor" to the Sharpe ratio. But improvements have been limited, the "best" seems to be FCFYield even giving to this factor the 90% and more of the importance (notice 100 ) Sharpe ratio from 2008 to current date is still somewhere around 0.7%, no more than that.
Yes, inside of your algorithms, you can set up and work on your own research notebooks. Thanks for linking to such a sample notebook on fundamental factor analysis. It looks like a great guide on how to perform such research/analysis. I might create a video on this in the future.
2
Henry Kwek
324 Pro
,
Hi Louis,
Thanks for the video and the strategy. Great stuff. If I want to do weekly rebalancing instead of monthly, what do I need to change
I believe I need to change the timedelta to 7 days from 31 days: (i.e. self.period = timedelta(7) ) within the main.py function. How should I amended correctly the AlphaModel.py function below?
# Return no insights if it's not time to rebalance if algorithm.Time.month == self.lastMonth: return [] self.lastMonth = algorithm.Time.month
Appreciate your kind advice !
1
Edited by Henry Kwek
Louis
141.8k Pro
,
Hi Henry,
Thanks for the comment. The timedelta that is saved into the period variable is used as a time-frame for the insights. If you want weekly rebalancing, it does make sense to change that from 31 to 7 days.
For weekly rebalancing, you could adjust the if statement as follows:
if self.Time.strftime("%V") == self.lastWeek:
# not time for rebalancing
# Else reassign the week variable
self.lastWeek = self.Time.strftime("%V")
I'm wondering in your forcing the rebalancing to monthly, one day only with the little time trick you do:
will the market orders actually clear etc. intra day? Are there any risks of this - else I guess one would end with orders that aren't executed until the next month?
as far as I remember there is an initialisation setting to hold securities for a minimum of T time (unless risk model kicks in); I'd like to implement that in your algo but I can't find the documentation for this setting; do you know about it?
This way the “scanning” of the universe could be done daily (finding rough diamonds during 30 days rather than 1 days) meanwhile the rebalancing would be done per security only if the security has been held. a minimum e.g. 30 days, so as to give it a time chance to proof itself.
0
Louis Szeto
STAFF Pro
,
Hi Bernino
will the market orders actually clear etc. intra day? Are there any risks of this - else I guess one would end with orders that aren't executed until the next month?
Since the insights are active for 31 bars (31 days in here), the algorithm will try to attain the set % of the portfolio from the insight weight throughout this 31 bars' period. This will be check and adjusted every rebalancing period of the Portfolio Construction Model (default as daily). So no matter did the order got filled on today or not, the algorithm would place/re-place order to attain the target on tomorrow.
as far as I remember there is an initialisation setting to hold securities for a minimum of T time (unless risk model kicks in); I'd like to implement that in your algo but I can't find the documentation for this setting; do you know about it?
Our fellow staff Varad has answered in this thread.
Best Louis Szeto
0
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.
I went through the code line by line to understand its mechanics in detail. I am just wondering one minor thing: In the AlphaModel in these lines
for symbol,value in quality_scores.items():
quality_rank = value
value_rank = value_scores[symbol]
size_rank = size_scores[symbol]
scores[symbol] = quality_rank*self.quality_weight + value_rank*self.value_weight + size_rank*self....
are the quality_rank / value_rank / size_rank variables really RANKS or SCORES? I understand the Scores() function to return score values (floats) per symbol. Sorry if I am overly accurate I am just trying to really understand…
Thx for any clearification, cheers,
George
0
Derek Melchin
STAFF Pro
,
Hi George,
The quality_rank variable represents the weighted rank of the security's quality factors, relative to the other securities in the universe. The value_rank and size_rank variables also represent the weighted rank, but on the value and size factors, respectively. In the alpha model, we see
for tup in fundamentals:
sortedBy.append(sorted(added, key=tup[0], reverse=tup[1]))
for index,symbol in enumerate(sortedBy[0]):
rank[0] = index
for j in range(1, length):
rank[j] = sortedBy[j].index(symbol)
score = 0
for i in range(length):
score += rank[i] * weights[i]
scores[symbol] = score
For example, say there are 200 securities in the universe. If one security has the highest gross margin, highest quick ratio, and lowest debt to assets ratio in the universe, it will have the lowest quality_rank.
Best, Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
0
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.
What confuses me is the term RANK. A rank, at least for me, is 1st, 2nd, 3rd… i.e. it's integers. That's also how it's used in the code you quoted. However in this code here
for symbol,value in quality_scores.items():
quality_rank = value
we iterate through the scores. A score can be a float with weights etc., whereas a weighted rank doesn't make sense to me. That's why I was wondering if it should rather be quality_score instead of quality_rank. But I maybe mistaken…
Thx
0
Derek Melchin
STAFF Pro
,
Hi George,
I call it a “weighted rank" because the value of quality_rank is a function of the security rank for a factor and the corresponding weight of that factor.
score += rank[i] * weights[i]
The quality_rank, value_rank, and size_rank values are not all integers like 1, 2, 3, etc, but the variable names that we use to reference these are arbitrary.
Best, Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
0
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.
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.
Loading...
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!