简体   繁体   中英

Portfolio Optimization R - error

Sorry if this is a dumb question, but I have trying to figure this out for 3 days now. I am getting this error every time I try to run the portfolio optimization and can't figure it out.

Error in assign(".objectivestorage", list(), envir = as.environment(.storage)) : 
  object '.storage' not found

I'm also getting this warning usually at the second and third objectives:

In addition: Warning message:
In is.na(le) : is.na() applied to non-(list or vector) of type 'NULL'

Here is my code:

##Import Dataset
setwd("D:\\Dropbox\\FUND - SSIF\\Portfolio Analysis Package")
Stocktrak<- Return.read("SSIF_Data.csv", frequency = "d")
# Create Objects for data and column names

R <- Stocktrak[, 1:17]
colnames(returns) <- c("JEC", "BNS", "AAPL", "PEG", "SLB", "TSM", "HD",
  "MON", "GWO", "TOT", "XPH", "CVS", "UNP", "KORS", "GNTX", "NWC", "WFC")
funds <- colnames(R)

# Create an initial portfolio object with leverage and box constraints
init <- portfolio.spec(assets=funds)
init <- add.constraint(portfolio=init, type="leverage", min_sum=0.99, max_sum=1.01)
init <- add.constraint(portfolio=init, type="box", min=0.01, max=0.65)

# Create Objectives for eq_meanETL Portfolio Optimization
eq_meanETL <- add.objective(portfolio=init, type="return", name="mean")
eq_meanETL <- add.objective(portfolio=eq_meanETL, type="risk", name="ETL", arguments=list(p=0.95))
eq_meanETL <- add.objective(portfolio=eq_meanETL, type="risk_budget", name="ETL", min_concentration=TRUE, arguments=list(p=0.95))

# Optimize Portfolio
opt_eq_meanETL <- optimize.portfolio(R=R, portfolio=eq_meanETL, optimize_method="DEoptim", search_size=2000, trace=TRUE, traceDE=5)

将以下内容放在optimize.portfolio之前

.storage <<- new.env()

Editing

Change the trace = FALSE

It will work. First time here.

Optimize Portfolio

opt_eq_meanETL <- optimize.portfolio(R=R, portfolio=eq_meanETL, optimize_method="DEoptim", search_size=2000, trace=FALSE, traceDE=5)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM