Industry as a feature

When developing our strategy for portfolio selection, are we allowed to use the firm’s corresponding industry as a feature in our model? Or in other words, can we pass in a dataframe containing each firm’s corresponding industry into our payoff function as second argument?

Yes you are allowed to use all data provided in the getTickersSP500 function. You can check on https://qlib.alphien.com/qlibv4/RFunctionEditor for equalWeightSP500Select (direct link : https://qlib.alphien.com/qlibv4/RFunctionEditor?open_functions=equalWeightSP500Select)


The payout has already an industry field - check the examples, you can try in R :


#’ port = portfolio(as.list(unique(getTickersSP500(zoom=“2007::2016”)$ticker))) ## take only the tickers for the period 2007::2016

#’ port = portfolio.addFeatures(port)                      ## add as features all the assets selected in the portfolio (default field is bb live)

#’ port = portfolio.loadData(port, zoom=“2007::2016”)              ## load the returns for the portfolio and the data for the features for the period considered (takes abt 1 min)

#’  

#’ port1 = payout(port, equalWeightSP500Select)                 ## now you add your payout (with your parameters)

#’ port1 = portfolio.eval(port1, payoutWithFeatures=TRUE)

#’ portfolio.print(port1)

#’ portfolio.plot(port1)

#’

#’ port2 = payout(port, equalWeightSP500Select, industry=“Computers & Peripherals”)

#’ port2 = payout(port, equalWeightSP500Select, industry=“Interactive Media & Services”)

#’ port2 = portfolio.eval(port2, payoutWithFeatures=TRUE)

#’ portfolio.print(port2)

#’ portfolio.plot(port2)


and see how an equally weighted basket with different industry would have performed !


Feel free to copy the pay-out and improve it.


Happy coding ! Lionel.