3

上下文:我有一个 csv 文件中的交易(交易)列表。我喜欢将这些交易导入 R,然后在图表上绘制交易,这样我就可以直观地看到进场和离场。我终于找到了导入部分(来自吸墨纸演示中的 amzn_test.R),但在更改图表上绘制的交易标记的颜色时遇到了困难。

我注意到chart.Posn.R (package:blotter) 源代码中交易标记的颜色目前是固定的。(文件名:chart.Posn.R,代码网址:https ://r-forge.r-project.org/scm/viewvc.php/pkg/blotter/R/chart.Posn.R?view=markup&root=blotter )

if(!is.null(nrow(Buys)) && nrow(Buys) >=1 ) (add_TA(Buys,pch=2,type='p',col='green', on=1));
    if(!is.null(nrow(Sells)) && nrow(Sells) >= 1) (add_TA(Sells,pch=6,type='p',col='red', on=1));

问题:有什么办法可以覆盖这些颜色?如果我不能,有什么办法可以将背景图表主题更改为黑色,以便更好地看到交易标记?我尝试了各种方法来设置chartTheme,但遇到了错误。

要重现错误,请执行以下吸墨纸 amzn_test 演示代码片段,然后执行自定义代码。

演示代码:

require(blotter)

# Remove portfolio and account data if run previously
try(rm("portfolio.amzn_port","account.amzn_acct",pos=.blotter))

# load the example data
data("amzn")
currency("USD")
stock("amzn",currency="USD",multiplier=1)
# Initialize the Portfolio
initPortf("amzn_port",symbols="amzn",initDate="2010-01-14")
initAcct("amzn_acct",portfolios="amzn_port",initDate="2010-01-14", initEq=10000)
# look at the transactions data
amzn.trades
# Add the transactions to the portfolio
blotter:::addTxns("amzn_port","amzn",TxnData=amzn.trades,verbose=TRUE)

# update the portfolio stats
updatePortf("amzn_port",Dates="2010-01-14")

# update the account P&L
updateAcct("amzn_acct",Dates="2010-01-14")

# and look at it
chart.Posn("amzn_port","amzn",Dates="2010-01-14")

自定义代码:

> black_theme = chartTheme("black")
> chart.Posn("amzn_port","amzn",Dates="2010-01-14", theme=chartTheme("black"))
Error in if (theme$lylab) { : argument is of length zero
> 

如果有人能指导我如何解决这个问题,我将不胜感激。

问候,

4

0 回答 0