test_2.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:crypto 作者: daljeetv 项目源码 文件源码
def random_portfolio(returns):
    def rand_weights(n):
        # Produces n random weights that sum to 1
        k = np.random.rand(n)
        return k / sum(k)

    '''
    Returns the mean and standard deviation of returns for a random portfolio
    '''
    p = np.asmatrix(np.mean(returns, axis=1))
    w = np.asmatrix(rand_weights(returns.shape[0]))
    C = np.asmatrix(np.cov(returns))

    mu = w * p.T
    sigma = np.sqrt(w * C * w.T)

    # This recursion reduces outliers to keep plots pretty
    if sigma > 2:
        return random_portfolio(returns)
    return mu, sigma
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号