Here's a suggested approach using TFire's framework:
# 1. Set up collections for different sectors
function setup_sector_collection(tickers, name)
spec = Specification(tickers, Date(2023,1,1), Date(2024,1,1))
collection = setup_collection(spec)
# Add momentum calculation layer
collection.layer_settings_pending[LayerEMA][:win_sizes] = [20, 60]
collection_momentum = add_layer(collection, LayerEMA)
return collection_momentum
end
# Example sector setup
tech_tickers = ["AAPL", "MSFT", "GOOGL"]
finance_tickers = ["JPM", "BAC", "GS"]
tech_collection = setup_sector_collection(tech_tickers, "Tech")
finance_collection = setup_sector_collection(finance_tickers, "Finance")
# 2. Create relative strength comparison
function relative_strength(args)
sector_ma = args[1]
benchmark_ma = args[2]
return sector_ma[end]/sector_ma[end-20] > benchmark_ma[end]/benchmark_ma[end-20]
end
# 3. Create scoring based on relative performance
dv_tech = DVLayerDictKey(tech_collection, :ma_values, 20)
dv_finance = DVLayerDictKey(finance_collection, :ma_values, 20)
# Generate buy signals for outperforming sector
tech_scores = BuyScores(tech_collection, [dv_tech, dv_finance], relative_strength)