我想手动添加在指定日期执行的订单。所以我想到了使用addOrder:
library(quantstrat)
library(quantmod)
# init
depotSymbols <- c('M7U.DE', 'ADS.DE')
getSymbols(Symbols = depotSymbols)
# init strategy
strategyName <- portfolioName <- accountName <- 'HotStock'
currencySymbol <- 'EUR'
initDate <- as.Date('2014-01-01')
endDate <- as.Date(Sys.Date())
strategy(name = strategyName)
currency(primary_id = currencySymbol)
Sys.setenv(TZ="UTC")
stock(depotSymbols, currency = currencySymbol, multiplier = 1)
initEquity <- 10000
riskSize <- initEquity / 100
rm.strat(strategyName)
initPortf(name = portfolioName, symbols = depotSymbols, initDate = initDate, currency = currencySymbol)
initAcct(name = accountName, portfolios = portfolioName, initDate = initDate, currency = currencySymbol, initEq = initEquity)
initOrders(portfolio = portfolioName, initDate = initDate)
strategy(name = strategyName, store = TRUE)
# add orders
orderSymbol <- 'M7U.DE'
orderLimit <- 3.80
orderStopp <- 2.75
orderTarget <- 5.50
orderDate <- as.POSIXct('2014-02-07')
addOrder(portfolio = portfolioName, symbol = orderSymbol, timestamp = orderDate, qty = 100, price = orderLimit, ordertype = 'limit', side = 'long', prefer = 'Close', TxnFees = -9.95)
# execute
applyStrategy(strategy = strategyName, portfolios = portfolioName)
如果我查看订单,订单将于2008-11-13执行。不是我想要的2014-02-07。
getOrderBook(portfolio = portfolioName)
$ HotStock $ HotStock $ ADS.DE NULL
$ $ HotStock M7U.DE Order.Qty Order.Price Order.Type Order.Side Order.Threshold Order.Status Order.StatusTime Prefer Order.Set Txn.Fees 2014-02-07 00:00:00&#34; 100&#34; &#34; 3.8&#34; &#34;限制&#34; &#34;长&#34;
NA&#34;关闭&#34; &#34; 2008-11-13 00:00:00&#34; &#34;关闭&#34; &#34;&#34;
&#34; -9.95&#34; Rule Time.In.Force 2014-02-07 00:00:00&#34;&#34; &#34;&#34;attr(,&#34; class&#34;)[1]&#34; order_book&#34;
我做错了什么?
谢谢, 克里斯托弗