Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7925841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:28:38+00:00 2026-06-03T18:28:38+00:00

Here’s an interesting puzzle. Below is an R snippet that identifies the tangency point

  • 0

Here’s an interesting puzzle.

Below is an R snippet that identifies the tangency point of a quadratic function with respect to a line drawn from the point (0,rf) on the y-axis.

For those familiar with portfolio theory, this point is in return and risk space and the solution is set of weights that define the tangency portfolio (max sharpe ratio). The snippet allows for negative weights (i.e. shorts) and there is one equality weight constraint which requires the sum of the weights = 1.

require(quadprog)

# create artifical data
nO     <- 100     # number of observations
nA     <- 10      # number of assets
mData  <- array(rnorm(nO * nA, mean = 0.001, sd = 0.01), dim = c(nO, nA))
rf     <- 0.0001     # riskfree rate (2.5% pa)
mu     <- apply(mData, 2, mean)    # means
mu2    <- mu - rf                  # excess means

# qp
aMat  <- as.matrix(mu2)
bVec  <- 1 # set expectation of portfolio excess return to 1
zeros <- array(0, dim = c(nA,1))
solQP <- solve.QP(cov(mData), zeros, aMat, bVec, meq = 1)

# rescale variables to obtain weights
w <- as.matrix(solQP$solution/sum(solQP$solution))

# compute sharpe ratio
SR <- t(w) %*% mu2 / sqrt(t(w) %*% cov(mData) %*% w)

My question — how to adapt the code to solve for the optimal set of weights such that the sum of weights sum to an arbitrary number (including the corner case of a self-financing portfolio where the sum of weights = 0) as opposed to unity?

Alternatively, you might consider adding an element ‘cash’ to the covariance matrix with variance-covariance of 0, and add an equality constraint requiring the weight on cash = 1. However this matrix would be not be positive semi-definite. Also I suspect the non-cash weights might be trivially zero.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T18:28:39+00:00Added an answer on June 3, 2026 at 6:28 pm

    Let us first explain why this
    actually produces the maximum Sharpe ratio portfolio.

    We want w to maximize w' mu / sqrt( w' V w ).
    But that quantity is unchanged if we multiply w by a number
    (it is “homogeneous of degree 0”):
    we can therefore impose w' mu = 1, and the problem
    of maximizing 1 / sqrt( w' V w ) is equivalent
    to minimizing w' V w.
    The maximum Sharpe ratio portfolio is not unique: they form a line.
    If we want the weights to sum up to 1 (or any other non-zero number),
    we just have to rescale them.

    If we want the weights to sum up to 0,
    we can add that constraint to the problem
    — it only works because the constraint is also homogeneous of degree 0.
    You will still need to rescale the weights, e.g., to be 100% long and 100% short.

    solQP <- solve.QP(cov(mData), zeros, 
      cbind(aMat,1), 
      c(bVec,0), 
      meq = 2
    )
    
    # Let us compare with another solver
    V <- cov(mData)
    library(Rsolnp)
    r <- solnp(
      rep(1/length(mu), length(mu)),
      function(w) - t(w) %*% mu2 / sqrt( t(w) %*% V %*% w ),
      eqfun = function(w) sum(w),
      eqB   = 0,
      LB = rep(-1, length(mu))
    )
    solQP$solution / r$pars  # constant
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code in a function I'm trying to revise. This example works
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is my function: function reCalculate(i) { document.getElementById(Q + i).value = document.getElementById(C + i).value
Here's some of my production code (I had to force line breaks): task =
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()
Here's my function: static Map AddFormation(Map _map, Tile tile, int x, int y, int
Here is a great article about GC may occur at unexpected point of code
Here is my javascript code for a cursor focus function to go to username
Here is what I want to do. Use this HTML line and have the
Here's the setup - I have a view that lists products. On that same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.