All Questions
Tagged with programming portfolio-optimization
84 questions
1
vote
1
answer
168
views
Bond portfolio optimization with Python reaching iteration limit
I am using scipy to optimize a hypothetical bond portfolio for maximum yield by choosing from a list of bonds in the portfolio's investable universe while adhering to portfolio constraints such as ...
1
vote
2
answers
114
views
Reverse Optimization: finding the returns that satisfy specific weights given one known return
Here is the premise: I have a three asset portfolio, I know the assets covariance, the client's risk aversion and the expected return of one of the assets. I also have a desired set of weights.
So, 1) ...
1
vote
1
answer
245
views
Reverse optimization: How to generate the expected portfolio returns given the weights and a series of constraints on those weights?
I have the below function in Python. My objective is to back out the expected returns associated with certain portfolio weights given a series of assumptions.
From this I want to generate the expected ...
0
votes
1
answer
206
views
Portfolio optimization with Scipy in Python
I performed Scipy portfolio optimization in two scenarios: 1) when I cannot lend or borrow at the risk-free rate; 2) when I can lend and borrow at rf=1.5%. Now, optimal risky portfolio weights anyway ...
1
vote
0
answers
243
views
Minimum transaction size for portfolio optimization with CVXPY
Long time reader, first time asker!
I am working on a portfolio optimizer where I have a universe which is much larger than potential portfolio and where I want to exclude small transaction, i.e. a ...
0
votes
1
answer
185
views
Incorporating market cap after Hierarchical Risk Parity (HRP) Portfolio Optimization. Using Black Litterman?
Hello financial experts :)
I recently got interested in portfolio optimization. I'm still learning. As I'm familiar with python I started experimenting a little in JupyterNotebooks with riskfolio. I ...
2
votes
1
answer
2k
views
Minimum variance portfolio in Python
I have a portfolio or $N$ assets in $t=10$ days.
...
1
vote
0
answers
107
views
Turnover Constraint ignores initial weights of Portfolio
I am trying to perform a standard portfolio optimization, but with a constraint to how much the final weights of the portfolio are allowed to deviate from a set of initial weights. I do this with the <...
2
votes
1
answer
4k
views
How to calculate Sortino ratio from a weighted portfolio with Python?
In this working example I'm able to calculate a Sharpe ratio (with rf=0) from a weighted portfolio of 3 securities, but how can I modify the code bellow so it calculates a Sortino ratio ?
...
0
votes
0
answers
751
views
Portfolio optimization with Python/CVXPY: DCPError
I'm trying to implement a script for portfolio optimization on a sample universe of 3 future contracts.
I have the following inputs:
current allocation --> number of contracts currently held for ...
0
votes
0
answers
89
views
Generate R data-frame with close prices in wide format instead of log-returns using Tidyquant (R-Project)
I need to generate a wide-formatted data frame with close price (not log returns) from Tidyquant, using syntax that's similar to that listed below for wide-formatting log-returns:
...
0
votes
0
answers
132
views
Optimx not recognizing "Nelder-Mead" method of optimization
I'm trying to run an optimization using optimx, specifically using the Nelder-Mead method since it is a not-derivative method. Below is my code:
...
0
votes
0
answers
108
views
Optimizing/maximizing portfolio returns & defining gradient function in R
I have been searching on this forum and see some similar questions, such as: R packages for calibration (optimization/minimization) of pricing models , but I believe I have a somewhat different ...
0
votes
1
answer
331
views
How to set a fixed return for mean-CVaR portfolio optimization?
I'm using the timeSeries and fportfolio package in R to minimize the CVaR with different constraints for a given portfolio. Everything is working out so far. However, I can't manage to set a fixed ...
1
vote
0
answers
109
views
Which Times Series Database framework for Python is best for portfolio optimization project?
I am starting to build a portfolio optimization algorithm in Python and want to structure a database to manipulate financial data. Although I have Python experience, I have never used SQL or such ...
0
votes
1
answer
60
views
Testing severity of VaR by changing portfolio component weights
Let's assume that I have a portfolio with two components:$$\omega_i = 0.3$$ $$\omega_j = 0.7$$
I also have two P&L vectors, $v_i$ and $v_j$ each containing 1000 P&Ls. I would like to play ...
4
votes
1
answer
374
views
PortfolioAnalytics and regime switching issue
I've been playing around with the R package PortfolioAnalytics and I have spent more time than I'm willing to admit to try and resolve this issue:
When I follow the regime switching example with the ...
3
votes
2
answers
889
views
Find k of n assets that "minimize" the correlation matrix
I'm trying to find an efficient way to select $k$ from $n$ risky assets that are the least correlated with each other. I know that I can perform a brute-force search of all $k$-sized combinations of ...
0
votes
0
answers
395
views
Sharpe ratio differs from Tradingview
I tried to backtest a simple strategy on TradingView, it made 6 trades with these results:
Now I want to calculate Sharpe ratio using definition provided by TradingView.
So, my daily returns(...
1
vote
0
answers
518
views
Deriving the tangency portfolio with a condition in Python
If there are sister-sites better suited for this question please let me know, I thought this to be the most fitting
I have the covariance matrix, the return vector and some scores (ESG scores). The ...
1
vote
1
answer
397
views
cvxpy Portfolio Optimization
I am trying to understand which is the best way to construct the parameters using the cvxpy engine.
I have seen this post:
more of list-like way of constructing constraints etc
and this post:
more ...
2
votes
4
answers
330
views
Cant replicate minimum variance portfolio variance by simulating many random portfolios in R
I have computed the theoretical minimum variance portfolio using the 30 stocks in the Dow.
The formula used is:
$$\underset{N\times 1}{\omega_{mvp}}=\frac{\lambda}{2}\cdot \Sigma^{-1}\iota=\frac{\...
0
votes
0
answers
85
views
optimize.portfolio not processing 'mean' objective
I've just started investigating the capabilities of the PortfolioAnalytics package. I've had it working for smaller considerations, around 20 stocks. These return all objectives I have registered (...
0
votes
0
answers
530
views
Bug found in Optimal Number of Clusters algorithm - from de Prado and Lewis (2018)
I believe I have found a bug in Optimal Number of Clusters (ONC) from the paper "Detection of False Investment Strategies Using Unsupervised Learning Methods".
...
-3
votes
1
answer
352
views
For portfolio variance, why doesn't $Var(X w) = w^\top \Sigma w$? [closed]
From multivariate asset returns $X$, we can calculate the sample covariance matrix $\Sigma$.
The definition of (any) portfolio variance is $w^\top \Sigma w$, where $w$ are portfolio weights.
If $X w$ ...
1
vote
0
answers
2k
views
Maximizing sharpe ratio using cvxpy or cvxopt
I have a dataframe $n$ by $m$ representing $m$ timeseries of returns (each column is a different time series) with total $n$ number of observations, I want to find weight vector of length $m$ such ...
2
votes
0
answers
201
views
Can genetic algorithm help in portfolio optimisation when convexity is not verifiable
I have the following portfolio cost function to maximise:
$$
w^T\mu-\frac{1}{2}\gamma w^T\Sigma w+\frac{1}{6}\gamma^2 w^TM_3(w\otimes w),
$$
which considers the co-skewness ($M_3$ tensor), $γ$ is the ...
1
vote
1
answer
254
views
How to transform a cubic optimisation problem into a quadratic for portfolio allocation
I have the following cost function for portfolio allocation:
$$
w^T\mu-\frac{1}{2}\gamma w^T\Sigma w+\frac{1}{6}\gamma^2 w^TM_3(w\otimes w),
$$
which considers also the co-skewness ($M_3$ tensor), $\...
3
votes
2
answers
513
views
How to add the effect of skewness in the portfolio optimisation objective function?
I have the following risk adjusted portfolio which I optimise,
where gamma is the risk return trade off, $r$ are the returns and $C$ is the covariance matrix which considers scenarios, so it is not ...
1
vote
1
answer
248
views
Ridge and Quadratic Programming for Portfolio Norm Optimization
Much like this post: https://stats.stackexchange.com/questions/119795/quadratic-programming-and-lasso, I'm trying to integrate RIDGE Penalty in a dedicated quadratic solver. In my case, I am working ...
0
votes
0
answers
442
views
Portfolio Optimization via Entropy Pooling in R (Meucci)
does anybody have experience with the Entropy Pooling Approach by Meucci in R?
I am currently trying to do a portfolio optimization with Stocks & Bonds, where a 101 example would be very helpful. ...
0
votes
0
answers
411
views
How to implement copula portfolio optimization?
This a reference request for any python notebooks, packages or blogs that teach how to do asset allocation using multivariate copulas. How can copula portfolio optimization actually be implemented in ...
0
votes
0
answers
124
views
Can I build an efficient frontier using matrix algebra?
If i have a vector of expected returns $A$, a covariance matrix $C$ and a vector of the corresponding weights $W$ for each investment, is it possible to generate the efficient frontier with vector ...
1
vote
0
answers
97
views
Get the weights of porfolio variance given standard deviation
I am trying to create a Simulated Portfolio Optimization based on Efficient Frontier on 50 stocks, which you can find the csv here. Yet it already takes me several minutes to get a suboptimal solution:...
0
votes
1
answer
603
views
Do Fama-French factor portfolios require optimization?
I am going to perform factor crowding analysis for my dissertation and I am struggling to build factor portfolios from the S&P 500 in r.
I built my dataset from the S&P 500 and I am able to ...
0
votes
1
answer
1k
views
Optimization with turnover constraint
I am optimizing using scipy.optimize using SLSQP. I am looking to minimize the variance with some upper bounds and lower bounds on each stock.
I am also looking to constraint the weight so that the ...
1
vote
1
answer
294
views
Portfolio/sub-portfolio optimization
I have a finite amount of 26 assets, the total amount of these assets needs to be allocated to 9 portfolios. Each portfolio has its own required return which needs to be met, using a min-variance ...
1
vote
1
answer
766
views
3
votes
2
answers
2k
views
Is my python solution good? : Global Minimum Variance portfolio with 'no-short sale' constraint
Question
Is my python code an answer (at least a close answer) to get the weight vector of the Global Minimum Variance portfolio problem? My codes are shown below after some explanations.
Details to ...
1
vote
0
answers
193
views
Walk Forward Analysis Using Portfolio Analytics R
I am learning how to use the Portfolio Analytics package in R and I am concerned with overfitting the data for the optimization.
The optimize.portfolio.rebalancing() function has 2 parameters that ...
8
votes
2
answers
3k
views
Random Portfolios vs Efficient Frontier
I understand the concept of the efficient frontier and am able to calculate it in Python. But even when generating 50'000 random 10 asset portfolios, the single portfolios are not even close to the ...
2
votes
0
answers
74
views
Why can't I take the Value at Risk "VaR" as a a risk objective in PerformanceAnalytics? (it does work for "ES)
I am currently playing around with PortfolioAnalytics package in R and some data and I am aiming to create different portfolios with different VaR. However, I am struggling first of all, add.objective(...
2
votes
0
answers
44
views
fPortfolio specify our constraints for efficientPortfolio [closed]
I am working on the library fPortfolio in R and I have a question. How can we fix for a portfolio the sum of weights equal to 1 ? When I study the code, I see that we cannot choose which constraints ...
6
votes
4
answers
698
views
R: Book with extensive examples for either portfolio optimization or volatility forecasting?
I'm at a new job and there's the option to use R (you don't have to, but I'd like to). I used R years ago, so I while I'm somewhat familiar with it, I have forgotten most of it. For me, the best ...
2
votes
1
answer
502
views
Objective function: as close to equal weight as possible
I am having trouble coming up with a function to optimize the weights to be as equal as possible.
It is a long-short portfolio with 6 positions
weights is a cvx variable: [long, long, short, short, ...
2
votes
3
answers
2k
views
Regularizers to compute Minimum Variance Portfolio weights
I need to compute the mimimum variance portfolio using different regularizers, to compare the results and use validation methods to find the optimal parameters. Currently my work has been performed ...
4
votes
2
answers
1k
views
Optimal Portfolio from Efficient Frontier
I found this code on plotly site, using CVXOPT to find the efficient frontier, and then, the optimal Portfolio.
The optimal function is
...
1
vote
0
answers
275
views
How to find the tangency portfolio using quadprog in R with different risk free rates
I am trying to find the optimal tangency portfolio for the efficient frontier (calculated using qp.solver in quadprog) but subject to different risk-free rates.
Demos for quadprog in R show that to ...
5
votes
3
answers
4k
views
Compute tangency portfolio with asset allocation constraints
I am looking to compute the tangency portfolio of the efficient frontier, but taking into account min_allocations and ...
2
votes
0
answers
113
views
VaR calculation using excel gives different value than VaR using R at all c values except at c=0.5
This is VaR calculation in excel using variance-covariance method.
This is VaR calculation in R.
...