可以购买等于可用投资组合总权益的金额,但是您必须定义自定义订单大小功能.而且该功能必须必须标记帐簿(使用updatePortf),才能确定可用股本的金额.I'm still playing around with Guy Yollins quantstrat example. In this example he buys 1000 shares of the SPY when it crosses its 10 day MA. Since we define an initial equity, is it possible to always buy for the whole portfolio amount and not just 900 shares? 'all' didn't work for the enter, just the exit..if (!exists('.blotter')) .blotter <- new.env()if (!exists('.strategy')) .strategy <- new.env()if (!exists('.instrument')) .instrument <- new.env()currency("USD")stock("SPY",currency="USD",multiplier=1)ls(envir=FinancialInstrument:::.instrument)initDate <- '1997-12-31'startDate <- '1998-01-01'endDate <- '2013-07-31'initEq <- 1e6Sys.setenv(TZ="UTC")getSymbols('SPY', from=startDate, to=endDate, adjust=T)SPY=to.monthly(SPY, indexAt='endof')SPY$SMA10m <- SMA(Cl(SPY), 10)# inz portfolio, accountqs.strategy <- "qsFaber"rm.strat(qs.strategy) # remove strategy etc. if this is a re-runinitPortf(qs.strategy,'SPY', initDate=initDate)initAcct(qs.strategy,portfolios=qs.strategy, initDate=initDate, initEq=initEq)initOrders(portfolio=qs.strategy,initDate=initDate)# instantiate a new strategy objectstrategy(qs.strategy,store=TRUE)add.indicator(strategy = qs.strategy, name = "SMA", arguments = list(x = quote(Cl(mktdata)), n=10), label="SMA10")add.signal(qs.strategy,name="sigCrossover", arguments = list(columns=c("Close","SMA10"),relationship="gt"), label="Cl.gt.SMA")add.signal(qs.strategy,name="sigCrossover", arguments = list(columns=c("Close","SMA10"),relationship="lt"), label="Cl.lt.SMA")add.rule(qs.strategy, name='ruleSignal', arguments = list(sigcol="Cl.gt.SMA", sigval=TRUE, orderqty=900, ordertype='market', orderside='long', pricemethod='market'), type='enter', path.dep=TRUE)add.rule(qs.strategy, name='ruleSignal', arguments = list(sigcol="Cl.lt.SMA", sigval=TRUE, orderqty='all', ordertype='market', orderside='long', pricemethod='market'), type='exit', path.dep=TRUE)out <- applyStrategy(strategy=qs.strategy , portfolios=qs.strategy)updatePortf(qs.strategy)updateAcct(qs.strategy)updateEndEq(qs.strategy)myTheme<-chart_theme()myTheme$col$dn.col<-'lightblue'myTheme$col$dn.border <- 'lightgray'myTheme$col$up.border <- 'lightgray'# plot performancechart.Posn(qs.strategy, Symbol = 'SPY', Dates = '1998::',theme=myTheme)plot(add_SMA(n=10,col=4, on=1, lwd=2)) 解决方案 You cannot use orderqty="all" on entries because "all" refers to the current position size (i.e., when you want to exit the entire position).It's possible to purchase an amount equal to the total available portfolio equity, but you have to define a custom order sizing function. And that function would necessarily have to mark the book (using updatePortf) in order to determine the amount of available equity. 这篇关于R:Quantstrat如何进行交易以完成投资组合中的全部股权?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-11 22:18