trophy

Long Only, ETF Alpha Streams Competition with $27,500 Prize Pool

Back

Coarse Fine Universe selection - previous quarter

Hello,

I'm trying to get the Fine selection to return symbols that has had positive EPS for previous 8 quarters. I know this is possible, but cannot find example or explaination on how to accomplish that beyound QC500 universe which does not check data for previous periods. Example would be very much appreciated!

Greetings,

Paweł

 

Update Backtest







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.


Hi Pawel,

In fine selection, we could access fundamental data which has ~900 tracked fields. Here is an example with selecting symbols with positive BasicEPS in past twelve months(the longest supported period for this field).

Hope it helps!

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.


Hi Link,

Thanks for your input. I also love how easy it is to attach backtest code to the post so there is substance to the conversation.

My algorithm relies on selection of companies that had consecutive positive EPS. For example such company that for each and every one of the previous 8 quarters the EPS > 0.

I was hoping that Algorithm Lab's Morningstar fundamentals would do it for me. After all, the actual data is there. After I realized that this is not currently possible with Coarse/Fine Universe Selection and I do not have any idea when this feature will get implemented except that probably 'not soon' and not feeling like having particular impact on the timeline of implementation of this feature, I have started looking for alternate data source for Fundamentals. With that I would code a custom/scheduled universe based on the 3rd party fundamentals data.

That being said, I am still leaning towards using the Algorithm Lab over "my own" instance of Lean. There are many reasons more than Morningstar's fundamental data availability, but this is subject for another conversation I think. So, this is where I am now.

Greetings,

Pawel Kowalke

 

0

Hi Pawel,

Here is my attempt to select tickers which keeps consecutive positive EPS in last two years. I used a flag named self.update to ensure the universe selection runs once every quarter, and use a rolling window for each symbol to store the EPS record for past two years, return the ones who have all 1's in their rolling window (meaning they have positive EPS in all past 8 quarters).

The main problem could be, fundamental data could only be accessed in fine selection, and it might not be compatible with your whole strategy. Moreover, since it requires a lot of data (fundamental data for all tickers that we offer, with time range of years), the selection process itself could be slow. You might want to add some logic in coarse selection to reduce the amount of work in fine selection.

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.


Hi Link,

I can't even begin to say how happy I am that you have come up with this genius scheme! :) It is genius in its simplicity! :)

Just one 'but' - I need help understanding what we are doing, because I am not fully proficient in Python language. I meant to learn Python so I can use the awesome QuantConnect features that require the knowledge of Python, just never got to it. Yet. Anyhow.

So, The whole premise of your solution working correctly is that the Fine universe selection will run during the warmup period the same as during the 'normal part' of the algorithm run? To be honest, I have tried similar approach and got discouraged by posts in this forum stating that the warmup period does not work with Fine universe selection. Let me just say that the Fine universe selection working together with warmup is a huge deal for me!

Kindly,

Pawel Kowalke

0

Hi Link,

Took a liberty of modifying your backtest to prove that unfortunately it is true. The warmup period does not work with Coarse/Fine selection. Please, see for yourself. I've added log statements in the coarse/fine functions and the logging starts on the day of the algorithm main run, bypassing the days of the warmup.

Anyhow, appreciate your reply and really, really nice try.

Greetings,

Pawel

0


Link to forum post that I was refering to (warmup and coarse/fine selection don't work together for now)

https://www.quantconnect.com/forum/discussion/4952/get-historical-fundamental-data-in-algorithm/p1

 

0

Hi Pawel,

I apology to write the algorithm in wrong language. Here is the C# version. I've fixed a bug of myself: when we are not doing the selection, we should return the result from the previous selection instead of an empty list.

Regarding warm up: you are right, unfortunately currently universe selection is not triggered during warmup. So I deleted that statement.

namespace QuantConnect.Algorithm.CSharp
{
public class NadionCalibratedReplicator : QCAlgorithm
{
bool update;
Dictionary<Symbol, RollingWindow<int>> rw;
List<Symbol> symbols;
public override void Initialize()
{
SetStartDate(2014, 11, 27); //Set Start Date
SetEndDate(2018, 12, 20);
SetCash(100000); //Set Strategy Cash

UniverseSettings.Resolution = Resolution.Daily;
update = false;
rw = new Dictionary<Symbol, RollingWindow<int>>();
symbols = new List<Symbol>();
SetUniverseSelection(new FineFundamentalUniverseSelectionModel(CoarseSelectionFunction, FineSelectionFunction));

}

public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
{

if (Time.Month % 3 != 0){
update = true;
}

if ((!update) || (Time.Month % 3 != 0 )){
return symbols;
}
symbols = new List<Symbol>();

// pass all tickers with fundamental data to fine selection
var filtered_coarse = coarse.Where(x => x.HasFundamentalData);
return filtered_coarse.Select(x => x.Symbol);
}


public IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine)
{
if ((!update) || (Time.Month % 3 != 0 )){
return symbols;
}
var selected = new List<Symbol>();

foreach(FineFundamental f in fine){
if (!rw.ContainsKey(f.Symbol)){
rw[f.Symbol] = new RollingWindow<int>(8);
}
if (f.EarningReports.BasicEPS.ThreeMonths > 0){
rw[f.Symbol].Add(1);
}
else{
rw[f.Symbol].Add(0);
}
if (rw[f.Symbol].IsReady && rw[f.Symbol].Sum() == 8){
selected.Add(f.Symbol);
}
}

update = false;
symbols = selected;
return symbols;
}

}
}

 

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.


Hi Link,

I must say this is really nice and in c# and works with backtesting (as in backtesting you can afford to simply move the startdate 8 quarters towards the past without the need to rely on warmup)

On my end, I am seriously considering modifying my strategy to not need 8 quarters back (in version 1.0), so I can go live!

Greetings,

Pawel

0

Update Backtest





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.


Loading...

This discussion is closed