How to use R and Quantmod to Tackle Options Trading (2024)

COVID-19 Has Reshaped Investing Strategies

Warren Buffet always preached the principle to “buy low and sell high”, but the biggest issue is timing the market and knowing what will happen to stocks. Unless you are privy to insider information and participate in illegal stock trading activity, your only clear sign to buy low and sell high is when a recession plagues the country.

In March 2020, many felt the effects of the stock market drop in their retirement and other investment accounts. Some had taken the opportunity to put any extra money into their accounts, knowing that one day their portfolios would bounce back and they would have made more money from the market.

But what if there were a way to truly maximize gains in extremely short amounts of time?

2020 has presented the opportunity to dive more into Stock Options Trading.

How to use R and Quantmod to Tackle Options Trading (2)

From Investopedia: “A stock option gives an investor the right, but not the obligation, to buy or sell a stock at an agreed upon price and date. There are two types of options: puts, which is a bet that a stock will fall, or calls, which is a bet that a stock will rise. “

When the market dropped, people were selling like mad, but wise investors looked at the future, and new the market would bounce back. They could have bought calls of stock options for a few months out, bet that the market would bounce back, and sell that option at a much higher price than they bought it at. Instead of paying for stocks that could be in the hundreds or thousands of dollars, they bought options that could range from $1 to $100+, but make more than 100% ROI if their bet pays off.

Since the market has regained much of what was lost, is this strategy still applicable?

The short answer: Yes

First, options trading tends to involve smaller amounts of money than buying actual stocks, therefore it’s a less risky way to invest money. The bets you make on stocks going up or down may not be as radical as they could have been earlier in the year.

Second: We don’t know what’s going to happen next. We don’t know how economies are going to react in the coming months, and big events are happening at the end of the year, including a presidential election. There are other opportunities for the market to jump or fall.

Linked above are some resources that go into more detail about what options are and how they work. My question was: can you use options trading to make money at higher-than-standard rates?

Quantmod has a beautiful wrapper to collecting Yahoo Finance Data, including historical price data and options prices for both calls and puts. A simple call to get AAPL options info is:

getOptionChain(“AAPL”)

That’s all fine and dandy, but what if you want to loop through all stocks and find really good deals on options? A simple loop can suffice. Quantmod automatically loads in the TTR package to get stock symbols.

library(quantmod)# Get all stock tickerssymbols <- stockSymbols() # From the TTR Package
symbols <- symbols$Symbol
myList <- list()
# Get Optionsfor(i in 1:length(symbols) { temp <- getOptionChain(symbols[i]) myList[[i]] <- temp}

With a list of 6,000+ tickers to loop through, this can take a little bit of time and will need some statements like tryCatch() to do some error checking, but it will put all of the data into a massive list.

You can then loop through the data to get everything into two big dataframes: one for calls and one for puts:

calls <- data.frame()puts <- data.frame()for(i in 1:length(myList)) { callTemp <- myList[[i]]$calls putsTemp <- myList[[i]]$puts calls <- rbind(calls, callTemp) puts <- rbind(puts, putsTemp)}

After that, you can filter the “Ask” prices of either the calls and puts to whatever you’d like.All that’s left is to examine the list of options, expiration dates, and historical data to see which ones may be the best deal/least risky for you!

Here you can find my entire R script, which I have automated to run daily thanks to cron jobs in Linux — my approach was to loop through all stocks and get their historical prices, and see which stocks either jumped or dropped 10% in a day, 15% in a week, or 25% in a month. From there, I looped through to collect all options they had where the Ask and Last prices were under $0.50, and pushed everything into a master dataframe. I added the option in my personal code to export the data to an excel doc and email it to myself and a friend everyday at 6am.

Whatever you do, decide on a strategy that you’d like to play with. Be wise with your money, and I wish you luck in your investing endeavors!

How to use R and Quantmod to Tackle Options Trading (2024)

FAQs

How do you handle volatility in options trading? ›

Here are some things to consider when trading options and futures in volatile markets:
  1. Hedging. One way to manage risk in volatile markets is to use options and futures contracts to hedge your portfolio against potential losses. ...
  2. Stay informed. ...
  3. Adjust positions. ...
  4. Stop-Loss Orders. ...
  5. Diversify. ...
  6. Stay calm.

What is the best option strategy for range bound options? ›

Effective Strategies for Trading Range-Bound Securities

Once the range, or price channel, is established, the simplest trading strategy is to buy near the support level and sell near the resistance. Alternatively, when trading options, one could purchase calls near support, and purchase puts near resistance.

How do you trade options efficiently? ›

  1. How to Trade Options in 5 Steps.
  2. 1.Assess Your Readiness.
  3. 2.Choose a Broker and Get Approved to Trade Options.
  4. 3.Create a Trading Plan.
  5. 4.Understand the Tax Implications.
  6. 5.Continuous Learning and Risk Management.
  7. Buying Calls (Long Calls)
  8. Buying Puts (Long Puts)

How do you use RSI in options? ›

These are the rules for opening positions based on the RSI signals:
  1. If the indicator's line crosses the level 70 from above, a short position (Sell) is opened.
  2. If the indicator's line crosses the level 30 from below, a long position (Buy) is opened.

Why sell options when volatility is high? ›

Option traders typically sell, or write, options when implied volatility is high because this is akin to selling or “going short” on volatility. Likewise, when implied volatility is low, options traders will buy options or “go long” on volatility.

What is the best option strategy for low volatility? ›

When you discover options that are trading with low implied volatility levels, consider buying strategies. Such strategies include buying calls, puts, long straddles, and debit spreads. With relatively cheap time premiums, options are more attractive to purchase and less desirable to sell.

What is the 3 30 formula in options trading? ›

The 3-30 rule in the stock market suggests that a stock's price tends to move in cycles, with the first 3 days after a major event often showing the most significant price change. Then, there's usually a period of around 30 days where the stock's price stabilizes or corrects before potentially starting a new cycle.

What is the most consistently profitable option strategy? ›

The most successful options strategy for consistent income generation is the covered call strategy. An investor sells call options against shares of a stock already owned in their portfolio with covered calls. This allows them to collect premium income while holding the underlying investment.

What is the 1 1 2 option strategy? ›

As the name suggests, the 1–1–2 options strategy consists of three distinct options positions: One long put. One short put. Two additional short puts.

Which timeframe is best for option trading? ›

Ans: The appropriate time frame for options trading depends on your purpose and research of the trade. However, a range of 30-90 days can be a good time frame for most trades.

Which indicator has the highest accuracy? ›

Which is one of the most accurate trading indicators? The most accurate for trading is the Relative Strength Index. It is considered one of the best momentum indicators for intraday trading. It helps investors identify the shares which are bought and sold in the market.

What is the RSI 5 strategy? ›

Specifically, it recommends using RSI with a period of 5 (RSI(5)) and using a crossover of the 20 level as a signal to buy or average into a position. When RSI(5) dips below 20 and crosses back above 20, this indicates an uptrend reversal that is a good opportunity to enter or average into a long position.

What is the best time to trade in options? ›

Trading at the Opening of the Market

Hence, this makes the time frame between 9:30 am to 10:30 am the ideal time to make trades. Intraday trading in the first few hours of the market opening has many benefits: – The first hour is usually the most volatile, providing ample opportunity to make the best trades of the day.

How to maximize profit with options? ›

The key to this trade is timing. The best time to enter the trade is when the market is relatively flat, and there is not much movement in either direction. This setup will allow you to buy the options with the lower strike price at a cheaper price and sell the options with the higher strike price for a higher price.

Which indicator is best for option trading? ›

Best Option Trading Indicators
  1. Automatic Demand and Supply Indicator by GTF: The Automatic Demand and Supply Indicator by GTF is developed by GTF a stock market institute, which is one of its kind indicator. ...
  2. Volume profile. ...
  3. RSI( Relative Strength Index) ...
  4. Ichimoku Cloud. ...
  5. Fibonacci retracement.
Aug 1, 2023

Why is options trading difficult? ›

Mathematics: Options trading involves complex mathematical calculations, such as determining potential profits and losses at different points, calculating breakeven points, and understanding the impact of changes in volatility on option prices. Volatility: Volatility can greatly influence option prices.

Top Articles
Latest Posts
Article information

Author: Barbera Armstrong

Last Updated:

Views: 6371

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Barbera Armstrong

Birthday: 1992-09-12

Address: Suite 993 99852 Daugherty Causeway, Ritchiehaven, VT 49630

Phone: +5026838435397

Job: National Engineer

Hobby: Listening to music, Board games, Photography, Ice skating, LARPing, Kite flying, Rugby

Introduction: My name is Barbera Armstrong, I am a lovely, delightful, cooperative, funny, enchanting, vivacious, tender person who loves writing and wants to share my knowledge and understanding with you.