Quanstrat闪亮

时间:2018-11-05 07:46:34

标签: r shiny quantmod quantstrat

我已使用Quantstrat上传了一个Web应用程序,以从服务器上发光。但是,当我在Shinyapps.io上发布时,它不起作用。有没有人发布过/拥有一些可以在这里帮助我的代码?预先感谢

这是我从计算机上运行它时发生的情况。效果很好。

当我将论文发布到Shinyapps.io时,会发生这种情况。enter image description here

我不确定在这里我在做什么错。我将为有兴趣提供帮助的人上传代码。

library(shiny)
library(devtools)
library(quantmod)
library(quantstrat)
library(TTR)
library(png)
library(dplyr)

ui <- fluidPage(

 # Application title
titlePanel("Old Faithful Geyser Data"),

 # Sidebar with a slider input for number of bins 
 sidebarLayout(
  sidebarPanel(
     sliderInput("bins",
                 "Number of bins:",
                 min = 1,
                 max = 50,
                 value = 30),
     selectInput("sto", "choose the stock", choices = c("AAPL", "CAT"))
  ),

  # Show a plot of the generated distribution
  mainPanel(
     plotOutput("plot")

  )
 )
)


server <- function(input, output) {
Sys.setenv(TZ = "UTC")
currency("USD")

#variables
init_date = "2010-01-01"
start_date = "2010-02-01"
end_date = Sys.Date()
tradesize = 10000
init_equity = 1000000
#chose the symbol
 A = getSymbols("AMZN", from = start_date, to = end_date, index.class = 
"POSIXct", adjust = F, auto.assign = F)
plot(Cl(A))
 stock("A", currency = "USD", multiplier = 1)
 portfolio.st = account.st = strategy.st = "jwrong.first"

rm.strat(portfolio.st)
rm.strat(account.st)
initPortf(name = portfolio.st, symbols = "A", initDate = init_date)
initAcct(name = account.st, portfolios = portfolio.st, initDate = init_date,
         initEq = init_equity)
initOrders(portfolio = portfolio.st, symbols = "A", initDate = init_date)
strategy(name = strategy.st, store = T)


 add.indicator(strategy = strategy.st,
            name = "EMA", 
            arguments = list(x = quote(Cl(mktdata)),
                             n = 100),
            label = "nFast")

 add.indicator(strategy = strategy.st,
            name = "EMA",
            arguments = list(x = quote(Cl(mktdata)),
                             n = 200),
            label = "nSlow")

  add.signal(strategy = strategy.st,
         name = "sigCrossover",
         arguments = list(columns = c("nFast", "nSlow"),
                          relationship = "gt"),
         label = "long")
  add.signal(strategy = strategy.st,
         name = "sigCrossover", 
         arguments = list(columns = c("nFast", "nSlow"), 
                          relationship = "lt"),
         label = "short")

    add.rule(strategy = strategy.st,
       name = "ruleSignal",
       arguments = list(sigcol = "long",
                        sigval = T,
                        orderside = "long",
                        ordertype = "stoplimit",
                        orderqty = 100,
                        threshold = .000,
                        prefer = "High",
                        TxnFees = -10,
                        replace = F),
       type = "enter",
       label = "EnterLong")
  add.rule(strategy = strategy.st,
       name = "ruleSignal",
       arguments = list(sigcol = "short",
                        sigval = T,
                        orderside = "short",
                        ordertype = "stoplimit",
                        orderqty = -100,
                        threshold = -.00,
                        prefer = "Low",
                        TxnFees = -10,
                        replace = F
       ),
       type = "enter",
       label = "EnterShort")
   add.rule(strategy.st,
       name = "ruleSignal", 
       arguments = list(sigcol = "short",
                        sigval = T,
                        orderside = "long",
                        ordertype = "market",
                        orderqty = "all",
                        TxnFees = -10,
                        replace = T),
       type = "exit",
       label = "Exit2Short")
   add.rule(strategy.st,
       name = "ruleSignal",
       arguments = list(sigcol = "long",
                        sigval = T,
                        orderside = "short",
                        ordertype = "market",
                        orderqty = "all",
                        TxnFees = -5,
                        replace = T
       ),
       type = "exit",
       label = "Exit2Long")



  results = applyStrategy(strategy.st,portfolios = portfolio.st)
   updatePortf(portfolio.st)
  updateAcct(account.st)
  updateEndEq(account.st)

   output$plot = renderPlot({
    chart.Posn(portfolio.st, Symbol = "A",
           TA = "add_EMA(n = 100, col = 3); add_EMA(n = 200, col = 4)")
  })
  }

  # Run the application 
 shinyApp(ui = ui, server = server)

0 个答案:

没有答案