Home > other >  Subsetting Puts from getOptionChain in Quantmod
Subsetting Puts from getOptionChain in Quantmod

Time:11-08

The result of running the getOptionChain is a list of symbols that includes both Calls and Puts.

I would like to subset the data and create a dataset that will include only the Puts.

This is the code I'm running to get the option chain. Now I need to subset and create a new dataset only for Puts.

library(quantmod)
Symbols<-c  ("AA","AAL","AAOI","ABBV","ABC","ABNB")
Options.20221111 <- lapply(Symbols, getOptionChain)
names(Options.20221111) <- Symbols

What is the best approach to get the Puts alone?

CodePudding user response:

When working with lists, lapply is your friend.

only_puts_list <- lapply(Options.20221111, function(x) x$puts)

This will create a list with only the puts in there.

  • Related