Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetOptionChain - missing implied volatility? #224

Closed
romanlelek opened this issue Apr 4, 2018 · 11 comments
Closed

GetOptionChain - missing implied volatility? #224

romanlelek opened this issue Apr 4, 2018 · 11 comments

Comments

@romanlelek
Copy link

romanlelek commented Apr 4, 2018

Hi,

I have a question, why in function getOptionChain() is missing a column with implied volatility? For example:

(option_chain_AAPL <- getOptionChain("AAPL"))
#                     Strike  Last        Chg   Bid   Ask Vol   OI
# AAPL180413C00135000  135.0 43.85  0.0000000 31.50 35.50   9   12

But when I have a look on web:
https://finance.yahoo.com/quote/AAPL/options?p=AAPL
I can see:

Contract Name | Last Trade Date | Strike | Last Price | Bid | Ask | Change | % Change | Volume | Open Interest | Implied Volatility

Is it possible to add this column too?

Update: I have added the column on my end v, but I think that others would be interested too.

Thank you.

Best regards,
Roman

@joshuaulrich
Copy link
Owner

I had purposefully left out the implied volatility column because it's my opinion that you should calculate it yourself rather than assume Yahoo's calculation is relevant for your situation.

Even though I still have that opinion, it probably makes more sense to just return the data as Yahoo sends it. Thoughts?

@romanlelek
Copy link
Author

romanlelek commented Apr 19, 2018

Yeah, in fact, I am calculating implied volatility by myslef, but I would like to compare it against implied volatility from Yahoo.

Today, I have discovered strange behaviour with function getOptionChain:
I would like to get optionChain for this date range - "2018-04-19/2018-07-18"

test1<-getOptionChain("PFE", "2018-04-19/2018-07-18")
test2<-getOptionChain("SPY", "2018-04-19/2018-07-18")

test1 result is as expected - data frame with various expiration dates
test2 shows Error in open.connection(con, "rb") : HTTP error 404.

Any ideas why SPY can not open connection? I have tried several tickers and only SPY doesn't work..It looks like that in case SPY, the function has a problem to return more than one expiration...

Best regards,
Roman

@simaan84
Copy link
Sponsor

Hi Josh,

I am have been using the getOptionChain on a recurring basis. However, the package drops information regarding the last trade date. Hence, if I download the data on a daily basis, the date during the data was downloaded can be misleading. I was wondering whether it would be possible to keep track of such info? I would appreciate any feedback on this.

Cheers,
Majeed

@joshuaulrich
Copy link
Owner

Hi @romanlelek, I'm not sure why you would get a 404 error. I wasn't able to try your code when you first encountered the issue, but your second line works now (with updated expiry dates).

Hi @simaan84, what would you think of adding an "updated" attribute to the result, similar to what getSymbols() does with the xts objects it returns?

@romanlelek
Copy link
Author

Hi @joshuaulrich,

well, I have tested it now and it works....strange...maybe Yahoo fixed something on their side. No problem anymore.

Best regards,
R.

@simaan84
Copy link
Sponsor

Hi @joshuaulrich, I will look into this. Cheers

@simaan84
Copy link
Sponsor

I did not get the chance to address above earlier. There seems to be an issue running when it comes to stacking the data in the data.frame
"Error in data.frame(Strike = strike, Last = lastprice, Chg = change, Bid = bid, : object 'volume' not found"

I reckon this has to do with the NewToOld function in the source file. I did some adjustment to the code. It seems to run smoothly now. In addition, I added IV and the full variables in the new edit. Let me know what you think.

simaan84 added a commit to simaan84/quantmod-1 that referenced this issue May 27, 2019
I did some changes to the above. There seems to be a trouble with the NewToOld function. In addition, following issue joshuaulrich#224, I editted the code to have the complete list of the original variables.

For instance, the following code stacks all contracts in a single data.frame
ds <- getOptionChain.yahoo("SPY",NULL)
ds <- lapply(ds, function(ds_i) lapply(1:length(ds_i), 
                                        function(i) data.frame(Type = names(ds_i)[i], ds_i[[i]]))  )
ds <- lapply(ds, function(ds_i) do.call(plyr::rbind.fill,ds_i)  )
ds <- do.call(plyr::rbind.fill,ds)
@hg2581
Copy link

hg2581 commented May 31, 2020

I am using the current version in CRAN and just ran into these two problems:

SPY0529<-getOptionChain("SPY", NULL)
Error in data.frame(Strike = strike, Last = lastprice, Chg = change, Bid = bid, :
object 'bid' not found
and
VIX0529<-getOptionChain("^VIX", NULL)
Error in data.frame(Strike = strike, Last = lastprice, Chg = change, Bid = bid, :
object 'ask' not found
Not sure what the reason might be?

@joshuaulrich
Copy link
Owner

@hg2581 I wasn't able to replicate that error, so I assume it was a temporary issue with Yahoo.

I just noticed that #304 was a duplicate of this one, and it has been closed as fixed. So I'm going to close this one too, since it is no longer an issue.

@joshuaulrich
Copy link
Owner

There seems to be an issue running when it comes to stacking the data in the data.frame
"Error in data.frame(Strike = strike, Last = lastprice, Chg = change, Bid = bid, : object 'volume' not found"

@simaan84, this was reported in #299 and fixed in #300, both by @jrburl.

@joshuaulrich
Copy link
Owner

@hg2581 the 'bid' and 'ask' errors were fixed by @jrburl in #302.

@joshuaulrich joshuaulrich added this to the Release 0.4.18 milestone Nov 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants