[R] portfolio.optim and assets with weigth equals to zero...
Hello. I don't understand a particular output of portfolio.optim (tseries). I have 4 assets and the portfolio.optim returns an asset with weight equals to zero. If I do a portfolio.optim with 3 assets, without the asset with weight equals to zero, it returns a completely different result. That's I would expected the same weights as the run with 4 assets. Below the code. Thanks in advance, Alberto Santini - require(tseries) f.mi - coredata(get.hist.quote(F.MI, start=2006-09-03, compression=w, quote=Close)) eng.mi - coredata(get.hist.quote(ENG.MI, start=2006-09-03, compression=w, quote=Close)) tis.mi - coredata(get.hist.quote(TIS.MI, start=2006-09-03, compression=w, quote=Close)) spmib - coredata(get.hist.quote(^SPMIB, start=2006-09-03, compression=w, quote=Close)) f.mi.rets - diff(log(f.mi[1:(length(f.mi)-1)])) eng.mi.rets - diff(log(eng.mi[1:(length(eng.mi)-1)])) tis.mi.rets - diff(log(tis.mi[1:(length(tis.mi)-1)])) spmib.rets - diff(log(spmib[1:(length(spmib)-1)])) x - cbind(f.mi.rets, eng.mi.rets, tis.mi.rets, spmib.rets) res - portfolio.optim(x); res$pw x2 - cbind(f.mi.rets, eng.mi.rets, spmib.rets) res - portfolio.optim(x2); res$pw -- View this message in context: http://www.nabble.com/portfolio.optim-and-assets-with-weigth-equals-to-zero...-tp19289567p19289567.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] portfolio.optim and assets with weigth equals to zero...
I tried with Rmetrics too, but the behaviour is the same. So I am missing something... Very interesting to understand why. :) I think it's a numerical problem: maybe, zero is not zero, it's very near to zero. Regards, Alberto Santini - require(fPortfolio) require(tseries) assets - c( F.MI, ENG.MI, TIS.MI, ^SPMIB ) f.mi - get.hist.quote(F.MI, start=2006-09-03, end=2008-09-03, compression=w, quote=Close) eng.mi - get.hist.quote(ENG.MI, start=2006-09-03, end=2008-09-03, compression=w, quote=Close) tis.mi - get.hist.quote(TIS.MI, start=2006-09-03, end=2008-09-03, compression=w, quote=Close) spmib - get.hist.quote(^SPMIB, start=2006-09-03, end=2008-09-03, compression=w, quote=Close) X - cbind(f.mi[1:(length(f.mi)-1)], eng.mi[1:(length(eng.mi)-1)], tis.mi[1:(length(tis.mi)-1)], spmib[1:(length(spmib)-1)]) colnames(X) - assets R - as.timeSeries(returns(X)) # Spec = portfolioSpec(model = list(type = c(MV), # estimator = c(mean, cov), tailRisk = list(), params = list()), # portfolio = list(weights = NULL, targetReturn = 0, #targetRisk = 0, targetAlpha = 0.05, riskFreeRate = NULL, #nFrontierPoints = 50), # solver = list(solver = c(quadprog), trace = FALSE)) Spec = portfolioSpec() frontier - portfolioFrontier(R, Spec, c(minW[1:nAssets]=0)) # weightsSlider(frontier) ptf - [EMAIL PROTECTED](getTargetRisk(frontier)[,1])+1,]*100 ptf assets2 - c( ENG.MI, ^SPMIB ) X2 - cbind(eng.mi[1:(length(eng.mi)-1)], spmib[1:(length(spmib)-1)]) colnames(X2) - assets2 R2 - as.timeSeries(returns(X2)) frontier - portfolioFrontier(R2, Spec, c(minW[1:nAssets]=0)) ptf - [EMAIL PROTECTED](getTargetRisk(frontier)[,1])+1,]*100 ptf -- View this message in context: http://www.nabble.com/portfolio.optim-and-assets-with-weigth-equals-to-zero...-tp19289567p19299309.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] xirr...
Hello. A few weeks ago, I need to calculate the Internal Rate of Return for irregular intervals. There is the package 'financial', with the function 'cashflow', calculating irr for regular intervals. So I developed xirr, managing irregular intervals, that's accepting a vector of dates as xirr Excel function. You can find the code at http://albertosantini.blogspot.com/2008/01/xirr.html #~ Title: XIRR Excel function simulation #~ #~ Reference 1: How to manage irregular intervals - http://www.geocities.com/accessreddy/excel/xirr.htm #~ Reference 2: How to calculate IRR manually - http://www.s-anand.net/Calculating_IRR_manually.html #~ #~ Step 1: enter zeroes (0) against dates that do not have any cash outflow or inflows. #~ Step 1bis: calculate IRR for these cash flow values using normal IRR function. #~ Step 1tris: or using an iteractive approach as bisection method to find the NPV zeroes. #~ Step 2: multiply this value of IRR by 365 to get annual IRR (since, these are daily cash flows). #~ Step 3: refine using the formula =( 1+ R / 365) ^ 365 - 1), where R is the the value obtained in Step2. #~ Regards, Alberto Santini -- View this message in context: http://www.nabble.com/xirr...-tp17203475p17203475.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there in R a function equivalent to the mround, as found in most spreadsheets?
Hello Luca. Dr. Ottorino-Luca Pantani wrote: ... c(1803.02, 193.51, 3.47) Each solution is to be taken with 3 different pipettes (5000, 250 and 10 µL Volume max) and each of those delivers volumes in steps of 50 µL, 5 µL or 1µL, respectively Since the above values would eventually become c(1800, 195, 3) ... You find a complete solution at http://albertosantini.blogspot.com/2008/05/mround.html It checks the sign of the number and the multiple and it hacks the issue of rounding off a 5 respect IEC 60559 standard. The test cases are: mround(10, 3) # 9 mround(-10, -3) # -9 mround(1.3, 0.2) # 1.4 mround(5, -2) # error mround(1.7, 0.2) # 1.8 mround(321.123, 0.12) # 321.12 mround(1803.02, 50) # 1800 mround(193.51, 5) # 195 mround(3.47, 1) # 3 Regards, Alberto -- View this message in context: http://www.nabble.com/Is-there-in-R-a-function-equivalent-to-the-mround%2C-as-found-in-most-spreadsheets--tp17143519p17170296.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.