Why does the addBBands() function error when the chartSeries plots using the same dataset?
After retrieving OHLC data using the getSymbols function, I'm adding a column to the OHLC data. I can plot the chart using the chartSeries function, but when I try to add Bollinger Bands using the addBBands() function, I get an error.
When removing the extra column from the OHLC data, the addBBands() function works fine. It's not clear to me if it's supposed to work this way or if this is a design shortcoming.
library (quantmod)
getSymbols("AAPL")
AAPL <- cbind(AAPL,AAPL[,4])
chartSeries(AAPL["2018"])
addBBands()
The chart plots and I would expect the addBBands() function to plot the Bollinger Bands, but I get the error, "Price series must be either High-Low-Close, or Close/univariate."
r
add a comment |
After retrieving OHLC data using the getSymbols function, I'm adding a column to the OHLC data. I can plot the chart using the chartSeries function, but when I try to add Bollinger Bands using the addBBands() function, I get an error.
When removing the extra column from the OHLC data, the addBBands() function works fine. It's not clear to me if it's supposed to work this way or if this is a design shortcoming.
library (quantmod)
getSymbols("AAPL")
AAPL <- cbind(AAPL,AAPL[,4])
chartSeries(AAPL["2018"])
addBBands()
The chart plots and I would expect the addBBands() function to plot the Bollinger Bands, but I get the error, "Price series must be either High-Low-Close, or Close/univariate."
r
add a comment |
After retrieving OHLC data using the getSymbols function, I'm adding a column to the OHLC data. I can plot the chart using the chartSeries function, but when I try to add Bollinger Bands using the addBBands() function, I get an error.
When removing the extra column from the OHLC data, the addBBands() function works fine. It's not clear to me if it's supposed to work this way or if this is a design shortcoming.
library (quantmod)
getSymbols("AAPL")
AAPL <- cbind(AAPL,AAPL[,4])
chartSeries(AAPL["2018"])
addBBands()
The chart plots and I would expect the addBBands() function to plot the Bollinger Bands, but I get the error, "Price series must be either High-Low-Close, or Close/univariate."
r
After retrieving OHLC data using the getSymbols function, I'm adding a column to the OHLC data. I can plot the chart using the chartSeries function, but when I try to add Bollinger Bands using the addBBands() function, I get an error.
When removing the extra column from the OHLC data, the addBBands() function works fine. It's not clear to me if it's supposed to work this way or if this is a design shortcoming.
library (quantmod)
getSymbols("AAPL")
AAPL <- cbind(AAPL,AAPL[,4])
chartSeries(AAPL["2018"])
addBBands()
The chart plots and I would expect the addBBands() function to plot the Bollinger Bands, but I get the error, "Price series must be either High-Low-Close, or Close/univariate."
r
r
asked Jan 18 at 15:58
S NovogoratzS Novogoratz
134
134
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This is by design. BBands checks the names of the columns. The check is based on the columns names. In your example you have 2 columns which contain the word Close. This is where it goes wrong. If you name the new column anything except high, low, open, close, volume it will work. Something like below.
library (quantmod)
getSymbols("AAPL")
AAPL <- cbind(AAPL,AAPL[,4])
# rename last column so it doesn't have "close" in the column name
names(AAPL)[7] <- "AAPL.New.Col"
chartSeries(AAPL["2018"])
addBBands()
I did rename the last column as you suggested and continue to get the error.
– S Novogoratz
Jan 18 at 17:58
check the result of names(AAPL) and see what that returns. It should work on the example. But only in a clean R environment.
– phiver
Jan 18 at 17:59
Here's the names result. I also wiped the environment before running it and continue to get the same error. AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted AAPL.New.Col
– S Novogoratz
Jan 18 at 18:02
Should work fine. I don't have any issues with this. Have you restarted your R session?
– phiver
Jan 18 at 18:06
1
Finally got it... the column name change needs to go before chartSeries(). Thank you for your help.
– S Novogoratz
Jan 18 at 18:45
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257447%2fwhy-does-the-addbbands-function-error-when-the-chartseries-plots-using-the-sam%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is by design. BBands checks the names of the columns. The check is based on the columns names. In your example you have 2 columns which contain the word Close. This is where it goes wrong. If you name the new column anything except high, low, open, close, volume it will work. Something like below.
library (quantmod)
getSymbols("AAPL")
AAPL <- cbind(AAPL,AAPL[,4])
# rename last column so it doesn't have "close" in the column name
names(AAPL)[7] <- "AAPL.New.Col"
chartSeries(AAPL["2018"])
addBBands()
I did rename the last column as you suggested and continue to get the error.
– S Novogoratz
Jan 18 at 17:58
check the result of names(AAPL) and see what that returns. It should work on the example. But only in a clean R environment.
– phiver
Jan 18 at 17:59
Here's the names result. I also wiped the environment before running it and continue to get the same error. AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted AAPL.New.Col
– S Novogoratz
Jan 18 at 18:02
Should work fine. I don't have any issues with this. Have you restarted your R session?
– phiver
Jan 18 at 18:06
1
Finally got it... the column name change needs to go before chartSeries(). Thank you for your help.
– S Novogoratz
Jan 18 at 18:45
|
show 3 more comments
This is by design. BBands checks the names of the columns. The check is based on the columns names. In your example you have 2 columns which contain the word Close. This is where it goes wrong. If you name the new column anything except high, low, open, close, volume it will work. Something like below.
library (quantmod)
getSymbols("AAPL")
AAPL <- cbind(AAPL,AAPL[,4])
# rename last column so it doesn't have "close" in the column name
names(AAPL)[7] <- "AAPL.New.Col"
chartSeries(AAPL["2018"])
addBBands()
I did rename the last column as you suggested and continue to get the error.
– S Novogoratz
Jan 18 at 17:58
check the result of names(AAPL) and see what that returns. It should work on the example. But only in a clean R environment.
– phiver
Jan 18 at 17:59
Here's the names result. I also wiped the environment before running it and continue to get the same error. AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted AAPL.New.Col
– S Novogoratz
Jan 18 at 18:02
Should work fine. I don't have any issues with this. Have you restarted your R session?
– phiver
Jan 18 at 18:06
1
Finally got it... the column name change needs to go before chartSeries(). Thank you for your help.
– S Novogoratz
Jan 18 at 18:45
|
show 3 more comments
This is by design. BBands checks the names of the columns. The check is based on the columns names. In your example you have 2 columns which contain the word Close. This is where it goes wrong. If you name the new column anything except high, low, open, close, volume it will work. Something like below.
library (quantmod)
getSymbols("AAPL")
AAPL <- cbind(AAPL,AAPL[,4])
# rename last column so it doesn't have "close" in the column name
names(AAPL)[7] <- "AAPL.New.Col"
chartSeries(AAPL["2018"])
addBBands()
This is by design. BBands checks the names of the columns. The check is based on the columns names. In your example you have 2 columns which contain the word Close. This is where it goes wrong. If you name the new column anything except high, low, open, close, volume it will work. Something like below.
library (quantmod)
getSymbols("AAPL")
AAPL <- cbind(AAPL,AAPL[,4])
# rename last column so it doesn't have "close" in the column name
names(AAPL)[7] <- "AAPL.New.Col"
chartSeries(AAPL["2018"])
addBBands()
answered Jan 18 at 17:50
phiverphiver
13.1k92734
13.1k92734
I did rename the last column as you suggested and continue to get the error.
– S Novogoratz
Jan 18 at 17:58
check the result of names(AAPL) and see what that returns. It should work on the example. But only in a clean R environment.
– phiver
Jan 18 at 17:59
Here's the names result. I also wiped the environment before running it and continue to get the same error. AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted AAPL.New.Col
– S Novogoratz
Jan 18 at 18:02
Should work fine. I don't have any issues with this. Have you restarted your R session?
– phiver
Jan 18 at 18:06
1
Finally got it... the column name change needs to go before chartSeries(). Thank you for your help.
– S Novogoratz
Jan 18 at 18:45
|
show 3 more comments
I did rename the last column as you suggested and continue to get the error.
– S Novogoratz
Jan 18 at 17:58
check the result of names(AAPL) and see what that returns. It should work on the example. But only in a clean R environment.
– phiver
Jan 18 at 17:59
Here's the names result. I also wiped the environment before running it and continue to get the same error. AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted AAPL.New.Col
– S Novogoratz
Jan 18 at 18:02
Should work fine. I don't have any issues with this. Have you restarted your R session?
– phiver
Jan 18 at 18:06
1
Finally got it... the column name change needs to go before chartSeries(). Thank you for your help.
– S Novogoratz
Jan 18 at 18:45
I did rename the last column as you suggested and continue to get the error.
– S Novogoratz
Jan 18 at 17:58
I did rename the last column as you suggested and continue to get the error.
– S Novogoratz
Jan 18 at 17:58
check the result of names(AAPL) and see what that returns. It should work on the example. But only in a clean R environment.
– phiver
Jan 18 at 17:59
check the result of names(AAPL) and see what that returns. It should work on the example. But only in a clean R environment.
– phiver
Jan 18 at 17:59
Here's the names result. I also wiped the environment before running it and continue to get the same error. AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted AAPL.New.Col
– S Novogoratz
Jan 18 at 18:02
Here's the names result. I also wiped the environment before running it and continue to get the same error. AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted AAPL.New.Col
– S Novogoratz
Jan 18 at 18:02
Should work fine. I don't have any issues with this. Have you restarted your R session?
– phiver
Jan 18 at 18:06
Should work fine. I don't have any issues with this. Have you restarted your R session?
– phiver
Jan 18 at 18:06
1
1
Finally got it... the column name change needs to go before chartSeries(). Thank you for your help.
– S Novogoratz
Jan 18 at 18:45
Finally got it... the column name change needs to go before chartSeries(). Thank you for your help.
– S Novogoratz
Jan 18 at 18:45
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257447%2fwhy-does-the-addbbands-function-error-when-the-chartseries-plots-using-the-sam%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown