Skip to content
Prev 12012 / 15274 Next

Using forecasted data in fportfolio

Here's how I approached it at one point when I wanted to use a 
consultant's data as input (code is pulled from a larger script, so 
doesn't stand alone ...).  There may be much easier/better ways.

expRet # this is the expected return of the asset classes
covM   # is a positive definite or near p.d. variance/covariance matrix
	# derived from asset class correlations and standard deviations
library(timeSeries)
library(MASS)
#create returns series
testdata<- 
timeSeries(mvrnorm(n=500,mu=expRet,Sigma=covM,empirical=TRUE))
#check : this should be a set of zeros
cor(testdata)-ia2$correlation
#create price series - used elsewhere
testprices<-100*apply(testdata,2,function(x) cumprod(1+x))
testprices<-rbind(matrix(rep(100,length(expRet)),nrow=1),testprices)
colnames(testprices)<-colnames(testdata)
#check that expected means are correct
colMeans(apply(testprices,2,function(x) 
ROC(x,type="discrete")),na.rm=TRUE)-expRet
library(fPortfolioAdvanced)
the_hull<-feasleHull(testdata)
...

Hope this helps,
Matt