At the moment, there are daily and hour avaiable, how to create different resolution. Thank you
public override void Initialize()
{
UniverseSettings.Leverage = 2.0m;
UniverseSettings.Resolution = Resolution.Hour;
SetStartDate(2015,1,15);
SetEndDate(DateTime.Now.Date.AddDays(-1));
SetCash(100*1000);
Alexandre Georges
Hi there,
I have the same issue than OuYangFeng, I would like to have a different resolution: 1 year in my case. After looking into the code, it does not seem to be possible to override the resolution easily since it is an enumeration and it is a parameter of the AddSecurity method...
That would be really nice to be able to customize the resolution and define it with more granularity.
Jing Wu
The data in universe selection (coarse universe and fine universe) are in daily resolution. Therefore, when you use
AddUniverse(CoarseSelectionFunction, FineSelectionFunction);,
CoarseSelectionFunction and FineSelectionFunction are set to default to run once a day (Running them on a lower resolution wouldn't change the filter result as the price, volume data in CoarseSelectionFunction and fundamental factor data in FineSelectionFunction are all daily data). After the universe selection, The data of symbols returned by FineSelectionFunction or CoarseSelectionFunction will be subscribed in OnData() based on the UniverseSettings
UniverseSettings.Resolution = Resolution.Hour;
That is to say, you can not use the price data of lower resolution than daily to filter stocks in universe selection but you can use the lower resolution to further screen stocks from the results returned by universe selection in OnData().
A reasonable way to use universe selection API would be trimming the result set down using coarse selection and using the hourly/minute price data in OnData(). You should be wary of large requests though, once you get over about 120K data points you'll run into timeout issues.
For higher resolution universe selection like monthly, quarterly or yearly, it would be easy to use the scheduled event API to run universe selection. Here is an example
Alexandre Georges
Thanks a lot, this is really helpful. I ended up using a similar implementation but I made a few mistakes.
I used the `OnSecuritiesChanged` method to have the delta (so I can know which stocks I should buy/sell) but it does not work well in this case. When the universe returns a different list of symbols `OnSecuritiesChanged` tries to remove the stocks I am invested in. I attached an example, the docs go quickly over this aspect. Basically, it is going to buy my stocks the first day and liquidate them the 2nd day because the new list is empty.
So it seems like `OnSecuritiesChanged` has been designed and should be used only when the user wants to trade at the same resolution than the universe.
Also when making this example, I noticed something a bit odd, AAPL works great but VZ ends up with a different symbol (BEL) in the logs when buying and selling. Not sure why.
Alexandre Georges
The 2nd issue I have is when the universe refreshes, markets seem to be closed (at 12AM). So the orders end up being MarketOnOpen orders. In this case, I try to allocate all the portfolio's money, so I divide my cash by a number of positions. Now correct me if I am wrong: the positions sometimes fail because the number of shares is calculated according to the price of the stock when the universe selection was done. However the price when the market opens will likely be different. So if the price goes up too much I don't have enough money to buy the number of shares calculated the day before.
Not sure how to solve this issue.
Hope this helps.
Jing Wu
"OnSecuritiesChanged" reflects the added and removed symbols from the coarse and fine universe selection. As coarse and fine universe selection are set to run on the daily basis by default, the added symbols in "OnSecuritiesChanged" are symbols returned by the fine selection. The removed symbols are symbols returned by the fine selection in the previous day but not selected in today's fine list. Data for "changes.RemovedSecurities" will be unsubscribed and "changes.RemovedSecurities" will be subscribed in the OnData().
"Debug(security.Symbol)" prints the string of the symbol object. To get the string ticker, you should use "Debug(security.Symbol.Value)".
To avoid such invalid orders, you can save the added and removed securities and move the SetHoldings() to OnData() and avoid placing orders at 00:00 (if Time.Hour !=0 && Time.Minute != 0) or you can set a higher leverage to allow more margin available.
F
Hey Jing,Â
About this:
"CoarseSelectionFunction and FineSelectionFunction are set to default to run once a day (Running them on a lower resolution wouldn't change the filter result as the price, volume data in CoarseSelectionFunction and fundamental factor data in FineSelectionFunction are all daily data)...."
I was under the impression of that as well... however adding a print statement of my list of tickers in the logs inside of the universe selection function, it only shows up in the logs at the very beginning once (instead of each day) and the universe doesn´t change throughout my entire algo...
This is taken from one of the tutorials.. my goal is to plot the minimum & maximum "breakpoints" for the P/B Ratio which determine whether a stock is in the "value" portfolio or not. But as you can see these breakpoints are constant, which means the universe is not being updated.
Apreciate your help! Thank you
Jack Simonson
Hi F,
What was happening was that the rebalancing schedule wasn't functioning as intended. Universe Selection gets updated before Market Open, and since the rebalance boolean was being set True after Market Open, it would go inside the code in OnData and then reset the rebalance boolean to False. This meant that the Universe was being told to never rebalance. I've made a couple of changes and attached a shortened backtest that force the Universe to update monthly and you will see that the breakpoints and Top/Bottom PB Symbols change in value.
OuYangFeng
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!