PortfolioAnalytics icon indicating copy to clipboard operation
PortfolioAnalytics copied to clipboard

Optimization with ROI method not working for specific edhec period

Open cruelas opened this issue 3 years ago • 0 comments

I'm trying to run a yearly rebalance using simple minimum volatility and box constraint using edhec data, but it fails for 2012-12-31 when using a rolling window of 60 months, so I isolated that period below and the problem persists:

# Load libraries
library(PortfolioAnalytics)
library(PerformanceAnalytics)

# Load edhec returns
data(edhec)
asset_returns <- edhec["2007-12-31/2012-12-31"]

# Create the portfolio specification
base_port_spec <- portfolio.spec(assets = colnames(asset_returns))
# Add a full investment constraint such that the weights sum to 1
base_port_spec <- add.constraint(base_port_spec,
                                 type = "full_investment")
# Add a long only constraint such that the weight of an asset is between 5% and 40%
base_port_spec <- add.constraint(base_port_spec,
                                 type = "box",
                                 min = 0.05, max = 0.4)
# Add an objective to minimize portfolio standard deviation
base_port_spec <- add.objective(base_port_spec,
                                type = "risk",
                                name = "StdDev")

# Run the optimization with periodic rebalance
opt_base <- optimize.portfolio(R = asset_returns,
                               optimize_method = "ROI",
                               portfolio = base_port_spec)

print(extractWeights(opt_base))

This results in:

 Convertible Arbitrage             CTA Global  Distressed Securities       Emerging Markets 
                    NA                     NA                     NA                     NA 
 Equity Market Neutral           Event Driven Fixed Income Arbitrage           Global Macro 
                    NA                     NA                     NA                     NA 
     Long/Short Equity       Merger Arbitrage         Relative Value          Short Selling 
                    NA                     NA                     NA                     NA 
        Funds of Funds 
                    NA 

I've checked the covariance matrix and everything seems fine. The eigenvalues are positive and both solve() and MASS::ginv() produce results so I'm pretty sure the covariance matrix is fine. Any other ideas why it would fail for this specific time period? I thought maybe ROI and box constraint were incompatible but it works for every other 60 month period fine (e.g. edhec["2007-11-30/2012-11-30"]), this is the only one that fails.

Thanks.

R Session info:

R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.3.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] PortfolioAnalytics_1.1.0   PerformanceAnalytics_2.0.4 foreach_1.5.1             
[4] xts_0.12.1                 zoo_1.8-9                 

loaded via a namespace (and not attached):
 [1] quadprog_1.5-8            lattice_0.20-44           codetools_0.2-18         
 [4] slam_0.1-48               grid_4.1.0                registry_0.5-1           
 [7] DEoptim_2.2-6             GenSA_1.1.7               ROI.plugin.quadprog_1.0-0
[10] iterators_1.0.13          tools_4.1.0               pso_1.0.3                
[13] ROI_1.0-0                 parallel_4.1.0            numDeriv_2016.8-1.1      
[16] compiler_4.1.0           

cruelas avatar Nov 16 '21 17:11 cruelas