Quantmod/getOptionChain Error in .Date(Exp/86400) : could not find function ".Date" - r

I'm getting an error when running getOptionChain from quantmod package.
The code should get Option chain data and subset into a new list that contains only the puts.
The error I get is: Error in .Date(Exp/86400) : could not find function ".Date"
Same code, sometimes runs without error. If I shorten the list of Symbols, there's no error, but the error as far as I know is not related to a specific symbol, because I made to run successfully. Seems random but frequent error.
All symbols are weekly expirations and the desired output is the next weekly expiration, so from my understanding, there's no need to specify a exp date.
library(quantmod)
library(xts)
Symbols<-c ("AA","AAL","AAOI","AAPL","ABBV","ABC","ABNB","ABT","ACAD","ACB","ACN","ADBE","ADI","ADM","ADP",
"ADSK","AEO","AFL","AFRM","AG","AGNC","AHT","AIG","AKAM","ALGN","AMAT","AMBA","AMC","AMD","AMGN",
"AMPX","AMRN","AMRS","AMZN","ANET","ANF","ANY","APA","APO","APPH","APPS","APRN","APT","AR","ARVL")
Options.20221118 <- lapply(Symbols, getOptionChain)
names(Options.20221118) <- Symbols
only_puts_list <- lapply(Options.20221118, function(x) x$puts)

After upgrading to R 4.2.2 the issue is fixed.

Related

Error when running initPortf in Blotter package for R

I am having trouble initializing portfolios with the Blotter Package in R.
I am cycling through a list of variables that I want to initialize, and when I initialize with a single symbol, it works fine.
But when I try to do it with a list of symbols, it throws up the error:
Error in portfolio$symbols[[instrument]] <- new.env(hash = TRUE) :
wrong arguments for environment subassignment
Here is my code:
for (i in strategies) {
temp_symbol_list <- as.list(c(portfolio_txns %>%
filter(strategy == i) %>%
select(symbol)))
# temp_symbol_list <- as.list(temp_symbol_list)
print (i)
print (temp_symbol_list)
initPortf(i, temp_symbol_list,initDate = earliest_date, currency = "CAD")
}
When there is only one symbol in the intialize function, it works fine. But if there are two symbols, I get the error.
I have tried many different ways of creating the symbol list, but I think it is expecting something that I am not able to create.
For example, if I do the following:
initPortf("strategy",c("symbol 1","symbol 2"), initDate = earliest_date,
currency = "CAD")
it works fine.
Somehow, my list is the problem.
I figured it out.
I was created the variable to send to the initPortf as a "list". I changed it to a string and it worked.
Specifically, this is the new line
temp_symbol_list <- toString(temp_symbol_list)
I was confused as the documentation for the Blotter package said it was expecting a list, but I probably don't understand the different types of data storage properly.
I'm leaving this up in case someone else has the same problem.
Big thanks to the folks who wrote these packages btw.

How to fix "unused argument" error message in R studio?

I tried to run my code like I usually do, and I got an "unused argument" error message. I have previously run the code multiple times and everything worked perfectly fine, this is the first time I have gotten an error message (I haven't changed the code). The only thing I've done different is I cleared the workspace at the end of my previous session (though I have no idea if this would actually affect it?).
Below is the code:
pacman::p_load(
rio, # importing data
here, # relative file pathways
janitor, # data cleaning and tables
lubridate, # working with dates
epikit, # age_categories() function
tidyverse, # data management and visualization
skimr,
psych,
reshape2, #for reshaping dataset
dplyr,
miscFuncs,
foreign, #read data formats
rcompanion, # group means
eeptools,
plyr)
mesh_dat <- import(here("R", "BTmeshdata.xlsx"))
The error message:
Error in here("R", "BTmeshdata.xlsx") :
unused argument ("BTmeshdata.xlsx")
The issue seems to be in how the dataset is imported because I have the same issue with importing a dataset from a different project.
.here and my folder "R" are located in my Documents folder.
Thanks!

Fatal error when runing es() function in R

es function in smooth package has a weird behavior for some short time-series. Here is a case:
require(smooth) # version 2.4.7
#create two time series of length 10
vec1_ts<-ts(c(36,24,51,7,7,77,1,29,19,2),start=c(2016,1),frequency=12)
vec2_ts<-ts(1:10,start=c(2016,1),frequency=12)
#this works:
es(vec1_ts)
#but this doesn't:
es(vec2_ts)
# another non-working example with a shorter length
vec3_ts<-ts(c(23,5,4,12,2,5),start=c(2016,1),frequency = 12)
es(vec3_ts)
I got a "R encountered a fatal error" message, and then forced to terminate the session when running es for the second time-series.
This looks like a bug in the function of that package. Can you, please, submit the bug here: https://github.com/config-i1/smooth/issues
The StackOverflow is not for solving problems of specific packages, it is for the solution of more general problems.

Where did the forecast.Holtwinters go in R 3.4.3?

I'm using R Studio based on R 3.4.3. However, when I tried to call the forecast.HoltWinters function, R told me that "could not find function "forecast.HoltWinters"". Inspect the installed package (v8.2) told me that it's true, there is no forecast.HoltWinters. But the manual in https://cran.r-project.org/web/packages/forecast/ clearly stated that forecast.HoltWinters is still available.
I have also tried stats::HoldWinters, but it's working wrong. The code run fine on another computer, but it couldn't run at all on mine. Is there any solution?
Here is the code. Book2.csv has enough data to last more than 3 periods.
dltt <- read.csv("book2.csv", header = TRUE)
dltt.ts <- ts(dltt$Total, frequency=12, start=c(2014,4))
dltt.ts.hw <- HoltWinters(dltt.ts)
library(forecast)
dltt.ts.hw.fc <- forecast.HoltWinters(dltt.ts.hw) //Error as soon as I run this line
Fit a HoltWinters model using the HoltWinters function and then use forecast. Its all in the help for HoltWinters and forecast, namely "The function invokes particular _methods_ which depend on the class of the first argument". I'll copy the guts of it here:
m <- HoltWinters(co2)
forecast(m)
Note this will call the non-exported forecast.HoltWinters function, which you should never call directly using triple-colon notation as some may suggest.

quantmod 3d graphics

I am trying to use the code on the quantmod website for a 3d graph. I followed the instructions and entered the year as 2010 (since 2008 link was not found). However, when I enter this command at the R prompt:
chartSeries3d0(TR)
I get the following error:
Error in if (on == "years") { : missing value where TRUE/FALSE needed
I am relatively new to R, so can anyone help me fix it.
The Treasury has re-designed its website since that example was created, so the code is not downloading any data (no matter what year you enter). Instead of using the getUSTreasuries function, you can just pull the data from FRED.
library(quantmod)
source("http://www.quantmod.com/examples/chartSeries3d/chartSeries3d.alpha.R")
getSymbols("DGS1MO;DGS3MO;DGS6MO;DGS1;DGS2;DGS3;DGS5;DGS7;DGS10;DGS20;DGS30",
src="FRED")
TR <- merge(DGS1MO,DGS3MO,DGS6MO,DGS1,DGS2,DGS3,DGS5,
DGS7,DGS10,DGS20,DGS30, all=FALSE)
colnames(TR) <- c("1mo","3mo","6mo","1yr","2yr","3yr","5yr",
"7yr","10yr","20yr","30yr")
TR <- na.locf(TR)
chartSeries3d0(TR["2011"])

Resources