Index-class {yahoofinancer}R Documentation

R6 Class Representing a Ticker

Description

Base class for getting all data related to indices from Yahoo Finance API.

Format

An R6 class object

Public fields

index

Index for which data is retrieved

Methods

Public methods


Method new()

Create a new Index object

Usage
Index$new(index = NA)
Arguments
index

Index

Returns

A new 'Index' object

Examples
nifty_50 <- Index$new('^NSEI')

Method set_index()

Set a new index.

Usage
Index$set_index(index)
Arguments
index

New index

Examples
indice <- Index$new('^NSEI')
indice$set_index('^NDX')

Method get_history()

Retrieves historical data

Usage
Index$get_history(period = "ytd", interval = "1d", start = NULL, end = NULL)
Arguments
period

Length of time. Defaults to 'ytd'. Valid values are:

  • '1d'

  • '5d'

  • '1mo'

  • '3mo'

  • '6mo'

  • '1y'

  • '2y'

  • '5y'

  • '10y'

  • 'ytd'

  • 'max'

interval

Time between data points. Defaults to '1d'. Valid values are:

  • '1m'

  • '2m'

  • '5m'

  • '15m'

  • '30m'

  • '60m'

  • '90m'

  • '1h'

  • '1d'

  • '5d'

  • '1wk'

  • '1mo'

  • '3mo'

start

Specific starting date. String or date object in yyyy-mm-dd format.

end

Specific ending date. String or date object in yyyy-mm-dd format.

Returns

A data.frame.

Examples
\donttest{
nifty <- Index$new('^NSEI')
nifty$get_history(start = '2022-07-01', interval = '1d')
nifty$get_history(start = '2022-07-01', end = '2022-07-14', interval = '1d')
nifty$get_history(period = '1mo', interval = '1d')
}

Method clone()

The objects of this class are cloneable with this method.

Usage
Index$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `Index$new`
## ------------------------------------------------

nifty_50 <- Index$new('^NSEI')

## ------------------------------------------------
## Method `Index$set_index`
## ------------------------------------------------

indice <- Index$new('^NSEI')
indice$set_index('^NDX')

## ------------------------------------------------
## Method `Index$get_history`
## ------------------------------------------------


nifty <- Index$new('^NSEI')
nifty$get_history(start = '2022-07-01', interval = '1d')
nifty$get_history(start = '2022-07-01', end = '2022-07-14', interval = '1d')
nifty$get_history(period = '1mo', interval = '1d')


[Package yahoofinancer version 0.3.0 Index]