Skip to main content
Tweeted twitter.com/StackQuant/status/1136014956980310019
Changed a function to account for weak weight allocation formula
Source Link

EDIT Since the weight generation process of my random portfolios seems to preffer too similar portfolio I changed the following function:

def random_portfolios(num_portfolios, mean_returns, cov_matrix, risk_free_rate):
    results = np.zeros((3,num_portfolios))
    weights_record = []
    for i in range(num_portfolios):
        weights = abs(np.random.randn(len(mean_returns)))
        weights[weights<1] = 0
        if sum(weights)==0:
            print("sum=0")
            indexes = np.unique(np.random.randint(0,10,3)).tolist()
            weights[indexes] = abs(np.random.randn(len(indexes)))
        weights /= np.sum(weights)
        weights_record.append(weights)
        portfolio_std_dev, portfolio_return = portfolio_annualised_performance(weights, mean_returns, cov_matrix)
        results[0,i] = portfolio_std_dev
        results[1,i] = portfolio_return
        results[2,i] = (portfolio_return - risk_free_rate) / portfolio_std_dev
    return results, weights_record

After doing so, the Portfolios are way better distributed:

Portfolios after new weighting scheme

So, can we then agree that the above code does what it should and I can continue from here?

EDIT Since the weight generation process of my random portfolios seems to preffer too similar portfolio I changed the following function:

def random_portfolios(num_portfolios, mean_returns, cov_matrix, risk_free_rate):
    results = np.zeros((3,num_portfolios))
    weights_record = []
    for i in range(num_portfolios):
        weights = abs(np.random.randn(len(mean_returns)))
        weights[weights<1] = 0
        if sum(weights)==0:
            print("sum=0")
            indexes = np.unique(np.random.randint(0,10,3)).tolist()
            weights[indexes] = abs(np.random.randn(len(indexes)))
        weights /= np.sum(weights)
        weights_record.append(weights)
        portfolio_std_dev, portfolio_return = portfolio_annualised_performance(weights, mean_returns, cov_matrix)
        results[0,i] = portfolio_std_dev
        results[1,i] = portfolio_return
        results[2,i] = (portfolio_return - risk_free_rate) / portfolio_std_dev
    return results, weights_record

After doing so, the Portfolios are way better distributed:

Portfolios after new weighting scheme

So, can we then agree that the above code does what it should and I can continue from here?

Became Hot Network Question
deleted 7 characters in body
Source Link

I understand the concept of the efficient frontier and are well awaream 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 efficient frontier.

I understand the concept of the efficient frontier and are well aware to calculate it in Python. But even when generating 50'000 random 10 asset portfolios, the single portfolios are not even close to the 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 efficient frontier.

added 4 characters in body
Source Link

I understand the concept of the efficient frontiertfrontier and are well aware to calculate it in Python. But even when generating 50'000 random 10 asset portfolios, the very portfoliosingle portfolios are not even close to the efficient frontier.

I see that, for example, the maximum sharpe ratio portfolio has very pronounced allocation (most of the 10 asset get 0 allocation).

I understand the concept of the efficient frontiert and are well aware to calculate it in Python. But even when generating 50'000 random 10 asset portfolios, the very portfolio are not even close to the efficient frontier.

I see that for example the maximum sharpe ratio portfolio has very pronounced allocation (most of the 10 asset get 0 allocation).

I understand the concept of the efficient frontier and are well aware to calculate it in Python. But even when generating 50'000 random 10 asset portfolios, the single portfolios are not even close to the efficient frontier.

I see that, for example, the maximum sharpe ratio portfolio has very pronounced allocation (most of the 10 asset get 0 allocation).

Source Link
Loading