Home > other >  Filtering strikes and premiums from getOptionChain results
Filtering strikes and premiums from getOptionChain results

Time:04-07

I'm running the following code which works correctly:

library(quantmod)
Symbols<-c  ("AA","AAL","AAOI","ABBV","ABC","ABNB","ABT","ACAD","ACB","ACN",
     "ADBE","ADI","ADM","ADP","ADS","ADSK","AEO","AFL","AFRM","AAPL",
     "XOM","MSFT","JNJ")
Options.20220408 <- lapply(Symbols, getOptionChain)
names(Options.20220408) <- Symbols

I'd like to know how to create a new dataset, that contains only puts, and by defining a premium range value (premium_range) filter which strikes are offering puts premium with a value previously defined (premium_range)

For example I'd to know which Strikes for puts are offering a premium between (0.8 and 1.2)

premium_range <-(>= 0.8 ,<=1.2)

The desired result is to know which tickers and its strikes are currently offering a premium between the specified value in the (premium_range)

For getting the premium value filtered, I'm thinking in the column "Last" but maybe the "Ask" column would work as well.

CodePudding user response:

A shortened example with the selection done on the ask price. I just printed it to the console, but you can save the results in a list if you want to.

library(quantmod)
Symbols<-c  ("AA","AAPL")
Options.20220408 <- lapply(Symbols, getOptionChain)
names(Options.20220408) <- Symbols


premium_range <- c(0.8, 1.2)

lapply(Options.20220408, function(x) subset(x$puts, x$puts$Ask >= premium_range[1] & x$puts$Ask <= premium_range[2] ))

$AA
                  Strike Last        Chg  Bid  Ask Vol  OI       LastTradeTime        IV   ITM
AA220408P00086000     86 0.90 -0.6500000 0.73 0.87  32 421 2022-04-06 11:50:01 0.5693402 FALSE
AA220408P00087000     87 1.06 -0.8100001 1.06 1.17 222 195 2022-04-06 12:07:18 0.5625044 FALSE

$AAPL
                    Strike Last  Chg  Bid  Ask   Vol    OI       LastTradeTime        IV   ITM
AAPL220408P00170000    170 1.12 0.74 1.11 1.12 75129 32287 2022-04-06 12:08:36 0.2539137 FALSE
  • Related