portfolio

Equally Weighted Reallocation of Stock Portfolio at Specific Dates According to a Signal

喜欢而已 提交于 2019-12-07 20:33:33
问题 I want to reallocate a strategy portfolio at specific dates: require(PerformanceAnalytics) require(TTR) require(quantmod) Get asset prices and obtain the daily discrete Returns tickers = c("ABI.BR","AI.PA","AIR.PA","ALV.DE","ASML.AS") getSymbols(tickers, from="2012-01-01", to="2013-12-01") close.prices = do.call(merge, lapply(tickers, function(x) Cl(get(x)))) colnames(close.prices) = c("Anheuser-Busch InBev", "L'Air Liquide","AIRBUS GROUP","Allianz","ASML HLDG") assets.ret = ROC(close.prices

Calculating monthly returns in R

断了今生、忘了曾经 提交于 2019-12-07 11:59:15
问题 This might be an insignificant question but unfortunately I'm unable to solve it. I have a portfolio of stocks of 50 companies. I have the dates and the closing prices on that particular day for each of the companies. Data for each company varies with respect to the date from which the stock is being traded. I used this code for calculating the daily returns: return=matrix(NA,nrow(companies),ncol(companies)-1) for (j in 2:52){ k=0 for (i in 1:nrow(companies)){ if (!is.na(companies[i,j]) & k=

Create efficient frontier in PortfolioAnalytics without an xts object

十年热恋 提交于 2019-12-07 07:25:15
问题 Is there a way to create an efficient frontier in the PortfolioAnalytics package without specifying an xts object of asset returns? Instead I'd like to supply the vector of expected returns and the covariance matrix. 回答1: There are two ways. First you can supply a list containing containing your matrices with the structure shown below and then call optimize.portfolio including this list as an argument. # num_assets is the number of assets in the portfolio momentargs <- list() momentargs$mu <-

Why doesn't solve.QP and portfolio.optim generate identical results?

蓝咒 提交于 2019-12-06 13:49:18
问题 The documentation for portfolio.optim {tseries} says that solve.QP {quadprog} is used to generate the solution for finding the tangency portfolio that maximizes the Sharpe ratio. That implies that results should be identical with either function. I'm probably overlooking something, but in this simple example I get similar but not identical solutions for estimating optimal portfolio weights with portfolio.optim and solve.QP. Shouldn't the results be identical? If so, where am I going wrong?

Equally Weighted Reallocation of Stock Portfolio at Specific Dates According to a Signal

*爱你&永不变心* 提交于 2019-12-06 04:29:33
I want to reallocate a strategy portfolio at specific dates: require(PerformanceAnalytics) require(TTR) require(quantmod) Get asset prices and obtain the daily discrete Returns tickers = c("ABI.BR","AI.PA","AIR.PA","ALV.DE","ASML.AS") getSymbols(tickers, from="2012-01-01", to="2013-12-01") close.prices = do.call(merge, lapply(tickers, function(x) Cl(get(x)))) colnames(close.prices) = c("Anheuser-Busch InBev", "L'Air Liquide","AIRBUS GROUP","Allianz","ASML HLDG") assets.ret = ROC(close.prices,type="discrete")[-1] Now I obtain RSI signals by applying the RSI function to each asset rsi.fct =

Calculating monthly returns in R

孤街醉人 提交于 2019-12-06 01:54:24
This might be an insignificant question but unfortunately I'm unable to solve it. I have a portfolio of stocks of 50 companies. I have the dates and the closing prices on that particular day for each of the companies. Data for each company varies with respect to the date from which the stock is being traded. I used this code for calculating the daily returns: return=matrix(NA,nrow(companies),ncol(companies)-1) for (j in 2:52){ k=0 for (i in 1:nrow(companies)){ if (!is.na(companies[i,j]) & k==0) { base= companies[i,j] k=k+1 } else {if ( k==1) {return[i,j-1] = ((companies[i,j]-base)/base)*100}

Why doesn't solve.QP and portfolio.optim generate identical results?

旧巷老猫 提交于 2019-12-04 19:33:44
The documentation for portfolio.optim {tseries} says that solve.QP {quadprog} is used to generate the solution for finding the tangency portfolio that maximizes the Sharpe ratio. That implies that results should be identical with either function. I'm probably overlooking something, but in this simple example I get similar but not identical solutions for estimating optimal portfolio weights with portfolio.optim and solve.QP. Shouldn't the results be identical? If so, where am I going wrong? Here's the code: library(tseries) library(quadprog) # 1. Generate solution with solve.QP via: comisef

Portfolio Optimisation under weight constraints

喜欢而已 提交于 2019-12-04 15:14:24
With a lot of help from contributors to StackOverflow I have managed to put together a function to derive the weights of a 2-asset portfolio which maximises the Sharpe ratio. No short sales are allowed and the sum of weights add to 1. What I would like to do now is to constrain asset A to not being more or less than 10% from a user defined weight. As an example I would like to constrain the weight of asset A to be no less than 54% or more than 66% (i.e 60% +/- 10%). So on the below example I would end up with weights of (0.54,0.66) instead of the unsconstrained (0.243,0.7570) .I assume this

SOCP Solver Error for fPortoflio using solveRsocp

与世无争的帅哥 提交于 2019-12-02 13:38:33
问题 I would like to use an R SOCP solver to get similar results to the following paper: http://www.optimization-online.org/DB_FILE/2014/05/4366.pdf And doing a bit of googling, it seems like it used to be part of fPortfolioSolver , but that package looks like it no longer exists.... And this looks like how it used to be implemented... https://stat.ethz.ch/pipermail/r-sig-finance/2010q2/006074.html The solver still sort of exists here: https://r-forge.r-project.org/scm/viewvc.php/pkg/fPortfolio/R

Portfolio Optimization SOLVE.QP inequality constraints

谁都会走 提交于 2019-12-02 10:13:02
问题 My name is Grégory and I am trying to compute a Minimum Variance portfolio with the following constraints: Sum of the weights lower or equal to 1 (the portfolio can be fully invested, but it's not an obligation) Sum of the weights higher or equal to 0 (the portfolio can be fully in cash, but it's not an obligation) 0<= Asset weight <= 5% (no short-sales are allowed, and the maximum asset weight is 5%) MV<-function (Returns, percentage = TRUE, ...) { if (is.null(dim(Returns))) { stop("Argument