将股价因素作为optimize.portfolio的约束

时间:2019-04-14 18:59:32

标签: stock quantitative-finance r-portfolioanalytics

在R的optimize.portfolio包中使用PortfolioAnalytics函数时,我很难在将股票价格因素纳入最佳加权中添加约束。例如,如果我有100美元的资本可用于投资(总投资组合),而股票的股价为3.17美元(例如),则无法将头寸加权为4.00%(没有杠杆或卖空,对吗?)

我已经搜索了StackOverflow和各种PerformanceAnalytics文档,但是找不到与该问题有关的任何材料。

到目前为止,我的投资组合优化代码是这样的:

tickers <- c("AAPL","AMZN",...) #not all tickers included for sake of space
start_date <- "2017-01-01"
price_data <- tq_get(tickers, get = "stock.prices", from = start_date)
names(price_data) <- c("ticker", "date", "open", "high", "low", 
                       "close", "volume", "adjusted")

price_data_wide <- price_data %>%
  select_("ticker", "date", "adjusted") %>%
  group_by(ticker) %>%
  spread(key = ticker, value = adjusted)

price_data_wide <- as.xts(price_data_wide[,-1], 
                          order.by = price_data_wide$date) 

returns <- Return.calculate(price_data_wide, method = "discrete") %>%
  na.omit()

mean_ret <- colMeans(returns)
cov_smp <- cov(returns)

p <- portfolio.spec(assets = colnames(returns))
p

p <- add.objective(portfolio = p, type = "risk", name = "var")
p <- add.objective(portfolio = p, type = "return", name = "mean")
p <- add.constraint(portfolio = p, type = "full_investment")
p <- add.constraint(p, type = "box", min = 0.000, max = 0.050)

opt_p <- optimize.portfolio(R = returns, portfolio = p, 
                            optimize_method = "ROI", trace = FALSE, 
                            maxSR = TRUE, rf = 0.025/252)
opt_p

理想地,在上述示例中,R建议权重为3.17%,6.34%,9.51%等,因为如果价格为3.17美元,则购买100美元投资组合中的示例股票将占3.17%, / p>

任何帮助将不胜感激,在此先感谢您!

0 个答案:

没有答案