Analisi citazioni in R: applicazione Quantmod
-
22-10-2019 - |
Domanda
Sto cercando di creare la funzione che fornisce volatilità storica dopo aver ottenuto il simbolo da Yahoo. Tuttavia, quando passo output funzione di volatilità non è così come esso; La variabile Get viene assegnato un vettore con le citazioni, per esempio "Spia", ma la funzione di volatilità richiede solo senza virgolette (SPY no "spia"). Cerco di prendere le citazioni fuori usando noquote () e ora ottenere seguente errore:
Errore nel log (x): argomento non numerico di funzione matematica
Il mio codice
require(quantmod)
vClose = function(X){
Get <- getSymbols(X, from="2000-01-01", src="yahoo")
Set <- noquote(Get)
volatility(Set, calc="close")
}
Qualsiasi aiuto sarebbe grande.
Soluzione
Just set auto.assign=FALSE
in your call to getSymbols
:
require(quantmod)
Get <- getSymbols("SPY", from="2000-01-01", auto.assign=FALSE)
volatility(Get, calc="close")
Altri suggerimenti
noquote()
is not the answer. Instead you want get()
. The following example works, though you might want to change the variable names as get
and Get
can get confused.
require(quantmod)
vClose = function(X){
Get <- getSymbols(X, from="2000-01-01", src="yahoo")
volatility(get(Get), calc="close")
}
vClose("SPY")