[R-sig-finance] fPortfolio

Bill Hutchison hutch at moneyware.com
Mon Jun 20 18:08:04 CEST 2005


The pfolio error seems to be a bug, so I have solved it by adding

	pfolio <- NULL

to the function, and replacing portfolioMarkowitz with my own version.

Here is the full function:

portfolioMarkowitz <- function (x, targetReturn, title = NULL, description =
NULL) 
{
    x = as.matrix(x)
    opt = .portfolio.optim(x = x, pm = targetReturn, covmat = cov(x))
		pfolio <- NULL #added to fPortfolio original code
    pfolio$what = "portfolio"
    pfolio$method = "QP"
    pfolio$opt = opt
    pfolio$pw = opt$pw
    pfolio$pm = opt$pm
    pfolio$ps = opt$ps
    if (is.null(title)) 
        title = "Mean-Variance Portfolio Optimization"
    if (is.null(description)) 
        description = as.character(date())
    new("fPFOLIO", call = as.call(match.call()), method = "Quadratic
Programming", 
        model = "Markowitz Portfolio", data = as.data.frame(x), 
        pfolio = pfolio, title = as.character(title), description =
as.character(description))
} 

Bill Hutchison

-----Original Message-----
From: r-sig-finance-bounces at stat.math.ethz.ch
[mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of L.Isella
Sent: Monday, June 20, 2005 9:46 AM
To: r-sig-finance at stat.math.ethz.ch
Subject: [R-sig-finance] fPortfolio

Dear All,
I have just started learning R and I am interested in using it for financial
applications.
I am not running the latest release of R and my OS is Ubuntu Linux (almost
equal to Debian as far as R is concerned).
I installed some extra packages to run fPortfolio.
I may have made some mistake as when I enter library() I get the warning: 
Warning message: 
library '/usr/local/lib/R/site-library' contains no package in: library() 

anyway, the fPortfolio library seems to load regularly; the output of
library(fPortfolio) does not produce any warnings but only a list of masked
packages.
Then, as a simple test, I form a simple matrix myport containing 3 assets
each with a few return values:

myport
    V1    V2    V3
1 0.04 0.020 0.060
2 0.01 0.060 0.059
3 0.09 0.014 0.058
4 0.02 0.017 0.062
5 0.06 0.019 0.063

Now if I try working out the composition of a portfolio without short
selling I do not get a positive answer for certain expected returns e.g.:

> myPortfolio = portfolioMarkowitz(myport, targetReturn = 0.01, title = 
> null, description = null)
Error in .solve.QP(covmat, dvec, Amat, bvec = b0, meq = 2) : 
	constraints are inconsistent, no solution!

but what bothers me is this error message I get when I choose another
expected return:


> myPortfolio = portfolioMarkowitz(myport, targetReturn = 0.03, title = 
> null, description = null)
Error in portfolioMarkowitz(myport, targetReturn = 0.03, title = null,  : 
	Object "pfolio" not found

As I wrote, I am still pretty new to R, so I do not know exactly how to deal
with it, but it seems to me that I followed closely the example in the
fPortfolio documentation, so I do not understand what is going wrong.
Best Regards
Lorenzo

_______________________________________________
R-sig-finance at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance



More information about the R-sig-finance mailing list