我需要生成多个(比如说,10万个)随机持有的用户谁可以持有多个控股集。对于任何给定的用户,这些持有量的总和必须为1。理论上,在numpy中生成这些随机持有量相当容易:
num_users = 100000
num_holdings = 8
random_holdings = np.random.rand(num_users, num_holdings)
random_holdings /= np.sum(random_holdings, axis=1, keepdims=True)
这给了我们
random_holdings
array([[0.044, 0.169, 0.204, ..., 0.051, 0.116, 0.176],
[0.132, 0.078, 0.23 , ..., 0.102, 0.028, 0.204],
[0.036, 0.182, 0.165, ..., 0.138, 0.065, 0.04 ],
...,
[0.195, 0.028, 0.136, ..., 0.147, 0.113, 0.22 ],
[0.19 , 0.237, 0.061, ..., 0.23 , 0.109, 0.046],
[0.181, 0.111, 0.1 , ..., 0.166, 0.126, 0.199]])
问题在于,这导致了许多类似的持有套数和相对较少的集中持有套数。例如:
len(np.where(random_holdings > 0.5)[0])
结果是24(在整个10万股中只有24股大于0.5)。你知道吗
有谁能推荐一个更好的随机化方法或者一个更明智的整体方法,这样我的同类持股会更少,集中持股会更多?你知道吗
谢谢!你知道吗
你要求“更好的随机化方法”,但“更好”并没有很好的定义。如果你只是想要一些能使持有量发生更大变化的东西,你可以试试
然后像你已经做的那样正常化。你知道吗
^{} 的第一个参数控制分布的形状。使用较大的值来减少持有量的极端变化。你也可以尝试其他重尾分布。你知道吗
相关问题 更多 >
编程相关推荐