[R-SIG-Finance] Using forecasted data in fportfolio
matt at considine.net
matt at considine.net
Fri Nov 8 19:10:04 CET 2013
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
> List-Post: <mailto:r-sig-finance at r-project.org>
> Content-Transfer-Encoding: quoted-printable
> From: ericstrom <ericstrom at aol.com>
> Precedence: list
> MIME-Version: 1.0
> To: r-sig-finance at r-project.org
> Date: Thu, 7 Nov 2013 19:42:54 -0500 (EST)
> Message-ID: <8D0AA32987CA530-1988-16EC8 at webmail-vm004.sysops.aol.com>
> Content-Type: text/plain
> Subject: [R-SIG-Finance] Using forecasted data in fportfolio
> Message: 1
>
> Still trying to figure out the correct way in the fportfolio package
> to de=
> termine the portfolio frontier using a forcasted returns vector
> and/or a fo=
> recasted covariance matrix ? I have no problem coming up with the
> portfoli=
> o frontier using historical returns. But what I want to do is use
> forcasted=
> returns and / or forecasted covariance matrix. For example, if my
> historic=
> al data is in zts, then the following works:spec
> =3DportfolioSpec()frontier=
> <- portfolioFrontier(zts, spec)frontierPlot(frontier,
> risk=3D"Sigma", a=
> uto=3DFALSE)class(zts)[1] "timeSeries"attr(,"package")[1]
> "timeSeries"head(=
> zts)GMT WBLRX LSBRX DBLTX
> TFSHX =
> TBT SPY2012-11-09 0.003013563 -0.002106003
> 0.0000000000 -0.=
> 0036968619 -0.0312447930 -0.0112530152012-11-16 -0.007045827
> -0.003519891 0=
> .0000000000 -0.0037105794 -0.0074161810 -0.0130282882012-11-23
> 0.003025721=
> 0.006326910 0.0000000000 0.0018570107 0.0337662016
> 0.0358429662012-11-=
> 30 0.001006543 0.005590511 0.0018365478 0.0027790662 -0.0096968465
> 0.00=
> 56951462012-12-07 -0.001006543 0.005559431 0.0009170106
> 0.0009246418 0.0=
> 008254231 0.0017955262012-12-14 0.004020106 0.005528694
> 0.0009161705 0.=
> 0046104277 0.0134406219 -0.002155018But suppose instead of using
> historica=
> l returns data, I want to use forecasted returns and/or forecasted
> covarian=
> ce (call them mu1 and covmat). What are the analogous statements to
> portfol=
> ioFrontier and frontierPlot using mu1 and covmat as inputs instead of
> histo=
> rical returns data ?> class(mu1)[1] "numeric"> class(covmat)[1]
> "matr=
> ix"> mu1 WBLRX LSBRX DBLTX TFSHX
> =
> TBT SPY 0.0013537910 0.0010611297 0.0001845725
> -0.0021064133=
> 0.0032720265 0.0052493188 > covmat WBLRX
> LSBRX =
> DBLTX TFSHX TBT SPYWBLRX
> 8.980255e-05 =
> 5.538752e-06 3.384955e-06 -2.753534e-06 -2.347333e-05
> 6.669676e-06LSBRX =
> 5.538752e-06 5.017554e-05 1.297063e-05 -1.055112e-05 -8.994622e-05
> 2.555=
> 718e-05DBLTX 3.384955e-06 1.297063e-05 1.848077e-05 -6.448218e-06
> -5.496=
> 978e-05 1.561903e-05TFSHX -2.753534e-06 -1.055112e-05 -6.448218e-06
> 4.277=
> 017e-05 4.471585e-05 -1.270549e-05TBT -2.347333e-05 -8.994622e-05
> -5.496=
> 978e-05 4.471585e-05 1.388306e-03 -1.083118e-04SPY 6.669676e-06
> 2.555=
> 718e-05 1.561903e-05 -1.270549e-05 -1.083118e-04 2.170639e-04I've
> checked=
> the package documentation and I am not finding anything. Any help
> would be=
> appreciated.
More information about the R-SIG-Finance
mailing list