Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chart_Series gives error running the basic example in quantstrat under R 4.3 #403

Closed
comintel opened this issue Aug 28, 2023 · 1 comment
Assignees
Labels

Comments

@comintel
Copy link

comintel commented Aug 28, 2023

Description

chart_Series() gives error running the basic example in quantstrat under R 4.3. Works ok in 4.2.

Expected behavior

Run error free in R 4.3

Minimal, reproducible example

#From the example in https://github.com/braverock/quantstrat#readme
library(FinancialInstrument)
library(PerformanceAnalytics)
library(quantstrat)

stock.str='AAPL' # what are we trying it on
currency('USD')
stock(stock.str,currency='USD',multiplier=1)
#
startDate="1999-12-31"
initEq=1000000
portfolio.st='macross'
account.st='macross'
initPortf(portfolio.st,symbols=stock.str)

initAcct(account.st,portfolios=portfolio.st, initEq=initEq)

initOrders(portfolio=portfolio.st)
stratMACROSS<- strategy(portfolio.st)
stratMACROSS <- add.indicator(strategy = stratMACROSS, name = "SMA", arguments = list(x=quote(Cl(mktdata)), n=50),label= "ma50" )
stratMACROSS <- add.indicator(strategy = stratMACROSS, name = "SMA", arguments = list(x=quote(Cl(mktdata)[,1]), n=200),label= "ma200")

stratMACROSS <- add.signal(strategy = stratMACROSS,name="sigCrossover",arguments = list(columns=c("ma50","ma200"), relationship="gte"),label="ma50.gt.ma200")
stratMACROSS <- add.signal(strategy = stratMACROSS,name="sigCrossover",arguments = list(column=c("ma50","ma200"),relationship="lt"),label="ma50.lt.ma200")

stratMACROSS <- add.rule(strategy = stratMACROSS,name='ruleSignal', arguments = list(sigcol="ma50.gt.ma200",sigval=TRUE, orderqty=100, ordertype='market', orderside='long'),type='enter')
stratMACROSS <- add.rule(strategy = stratMACROSS,name='ruleSignal', arguments = list(sigcol="ma50.lt.ma200",sigval=TRUE, orderqty='all', ordertype='market', orderside='long'),type='exit')

getSymbols(stock.str,from=startDate)
for(i in stock.str)
	assign(i, adjustOHLC(get(i),use.Adjusted=TRUE))
start_t<-Sys.time()
out<-applyStrategy(strategy=stratMACROSS , portfolios=portfolio.st)

end_t<-Sys.time()
print(end_t-start_t)

start_t<-Sys.time()
updatePortf(Portfolio='macross',Dates=paste('::',as.Date(Sys.time()),sep=''))

end_t<-Sys.time()
print("trade blotter portfolio update:")

print(end_t-start_t)
chart.Posn(Portfolio='macross',Symbol=stock.str, TA=c("add_SMA(n=50,col='red')","add_SMA(n=200,col='blue')"))

The line that gives the error is

chart.Posn(Portfolio='macross',Symbol=stock.str, TA = c("add_SMA(n=50,col='red')", "add_SMA(n=200,col='blue')"))
## "Error in !is.null(TA) && nchar(TA) > 0 :   'length = 2' in coercion to 'logical(1)' "
traceback()
## 2: chart_Series(Prices, name = Symbol, TA = TA, ...) at chart.Posn.R#82
## 1: chart.Posn(Portfolio = "macross", Symbol = stock.str, TA = c("add_SMA(n=50,col='red')", 
##        "add_SMA(n=200,col='blue')"))

It occurs because TA has 2 elements

@joshuaulrich
Copy link
Owner

joshuaulrich commented Aug 28, 2023

Thanks for the report and reproducible example!

@joshuaulrich joshuaulrich added this to the Release 0.4.26 milestone Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants