I'm making an algorithm that takes p/e ratio into account. To do this, I need to give it perspective of the entire sector's p/e ratio. Is there a source of historical sector wide p/e ratio averages? If not, how could I calculate it using the p/e ratio of individual stocks? Any help would be appreciated.