Back

Questions about Historical Fundamentals in FineSelection: Need Help to Translate Quantopian Code

I don't know how I can get historical fundamental data and compare today's fundamental to last year's fundamental in FineSelectionFunction. For example, my strategy is as follow:

I'd like ROA today to be greater than ROA last year. If so, I'd add one score to the equity. And then, equites with highest score would be chosen. 

Next, I try to get recent several quarters' ROE and take an average and sort by the average ROE.

In Quantopian, I can do this by Pipeline as below:

class Previous(CustomFactor):
def compute(self, today, asset_ids, out, inputs):
out[:] = inputs[0]

class TargetScore(CustomFactor):
inputs = [
morningstar.operation_ratios.roa,
]
def compute(self, today, asset_ids, out, roa):
score = np.zeros(roa.shape[1])
score += roa[-1] > roa[0]
out[:] = score

def make_pipeline():
score = TargetScore(window_length=252)
score_filter = (score>=1)

roe = morningstar.operation_ratios.roe.latest
roe_last_qtr = Previous(inputs = [morningstar.operation_ratios.roe], window_length = 63)
roe_last_2_qtr = Previous(inputs = [morningstar.operation_ratios.roe], window_length = 63*2)
roe_last_3_qtr = Previous(inputs = [morningstar.operation_ratios.roe], window_length = 63*3)

avg_roe = (roe + roe_last_qtr + roe_last_2_qtr + roe_last_3_qtr)/4

return Pipeline(
columns={
'avg_roe':avg_roe
},
screen = (score_filter)
)

How can I do the same thing in Quantconnect? I noticed some functions like RollingWindow can store previous values for me. But in my case, shouldn't I wait for 252 days before the algorithm works? It's Okay in case of backtesting. But I'd like to put this strategy to live mode. Should I wait 252 days as well before I can trade in live?

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 Ken,

When backtesting with QC, fundamental data is provided in universe selection. Currently, universe selection is not performed during warm-up periods. So by default, an algorithm like this would be required to wait 252 days before trading. As a workaround, some users store historical universe selection values in the ObjectStore.

In regards to translating this algorithm to work with our API, a good place to start is this discussion thread. Then I recommend reviewing our Bootcamp lessons on backtesting with fundamental data and rolling windows. Reviewing our documentation is also a good idea as it contains thorough information and many example algorithms.

Best,
Derek Melchin

1

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.


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