[GSoC-PortA] Error in plot method
Peter Carl
peter at braverock.com
Wed Sep 18 03:53:02 CEST 2013
Ross,
You might already know about this, given that I'm a day behind on svn.
Sorry for the lack of detail, I can do more debugging if you need.
> R = edhec[,c("Convertible Arbitrage", "Equity Market Neutral","Fixed
Income Arbitrage", "Event Driven", "CTA Global", "Global Macro",
"Long/Short Equity")]
> init.portf <- portfolio.spec(assets=colnames(R))
> init.portf <- add.constraint(portfolio=init.portf,
+ type="leverage",
+ min_sum=1,
+ max_sum=1)
> # Add box constraint
> init.portf <- add.constraint(portfolio=init.portf,
+ type="box",
+ min=0.05,
+ max=0.3)
>
> # Add group constraint
> init.portf <- add.constraint(portfolio=init.portf, type="group",
+ groups=list(c(1:4),
+ c(5:7)),
+ group_min=c(0.1,.05),
+ group_max=c(0.85,0.75)
+ )
> #Add measure 1, annualized return
> init.portf <- add.objective(portfolio=init.portf,
+ type="return", # the kind of objective this is
+ name="mean", # name of the function
+ enabled=TRUE, # enable or disable the objective
+ multiplier=0 # calculate it but don't use it
in the objective
+ )
>
> # Add measure 2, annualized standard deviation
> init.portf <- add.objective(portfolio=init.portf,
+ type="risk", # the kind of objective this is
+ name="var", # to minimize from the sample
+ enabled=TRUE, # enable or disable the objective
+ multiplier=0 # calculate it but don't use it
in the objective
+ )
>
> # Add measure 3, ES
> init.portf <- add.objective(portfolio=init.portf,
+ type="risk", # the kind of objective this is
+ name="ES", # the function to minimize
+ enabled=FALSE, # enable or disable the
objective
+ multiplier=0, # calculate it but don't use
it in the objective
+ arguments=list(p=p)
+ )
> MeanVar.portf <- init.portf
# Turn back on the return and sd objectives
> MeanVar.portf$objectives[[1]]$multiplier = -1 # mean
> MeanVar.portf$objectives[[2]]$multiplier = 1 # var
> MeanVar.ROI<-optimize.portfolio(R=R,
+ portfolio=MeanVar.portf,
+ optimize_method='ROI'
+ )
> summary(MeanVar.ROI)
**************************************************
PortfolioAnalytics Optimization Summary
**************************************************
Call:
optimize.portfolio(R = R, portfolio = MeanVar.portf, optimize_method = "ROI")
Optimal Weights:
Convertible Arbitrage Equity Market Neutral Fixed Income Arbitrage
Event Driven CTA Global Global Macro
0.0500 0.0500 0.0500
0.2134 0.0500
0.3000
Long/Short Equity
0.2866
Objective Measures:
mean
0.007309
StdDev
0.01561
Portfolio Assets and Initial Weights:
Convertible Arbitrage Equity Market Neutral Fixed Income Arbitrage
Event Driven CTA Global Global Macro
0.1428571 0.1428571 0.1428571
0.1428571 0.1428571
0.1428571
Long/Short Equity
0.1428571
**************************************************
PortfolioAnalytics Portfolio Specification
**************************************************
Call:
portfolio.spec(assets = colnames(R))
Assets
Number of assets: 7
Asset Names
[1] "Convertible Arbitrage" "Equity Market Neutral" "Fixed Income
Arbitrage" "Event Driven" "CTA Global"
[6] "Global Macro" "Long/Short Equity"
Constraints
Number of constraints: 3
Number of enabled constraints: 3
Enabled constraint types
- leverage
- box
- group
Number of disabled constraints: 0
Objectives
Number of objectives: 3
Number of enabled objectives: 2
Enabled objective names
- mean
- var
Number of disabled objectives: 1
Disabled objective types
- ES
****************************************
Constraints
****************************************
Leverage Constraint:
min_sum = 1
max_sum = 1
Box Constraints:
min:
Convertible Arbitrage Equity Market Neutral Fixed Income Arbitrage
Event Driven CTA Global Global Macro
0.05 0.05 0.05
0.05 0.05
0.05
Long/Short Equity
0.05
max:
Convertible Arbitrage Equity Market Neutral Fixed Income Arbitrage
Event Driven CTA Global Global Macro
0.3 0.3 0.3
0.3 0.3
0.3
Long/Short Equity
0.3
Group Constraints:
Groups:
$group1
[1] 1 2 3 4
$group2
[1] 5 6 7
Lower bound on group weights, group_min:
group1 group2
0.10 0.05
Upper bound on group weights, group_max:
group1 group2
0.85 0.75
Group position limits, group_pos:
NULL
Group Weights:
group1 group2
0.3633993 0.6366007
Position Limit Constraints:
Maximum number of non-zero weights, max_pos:
NULL
Realized number of non-zero weights (i.e. positions):
[1] 7
Maximum number of long positions, max_pos_long:
NULL
Realized number of long positions:
[1] 7
Maximum number of short positions, max_pos_short:
NULL
Realized number of short positions:
[1] 0
Diversification Target Constraint:
NULL
Realized diversification:
[1] 0.7723208
Turnover Target Constraint:
NULL
Realized turnover from initial weights:
[1] 0.1061224
****************************************
Objectives
****************************************
Objective: return_objective
$name
[1] "mean"
$target
NULL
$arguments
list()
$enabled
[1] TRUE
$multiplier
[1] -1
$call
add.objective(portfolio = init.portf, type = "return", name = "mean",
enabled = TRUE, multiplier = 0)
attr(,"class")
[1] "return_objective" "objective"
****************************************
Objective: portfolio_risk_objective
$name
[1] "var"
$target
NULL
$arguments
$arguments$portfolio_method
[1] "single"
$enabled
[1] TRUE
$multiplier
[1] 1
$call
add.objective(portfolio = init.portf, type = "risk", name = "var",
enabled = TRUE, multiplier = 0)
attr(,"class")
[1] "portfolio_risk_objective" "objective"
****************************************
Objective: portfolio_risk_objective
$name
[1] "ES"
$target
NULL
$arguments
$arguments$p
[1] 0.9166667
$arguments$portfolio_method
[1] "single"
$enabled
[1] FALSE
$multiplier
[1] 0
$call
add.objective(portfolio = init.portf, type = "risk", name = "ES",
arguments = list(p = p), enabled = FALSE, multiplier = 0)
attr(,"class")
[1] "portfolio_risk_objective" "objective"
****************************************
Elapsed Time:
Time difference of 0.5688059 secs
> plot(MeanVar.ROI)
Error in apply(R, 2, "mean") : dim(X) must have a positive length
> traceback()
10: stop("dim(X) must have a positive length")
9: apply(R, 2, "mean")
8: as.vector(apply(R, 2, "mean"))
7: matrix(as.vector(apply(R, 2, "mean")), ncol = 1)
6: moments(R)
5: applyFUN(R = R, weights = rp, FUN = return.col, ... = ...)
4: chart.Scatter.ROI(object = ROI, rp = rp, return.col = return.col,
risk.col = risk.col, ..., chart.assets = chart.assets,
element.color = element.color,
cex.axis = cex.axis, main = main, xlim = xlim, ylim = ylim)
3: charts.ROI(ROI = x, rp = rp, risk.col = risk.col, return.col = return.col,
chart.assets = chart.assets, main = main, xlim = xlim, ylim = ylim,
...)
2: plot.optimize.portfolio.ROI(MeanVar.ROI)
1: plot(MeanVar.ROI)
pcc
--
Peter Carl
http://www.braverock.com/peter
More information about the GSoC-PortA
mailing list