need help setting up a min Tracking Error optimization

1 message Options
Embed this post
Permalink
tom81

need help setting up a min Tracking Error optimization

Reply Threaded More More options
Print post
Permalink
I am trying to get a optimization based on tracking error (TE) , but I cant get it to work. My problem is getting the data from the benchmark included in the TE calculation.

Here is a piece of code where I'm currently at:

library(PerformanceAnalytics)
library(fPortfolio)

# Set up a dataset
Data <- LPP2005.RET[,1:6]

# Construct a benchmark
benchmarkWeights = c(rep(.5,2),rep(0,4))
Benchmark <- Data %*% benchmarkWeights

# Set up Optimization
Spec <- portsfolioSpec()
setTargetReturn(Spec) <- mean(Rb)

setObjective(Spec) = c("Objective", "Return", "Risk")
Return <- function(weights)(getMu(Data) %*% weights)
Risk <- function(weights,Benchmark ){TrackingError(Data %*% weights, Benchmark , scale = 252)}
Objective <-function(weights,Benchmark ) Risk(weights,Benchmark )

x = minriskPortfolio(Data, Spec, "LongOnly")
x

# Optimized TE
w = getWeights(x)
TrackingError(Data %*% w,Benchmark , scale = 252)

#Correct TE
TrackingError(Data %*% benchmarkWeights ,Benchmark , scale = 252)


Would appreciate any help
Regards Tom