Now that options data is available at QuantConnect, I was trying to create a log of historical volatility skew for a selected symbol. Here is an example chart of GLD skew based on fixed 90 - 110 moneyness strikes:

Attached is my first attempt to collect the data for a portion of the chart. The code interpolates implied volatilities of the nearest expiration contracts daily at a specific time.

This backtest runs out of memory when processing just 2 months of history ("Memory Usage Maxed Out"); also, it runs quite slowly. I suspect contract pre-filtering and ranking could be done more efficiently. How could this code be optimized for a smaller memory use and a more performant option contract selection?