How to calculate rewards APY on Avalanche and Optimism Markets

I am doing a research project to study the historical APY for suppliers on Aave. I have been able to calculate historical supply APY from log events pretty well, however I am struggling to calculate the APY for rewards distributed on Avalanche and Optimism. I have been scouring the docs to find how the Reward APY on the website is calculated and cannot find anything. I was wondering if there is a way to calculate Rewards APY, ideally from log events?

Any information would be greatly appreciated!