Skip to content

Commit 265fff9

Browse files
committed
update extract_risk man page and EQS EF
1 parent 9b80308 commit 265fff9

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

man/extract_risk.Rd

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sandbox/EQS Efficient Frontier.R

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
############################## 1. EQS example ###################################
2+
library(PortfolioAnalytics)
3+
library(PCRA)
4+
5+
# Load Data
6+
# Select 10 midcap stocks and risk-free rate
7+
stockItems <- c("Date", "TickerLast", "CapGroupLast", "Return",
8+
"MktIndexCRSP", "Ret13WkBill")
9+
dateRange <- c("1997-01-31", "2001-12-31")
10+
ret <- selectCRSPandSPGMI(periodicity = "monthly",
11+
dateRange = dateRange,
12+
stockItems = stockItems,
13+
factorItems = NULL,
14+
subsetType = "CapGroupLast",
15+
subsetValues = "MidCap",
16+
outputType = "xts")
17+
k <- 5
18+
nset <- seq(k,k+45,by = 5)
19+
midcap10andRF <- ret[,c(nset,69)]
20+
midcap10 <- midcap10andRF[,1:10]
21+
riskFree <- mean(midcap10andRF[,11])
22+
funds <- colnames(midcap10)
23+
24+
# Build long-only EQS portfolio
25+
pspec = portfolio.spec(assets=funds)
26+
pspec = add.constraint(pspec,type = "full_investment")
27+
pspec = add.constraint(pspec, type="long_only")
28+
pspecEQS = add.objective(portfolio=pspec, type="risk", name="EQS")
29+
optimize.portfolio(midcap10, pspecEQS, optimize_method = "CVXR")
30+
31+
############################## 2. Efficient Frontier ###################################
32+
# Test 1: minEQS with large turnover target, small penalty
33+
pspecEQS.TO2s = add.constraint(pspecEQS, type="turnover", turnover_target = 0.7, turnover_penalty = 1e-10)
34+
optTO2s = optimize.portfolio(midcap10, pspecEQS.TO2s, optimize_method="CVXR")
35+
round(optTO2s$weights, 6) # I increased the precision
36+
optTO2s$opt_values
37+
38+
# Test 2: minEQS with small turnover target, small penalty
39+
pspecEQS.TO05s = add.constraint(pspecEQS, type="turnover", turnover_target = 0.3, turnover_penalty = 1e-10)
40+
optTO05s = optimize.portfolio(midcap10, pspecEQS.TO05s, optimize_method="CVXR")
41+
round(optTO05s$weights, 6)
42+
optTO05s$opt_values
43+
44+
# Test 3: EQS with turnover Efficient Frontier
45+
# Compare TO with no TO for EQS portfolio
46+
# Note: For CSM and EQS efficient frontiers, chart.EfficientFrontier() doesn't work.
47+
# You can only use plotFrontiers()
48+
legend_labels <- c("No TOC", "TOC = 0.7", "TOC = 0.3")
49+
50+
eqs.NTO = meaneqs.efficient.frontier(pspecEQS, midcap10, optimize_method = 'CVXR')
51+
eqs.TO2s = meaneqs.efficient.frontier(pspecEQS.TO2s, midcap10, optimize_method = 'CVXR')
52+
eqs.TO05s = meaneqs.efficient.frontier(pspecEQS.TO05s, midcap10, optimize_method = 'CVXR')
53+
plotFrontiers(midcap10, frontiers=list(eqs.NTO, eqs.TO2s, eqs.TO05s),
54+
legend.labels = legend_labels, risk='EQS')

0 commit comments

Comments
 (0)