joshuaulrich / quantmod

Quantitative Financial Modelling Framework
http://www.quantmod.com/
GNU General Public License v3.0
798 stars 219 forks source link

Add orats source for getOptionChain() #325

Closed SteveBronder closed 3 years ago

SteveBronder commented 3 years ago

Adds orats as a backend for getOptionChain(). The orats API has a lot of useful features including greek calculations for each option. Users with an API key provided by orats can now use src="orats" to get access to the orats options data

I'm opening this now but this still needs tests. But before I write those I wanted to discuss the return of the function as some things differ for the orats source.

  1. First, the orats API does returns Near End of Day options data, about 15 minutes before close. So data from yahoo and orats will most likely differ. Discussing this with the orats folks it is because options spreads can get kind of wacky very close to the close so it's more representative of the day to get them a little before close.

  2. They don't provide a last sold price (unless I'm reading the column definitions from here wrong and it's actually there). So this column does not exist. Is that alright? I could also just make a column of NA values here and make a note to users about that in the docs.

  3. On weekends it seems like they actually still return that fridays options that expired as the most recent. Honestly I'm not sure about the intricacies of options execution so it's unclear to me whether we should return what yahoo returns for an API call on a weekend (the options that expire next week) or the friday options orats returns.

  4. Because their API allows for multiple tickers the data in each data.frame of the list I return has a column Ticker. imo I like this over a list of list of list approach for multiple dates/tickers but I'm open to whatever here.

  5. Their API returns a lot of neat things. I tried making call and put as close as possible to the yahoo return, and then added a call/put_extra as well as extra data frames that are returned containing the extra information like greeks etc. How would you feel about a format argument with values like "standard" for the standard format and "raw" for returning back what their API returns?

joshuaulrich commented 3 years ago

Thanks for the contribution! Sorry it took so long to merge... Note that I moved the new source to it's own file. I know getSymbols has everything in one file, but I don't like that...

SteveBronder commented 3 years ago

Oh awesome! Yes that's totally fine, I'll take another look at this during the week and add some unit tests as well if you'd like. They have a demo api we should be able to use for the unit tests

joshuaulrich commented 3 years ago

Unit tests are always welcome!