如何使有状态的JBehave步骤对于多线程执行是安全的(How to make stateful JBehave steps safe for multithreaded execution)
目前,我正在使用Spring将一个步骤类注入到JUnit测试中:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration... class MyTest extends JUnitStories { @Autowired private MySteps mySteps; public List<CandidateSteps> candidateSteps() { return new InstanceStepsFactory(configuration(), mySteps).createCandidateSteps(); } ... }
我想用多线程运行JBehave ,所以我不能再注入一个单独的MySteps bean了。
我已经阅读了http://jira.codehaus.org/browse/JBEHAVE-492但仍然无法看到如何解决我的问题。
Currently, I'm injecting a steps class into a JUnit test using Spring:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration... class MyTest extends JUnitStories { @Autowired private MySteps mySteps; public List<CandidateSteps> candidateSteps() { return new InstanceStepsFactory(configuration(), mySteps).createCandidateSteps(); } ... }
I'd like to run JBehave with multiple threads, so I can't inject a singleton MySteps bean any longer.
I've read http://jira.codehaus.org/browse/JBEHAVE-492 but still can't see how to solve my problem.
原文:https://stackoverflow.com/questions/11666442
最满意答案
chart.PerformanceSummary
实际上只是几个图表的包装器。您可以这样做,并根据需要将其水平扩展到任意数量的符号(如果您愿意,可以超过2个符号) :
par(mfrow=c(3,2)) # First row chart.CumReturns(XTS1, ylab = "Cumulative Return", main = "give me a title") chart.CumReturns(XTS2, ylab = "Cumulative Return", main = "give me a title2") # second row chart.BarVaR(XTS1) chart.BarVaR(XTS2) # third row chart.Drawdown(XTS1, main = "DD title", ylab = "Drawdown", ) chart.Drawdown(XTS2, main = "", ylab = "Drawdown", )
您需要为每个绘图添加适当的参数,例如颜色和标题(留给您),但您可以灵活地添加来自精彩
xts
,quantmod
,performanceAnalytics
包(以及其他)的任何图表。
chart.PerformanceSummary
is really just a wrapper to several charts.You could do this, and extend it to any number of symbols horizontally if you wish (more than 2 symbols if you wanted):
par(mfrow=c(3,2)) # First row chart.CumReturns(XTS1, ylab = "Cumulative Return", main = "give me a title") chart.CumReturns(XTS2, ylab = "Cumulative Return", main = "give me a title2") # second row chart.BarVaR(XTS1) chart.BarVaR(XTS2) # third row chart.Drawdown(XTS1, main = "DD title", ylab = "Drawdown", ) chart.Drawdown(XTS2, main = "", ylab = "Drawdown", )
You need to add the appropriate parameters to each plot for things like colour and titles (leaving that to you), but you have the flexibility of adding any charts from the wonderful
xts
,quantmod
,performanceAnalytics
packages (and others).
相关问答
更多-
下面的cor_matrix函数执行此操作,并添加了一个双变量内核密度图。 感谢@ karl-anka关于让我开始的评论。 import matplotlib.pyplot as plt import seaborn as sns from scipy import stats sns.set(style='white') iris = sns.load_dataset('iris') def corrfunc(x, y, **kws): r, p = stats.pearsonr(x, y) p ...
-
我使用performanceanalytics版本1.4.3541时没有收到错误。 也许更新你的版本? 我确实收到警告,当调用charts.PerformanceSummary并使用na.rm = TRUE时,“na.rm不是图形参数”。 出现此警告是因为na.rm = T作为额外参数传递给函数(因为函数具有特殊参数... ),然后将其传递给charts.PerformanceSummary的图表函数,其中包括chart.CumReturns , chart.BarVaR和chart.Drawdown ,所 ...
-
您可以尝试从BASE R获得par(mfrow=c(1,2)) ,并执行下面的操作,我也在RStudio beamer上测试了它,它可以工作: library(wordcloud) par(mfrow=c(1,2)) obj1 <- data.frame(words=c("a","b","c"), freq=c(10,6,2)) obj2 <- data.frame(words=c("a","b","c"), freq=c(15, ...
-
数据的子集应该在传递给charts.RollingRegression函数之前完成。 强大的xts提供此功能: charts.RollingRegression(Ret["2009-04::",], Rb["2009-04::",2, drop = FALSE], Rf = 0.001, na.pad = TRUE) 您可以通过查看R via ?subset.xts中的帮助页面来阅读有关如何使用xts进行子集的更多信息。 The subsetting of the data should be done p ...
-
基于一个闪亮的小部件,在Rmarkdown中并排绘制2个图(2 Plots side by side in Rmarkdown based on one shiny widget)[2022-04-12]
在这种情况下,您应该按照闪亮教程中的说明个性化您的布局,例如分为2列: ```{r, echo = FALSE, fig.show='hold', out.width='50%'} iteration <- sort(unique(mtcars$cyl)) selectInput('cyl', 'Choose number of cylinder:', choices = iteration, selected = iteration[1]) data <- ... -
R - PerformanceAnalytics - SharpRatio rollapply动物园(R - PerformanceAnalytics - SharpRatio rollapply zoo)[2021-04-23]
由于我不是Sharp Ratios的专家,您期望得到什么结果? 从不如此,不要忘记您假设无风险率为0(因为SharpeRatio(R, Rf = 0, p = 0.95)的默认值为零),这可能会使您的结果产生偏差。 关于你问题的后半部分我会做这样的事情: rollapply(dreturns.z, FUN = function(x) SharpeRatio(x, FUN = "StdDev"), by.column=T, width=20, align="right") 希望这可以帮 ... -
一个使用ggplot2的解决方案(以及一点dplyr) library(ggplot2) library(dplyr) irf1_df <- data.frame(impulse = "dolcan", response = "cpiUSA", value = irf1$irf$dolcan[ , 1]) %>% mutate(index = 1:n()) irf2_df <- data.frame(impulse = "cpiCAN", response = "dolcan", value = irf2 ...
-
答案是在开始时删除总计为0的权重。 Answer is to remove any rows at the beginning with weights totaling to 0.
-
该函数的返回值是一个数据框,因此问题是如何使用百分号打印数据框的列。 可重复的例子如下。 > require(PerformanceAnalytics) > data(managers) > tb = table.AnnualizedReturns(managers[,1],Rf=0) > tb HAM1 Annualized Return 0.1375 Annualized Std Dev 0.0888 Ann ...
-
chart.PerformanceSummary实际上只是几个图表的包装器。 您可以这样做,并根据需要将其水平扩展到任意数量的符号(如果您愿意,可以超过2个符号) : par(mfrow=c(3,2)) # First row chart.CumReturns(XTS1, ylab = "Cumulative Return", main = "give me a title") chart.CumReturns(XTS2, ylab = "Cumulative Return", main = "give m ...