quantmod 3d graphics - r

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"])

Related

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

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.

Problems with getMgmtDisc (from edgar): "no filing information found" or "object ´words.count´ not found"

I am unfortunately working with R for the first time and I am having a problem with the package "edgar".
My code is as follows:
Normal:
MgmtDisc <- getMgmtDisc(cik.no = c(1390777, 1077771, 70858, 1409775, 821127,
1049782),
filing.year = c(2016, 2017, 2018))
or
With a loop:
cik_vector <- c(1390777, 1077771, 70858, 1409775, 821127, 1049782)
years <- c(2016, 2017, 2018)
for (i in seq_along(cik_vector)) {
for (j in seq_along(years)) {
print(i)
MgmtDisc <- getMgmtDisc(cik.no = cik_vector[i],
filing.year = years[i])
}}
I am trying to pull the 10-K filings from the SEC via the edgar package. More specifically, I would like to get the Management Discussion and the Business Describtion. So on the one hand I use the formula getMgmtDisc and getBusinDescr. However, for both of them I have two problems.
sometimes the code works and I get the full filings, but sometimes I don't get anything at all, even though I haven't changed anything in the code and just restarted R or similar.
In this case I get the following error message:
No filing information found for given CIK(s) and Form Type in the mentioned year(s)/quarter(s).
No annual statements found for given CIK(s) and year(s).
Although I know this is not true.
if the code for the filings worked then, but sometimes/most of the time I still don't get the management discussion or the business description. Sometimes only for certain years, even though I know they exist for all years. It just changes very randomly.
In this case, the following error message appears:
Error in getMgmtDisc(cik.no = cik_vector[i], filing.year = years[i]) :
object 'words.count' not found
I have tried it with a normal code as well as with a loop. (By the way, is the loop correct?).
Thank you so much for your help!!

Azume ML Cannot Find timeSeries function

I am trying to run an R Script in Azure ML Studio. Unfortunately, I receive the following error:
Error 0063: The following error occurred during evaluation of R script:
---------- Start of error message from R ----------
could not find function "timeSeries"
It seems strange that Azure ML cannot find the function timeSeries as the timeSeries package is installed by default. Here is the proof, you can see that timeSeries is listed.
Here is my code and the Azure diagram. The 1st R script was used to write a CSV of the installed packages (1st Picture). The code in the second R script is displayed to the right of the 2nd picture.
Thanks
The library needs to be loaded as it is an external library
library(timeSeries)
#Map 1-based optional input ports to variables
dataset1 <- maml.mapInputPort(1) #class: data.frame
HOLD <- maml.mapInputPort(2) #class: data.frame
colnames(HOLD) <- c("Dates", "Val")
Daily.TS <- timeSeries(HOLD$Val, as.Date(HOLD$Dates),
format="%Y-%m-%d")

ClusterLongData kml package export to scv

I am clustering time series in R using package KmL. I have read both manual and paper how to use this package, but Im not very clear how to export the results (data frame, where each trajectories are assign to some clusters e.g.
trajectory (i), time1, time2, time3, clustername)
I have read several answers here Output from 'choice' in R's kml
but if I do the same (run choice(myCld, typeGraph= "bmp")) my R says:
~ Choice : menu ~ 'Arrow' : change partition 'Space' : select/unselect a partition ... etc. e : change the display (both)
~ 'Return' when its done ~
And only thing that is saved to my library is myCld.Rdata and it runs for very long time without any more results. (my dataset: N trajectories, with time= 1:53) I want to have csv. files as manual suggest (objectName-Cx-y-Clusters.csv)
I am also not very clear WHERE should I PRESS on "Return" or "Arrow"? There is no option to press on anything in my Rstudio workplace.
I am really a beginner with R so any help would be appreciated. Thanks!
I am not sure that kml is compatible with Rstudio. The older version of Rstudio did not handle instruction like getGraphicsEvent that was used by choice.

How to save Variant Call Format (VCF) file to disk in R using VariantAnnotation Package

I've searched the web for this without much luck. More or less you always get to the example from the VariantAnnotation Package. And since this example works fine on my computer I have no idea why the VCF I created does not.
The problem: I want to determine the number and location of SNPs in selected genes. I have a large VCF file (over 5GB) that has info on all SNPs on all chromosomes for several mice strains. Obviously my computer freezes if I try to do anything on the whole genome scale, so I first determined genomic locations of genes of interest on chromosome 1. I then used the VariantAnnotation Package to get only the data relating to my genes of interest out of the VCF file:
library(VariantAnnotation)
param<-ScanVcfParam(
info=c("AC1","AF1","DP","DP4","INDEL","MDV","MQ","MSD","PV0","PV1","PV2","PV3","PV4","QD"),
geno=c("DP","GL","GQ","GT","PL","SP","FI"),
samples=strain,
fixed="FILTER",
which=gnrng
)
The code above is taken out of a function I wrote which takes strain as an argument. gnrng refers to a GRanges object containing genomic locations of my genes of interest.
vcf<-readVcf(file, "mm10",param)
This works fine and I get my vcf (dim: 21783 1) but when I try to save it won't work
file.vcf<-tempfile()
writeVcf(vcf, file.vcf)
Error in .pasteCollapse(ALT, ",") : 'x' must be a CharacterList
I even tried in parallel, doing the example from the package first and then substituting for my VCF file:
#This is the example:
out1.vcf<-tempfile()
in1<-readVcf(fl,"hg19")
writeVcf(in1,out1.vcf)
This works just fine, but if I only substitute in1 for my vcf I get the same error.
I hope I made myself clear... And any help will be greatly appreciated!! Thanks in advance!
Thanks for reporting this bug. The problem is fixed in version 1.9.47 (devel branch). The fix will be available in the release branch after April 14.
The problem was that you selectively imported 'FILTER' from the 'fixed' field but not 'ALT'. writeVcf() was throwing an error because there was no ALT value to write out. If you don't have access to the version with the fix, a work around would be to import the ALT field.
ScanVcfParam(fixed = c("ALT", "FILTER"))
You can see what values were imorted with the fixed() accessor:
fixed(vcf)
Please report and bugs or problems on the Bioconductor mailing list Martin referenced. More Bioc users will see the question and you'll get help more quickly.
Valerie
Here's a reproducible example
library(VariantAnnotation)
fl <- system.file("extdata", "chr22.vcf.gz", package="VariantAnnotation")
param <- ScanVcfParam(fixed="FILTER")
writeVcf(readVcf(fl, "hg19", param=param), tempfile())
## Error in .pasteCollapse(ALT, ",") : 'x' must be a CharacterList
The problem seems to be that writeVcf expects the object to have an 'ALT' field, so
param <- ScanVcfParam(fixed="ALT")
writeVcf(readVcf(fl, "hg19", param=param), tempfile())
succeeds.

Resources