Hello,
I am trying to implement a strategy using the pe ratio of a stock compared to the average pe ratio of stocks in the same sector. How would I find the average pe of a sector?
My code is currently:
universe = monthly_top_volume & base_universe
# Alpha Generation
# ----------------
# Compute Z-scores of free cash flow yield and earnings yield.
# Both of these are fundamental value measures.
vr = mstar.valuation_ratios
#fcf_zscore = vr.fcf_yield.latest.zscore(mask=universe)
#yield_zscore = vr.earning_yield.latest.zscore(mask=universe)
pe = vr.pe_ratio
sent_factor = sentdex.sentiment_signal.latest
**sector_pe = mstar.asset_classification.morningstar_sector_code.vr.pe_ratio.latest(mask=universe)**
score = compute_score(pe, sector_pe, sent_factor)