treewolf
treewolf

Reputation: 1

How to type stock ticker with an equal sign operator? (ES=F, e-mini S&P 500)

I am trying to retrieve historical price data for the e-mini S&P 500 ticker ES=F on yahoo finance; however, the = symbol in the ticker is throwing off the output because it is an assignment operator. Example of the code nugget:

library(quantmod)
library(TTR)
library(PerformanceAnalytics)

**# Getting stock prices of ES=F**
getSymbols ('ES=F', src = 'yahoo', from = '2019-01-01')
**# Basic plot of the e-mini S&P 500 futures March 2023 contract**
barChart(ES=F, theme = chartTheme('black'))

Any assistance with how to properly type the ticker w/o causing error would be greatly appreciated.

Best regards!

**Things I've tried so far:

-adding backtick characters, ES=F... which didn't work. -Tried all the varying ticker symbols I could think of (ESH3, ES_F,/ES), but YahooAPI requires ES=F. -Changed getSymbols and barChart but that just lead me worse off.

Upvotes: 0

Views: 343

Answers (1)

phiver
phiver

Reputation: 23598

If you get the e-mini S&P 500 like this, for further use in R you need to use backticks, like below.

barChart(`ES=F`, theme = chartTheme('black'))

The best way forward is to make sure that what you retrieve is stored in a sensible object.

sp_mini <- getSymbols ("ES=F", src = 'yahoo', from = '2019-01-01', auto.assign = FALSE)

This will store the data in the sp_mini object which doesn't have any symbols that the R environment doesn't like in the object names.

Upvotes: 2

Related Questions