简体   繁体   English

计算负收益的投资组合权重的算法?

[英]algorithm to calculate portfolio weights with negative returns?

Summary概括

Below is the full question (a bit complicated in its full form) here's a super simplified version (which is the heart of what I'm asking).下面是完整的问题(完整形式有点复杂)这是一个超级简化的版本(这是我要问的核心)。 If I told you to give me the weights of 49 and 17, you would take 66 (49+17) and divide each number by 66 (49/66=74% and 17/66=26%).如果我告诉你给我 49 和 17 的权重,你会取 66 (49+17) 并将每个数字除以 66(49/66=74% 和 17/66=26%)。 My question is, if I added a negative number -27 to the above numbers, how would you weight them (if I couldn't use a negative weight)?我的问题是,如果我在上面的数字中加上一个负数 -27,你会如何给它们加权(如果我不能使用负权重)?

I somehow need to represent the negative number in the overall weight but the negative weight is throwing my numbers off.我不知何故需要在总重量中表示负数,但负重量使我的数字消失了。 39(49 + 17 + -27), causes 39/39=1.25%, 17/39=44%, and -27/39=-69%. 39(49 + 17 + -27),导致 39/39=1.25%、17/39=44% 和 -27/39=-69%。 So in the example below, if this were stocks and I gave you $100 how would you know how much to buy?所以在下面的例子中,如果这是股票,我给你 100 美元,你怎么知道要买多少?

Detailed question详细问题

I'm having a bit of trouble figuring out an algorithm (or the logic how to do this).我在弄清楚算法(或如何执行此操作的逻辑)时遇到了一些麻烦。

Stock       percent of return              Return
Blue        .98                            50       
Red         .85                            20       
Black       .90                           -30      

It's basically providing us with a report saying we want.98% of the return of 50%, 85% of the return from 20% and 90% of the returns from -30 (the total in this case is 39%).它基本上是在向我们提供一份报告,说我们想要 50% 的回报率的 98%、20% 的回报率的 85% 和 -30 的回报率的 90%(本例中的总回报率为 39%)。 I'm unsure how to translate this into an actual portfolio (like how much to buy to get this amount if I do not hold the fund already)?我不确定如何将其转化为实际投资组合(例如,如果我还没有持有该基金,要购买多少才能获得该金额)?

I'm starting to feel this is not possible, but I'm basically asking if I gave you the above table (name,return and % of return I want to capture) and $100 how can you make that portfolio?我开始觉得这是不可能的,但我基本上是在问我是否给了你上面的表格(名称、回报和我想要捕获的回报百分比)和 100 美元你如何制作那个投资组合? If I only gave you one stock that was 50% and said I wanted 100% of its returns you could easily just buy $100 of that single stock.With two stocks you could add the total returns/weights and get the weight but how do you deal with negative returns you want to capture?如果我只给你一只 50% 的股票,并说我想要 100% 的回报,你可以很容易地购买这只股票的 100 美元。有了两只股票,你可以添加总回报/权重并得到权重,但你如何处理您想捕获的负收益?

I don't think I'm getting this right but here's my logic so far (If this is totally wrong, please ignore and suggest anything you like).我不认为我做对了,但到目前为止这是我的逻辑(如果这完全错误,请忽略并提出任何你喜欢的建议)。

Get list of data
total_return = multiple percent_of_return and return (do this as a recursion for all stocks in the list)
take total of all items in total_return (using absolute numbers..no negatives so above 39 equals 42) and figure out the weight of each from that.
multiply these weights by stock price and divide by total to give weight.

The result of this is (note:the total changed from 39% to 93%):这样做的结果是(注:总数从 39% 变成了 93%):

Blue 0.52688172
red 0.182795699
black 0.290322581

The problem, which I'm really unsure if is converting a negative weight into a absolute (positive) weight.这个问题,我真的不确定是否将负权重转换为绝对(正)权重。 I'm not good with math (and worst with finance) but I'm unsure how to 'buy' a percent of negative returns (the two data points I'm given, but I can enrich it with other data if needed like stock price, etc.).我不擅长数学(最不擅长金融),但我不确定如何“购买”负回报的百分比(我给出的两个数据点,但如果需要,我可以用其他数据丰富它,比如股票价格等)。 Also, just to make it clear, I do not own these portfolios already so I can't just take these weights against an existing portfolios, I am using the above information as guidance to create a new one (just need to figure out an algo to do that).另外,为了清楚起见,我还没有拥有这些投资组合,所以我不能只将这些权重与现有投资组合进行对比,我使用上述信息作为创建新投资组合的指导(只需要找出一个算法要做到这一点)。

Update更新

I always learn from code so here's my code (in Python) and some test cases (it's horribly ugly as I'm prototyping just to understand the logic of how to do this):我总是从代码中学习,所以这是我的代码(用 Python 编写)和一些测试用例(它非常丑陋,因为我正在制作原型只是为了理解如何做到这一点的逻辑):

overall_total_value = []
def test(data_return, datacoeff, data_value):
    total_results = 0
    data_total_of_return = {}
    for x in data_return:
        current_value = data_return[x] * (datacoeff[x]*.001)
        data_total_of_return[x] = current_value
        total_results = total_results + current_value

    #abs
    abs_total_value = 0
    for x in data_total_of_return:
        #print x, '=', abs(data_total_of_return[x])
        abs_total_value = abs_total_value + abs(data_total_of_return[x])
    
    print abs_total_value
    weight = {}
    for x in data_total_of_return:
        weight[x] = abs(data_total_of_return[x]/abs_total_value)
    
    total_value = 0
    for x in weight:
        valuer = weight[x] * data_value[x]
        print x, weight[x], '=', valuer
        total_value = total_value + valuer
    
    print 'ABS total % return: ',total_results
    print total_value
    overall_total_value.append(total_value)
    
    print "*"*30
    
    
data_return = {'Blue':50, 'Red':20, 'Black':-30}
data_value = {'Blue':10.4, 'Red':4, 'Black':8}

datacoeff = { "Blue": 78 , "Red": 0 , "Black": 0 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 48 , "Red": 75 , "Black": 0 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 46 , "Red": 80 , "Black": 0 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 38 , "Red": 100 , "Black": 0 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 62 , "Red": 100 , "Black": 40 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 100 , "Red": 20 , "Black": 50 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 98 , "Red": 55 , "Black": 70 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 90 , "Red": 75 , "Black": 70 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 100 , "Red": 65 , "Black": 80 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 98 , "Red": 70 , "Black": 80 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 96 , "Red": 75 , "Black": 80 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 94 , "Red": 80 , "Black": 80 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 92 , "Red": 85 , "Black": 80 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 90 , "Red": 90 , "Black": 80 , }
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 88 , "Red": 95 , "Black": 80 , }
test(data_return, datacoeff, data_value)
test(data_return, datacoeff, data_value)
datacoeff = { "Blue": 98 , "Red": 100 , "Black": 100 , }
test(data_return, datacoeff, data_value)

Right now you're trying to calculate this entierly off of the return.现在你正试图完全从回报中计算出来。 If you're able to include current market value as well (ie the current (price * size) of the positions if you were to sell them right now) you will achieve the actual weight of each position within your portfolio.如果您还能够包括当前市场价值(即,如果您现在要卖出头寸,则头寸的当前(价格 * 大小))您将在您的投资组合中实现每个 position 的实际权重。 From there it's a simple matter of multiplyting this <1 weight by whatever cash you're injecting into the portfolio.从那里开始,将这个 <1 的权重乘以你注入投资组合的现金就很简单了。

If you have access to the stock price, pull that in and use the following logic.如果您有权访问股票价格,请将其拉入并使用以下逻辑。

decimal portfolioAssets;
Dictionary<stock, decimal> stockAssets = new Dictionary<stock, decimal>();
foreach(stock in stocks)
{
    decimal assets = stock.Shares*stockPrice;
    portfolioAssets =+ assets;
    stockAssets.Add(stock, assets);
}

foreach(stock in stocks)
{
decimal weight = stockAssets[stock]/portfolioAssets;
//do something with weight 
}

You are getting this all wrong in my opinion (or there's some confusion in your data).我认为你完全错了(或者你的数据有些混乱)。 I assume that the return column is something you don't have in advance, otherwise you could engage in arbitrage, which is nonsense.我假设返回栏是你事先没有的东西,否则你就可以套利,这是废话。 Basic theory: some stocks have positive beta coefficients (they go with the market), others have negative beta coefficients (they go against the market).基本理论:一些股票的贝塔系数为正(与市场 go),其他股票的贝塔系数为负(与市场 go)。 In the situation you have proposed the first two stocks have (probably) a beta coefficient with the same sign and the remaining one a beta coefficient of the opposite sign.在您提议的情况下,前两只股票(可能)具有相同符号的贝塔系数,而其余一只股票具有相反符号的贝塔系数。 Therefore, since you are trying to reduce your losses it's normal for one of your stocks to have negative returns, as the loss is offset by the gains in the other two stocks.因此,由于您正试图减少损失,因此您的一只股票出现负回报是正常的,因为损失会被其他两只股票的收益所抵消。

Let's assume for sake of simplicity that you are trying to invest 100$.为简单起见,我们假设您正尝试投资 100 美元。

You want to get.98 of the returns of the first stock (whatever they are).您想要获得第一只股票(无论它们是什么)回报的 98。

You want to get.85 of the returns of the second stock (whatever they are).您想要获得第二只股票(无论它们是什么)收益的 85。

You want to get.90 of the returns of the third stock (whatever they are).您想要获得第三只股票(无论它们是什么)收益的 90。

Now let's normalize the desired returns so that they sum to 1 (and by maintaining the proportions.).现在让我们对期望回报进行归一化,使它们总和为 1(并保持比例)。

For each $ in your portfolio you want to buy:对于您要购买的投资组合中的每一美元:

.98/(.98+.85+.90) = 0.358974358974359$ of the first stock第一只股票的 .98/(.98+.85+.90) = 0.358974358974359$

.85/(.98+.85+.90) = 0.31135531135531136$ of the second stock第二只股票的 .85/(.98+.85+.90) = 0.31135531135531136$

.90/(.98+.85+.90) = 0.32967032967032966$ of the third stock第三只股票的 .90/(.98+.85+.90) = 0.32967032967032966$

Therefore considering your endowment of 100$ and assuming that you can freely buy portions of stocks you'll invest respectively:因此,考虑到您的 100 美元捐赠并假设您可以自由购买您将分别投资的部分股票:

$35.90, $31.14, $32.96 35.90 美元、31.14 美元、32.96 美元

And finally, (and this is not the case.) whenever you find a minus sign in the desired returns (first column) it actually means that you're short selling that stock (ie borrowing the underlying asset to sell it in the future at a -hopefully- higher price).最后,(事实并非如此。)每当你在期望回报率(第一列)中找到一个负号时,它实际上意味着你正在卖空该股票(即借入标的资产以在未来以一个 - 希望 - 更高的价格)。

>>> desired_returns = [.98,.85,.9]
>>> real_weights = [i/sum([abs(j) for j in desired_returns]) for i in desired_returns]
>>> real_weights
[0.358974358974359, 0.31135531135531136, 0.32967032967032966]
>>> cash_available=100
>>> labels=['blue','red','green']
>>> for i in range(len(desired_returns)):
...     if desired_returns[i]>=0:
...          print "Buy %s$ of the stock %s" % (cash_available*real_weights[i],labels[i])
...     else:
...           print "Short sell %s$ of the stock %s" % (abs(cash_available*real_weights[i]),labels[i])
Buy 35.8974358974$ of the stock blue
Buy 31.1355311355$ of the stock red
Buy 32.967032967$ of the stock green

Can you just surround your entire formula with ABS(), to return the absolute value, which would eliminate your negative numbers?你能不能用 ABS() 包围你的整个公式,返回绝对值,这会消除你的负数?

If it's your position that is short then surely the number of shares should be negative?如果是你的 position 做空那么股数肯定应该是负数吧? If you then have a -ve number of shares each with a -ve value you will have a +ve value in your portfolio.如果您随后拥有 -ve 股,每股的价值为 -ve,那么您的投资组合中的价值将为 +ve。 In general, though, it's not necessary that +/- signs match up, why can't you hold shares which have lost value and make a -ve contribution to your wealth?不过,一般来说,+/- 符号不一定要一致,为什么你不能持有已经贬值的股票并为你的财富做出 -ve 贡献呢?

If you bought 90 shares which lost 30 in value then you have lost 2700 dongs (or whatever your local currency is).如果您购买了 90 股而价值下跌了 30 股,那么您将损失 2700 盾(或任何您当地的货币)。 Personally I don't have a problem with the idea that the contribution to the total value of a portfolio is, say, -34.54%.就个人而言,我对投资组合总价值的贡献是-34.54% 的想法没有问题。 However, I agree that it does look a little odd that one of your shares contributes more than 100% to the value of your portfolio.但是,我同意您的一只股票对您的投资组合价值的贡献超过 100%,这看起来确实有点奇怪。 This indicates that perhaps you should follow the advice given in the answer to the question you linked to and ignore, in weighting the values of the holdings in your portfolio, negative values entirely.这表明也许您应该遵循您链接到的问题的答案中给出的建议,并在对您投资组合中持有的资产的价值进行加权时完全忽略负值。

What I wouldn't do, in your case, is start ignoring -ve numbers because they leave your results looking untidy.在您的情况下,我不会做的是开始忽略 -ve 数字,因为它们会使您的结果看起来不整洁。 The information contained in the - is essential to valuing your portfolio. - 中包含的信息对于评估您的投资组合至关重要。 Choose derivations of the raw information that suit your purposes, I mean, if you don't like the way the weights come out when calculated as in your question choose a different statistic, one that suits your purposes.选择适合您目的的原始信息的推导,我的意思是,如果您不喜欢按照您的问题计算权重的方式,请选择适合您目的的不同统计数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM