我惊讶地发现概率密度之和不等于1。是否有调整使其等于1
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import PercentFormatter
plt.style.use('seaborn-deep')
#input file is a flat file that contains portfolio holdings and characteristics
input_file = r'\\CP\file.xls'
df = pd.read_excel(input_file,header=6)
#number of lines in Fund is 123
df_Fund=df[(df['Port. Weight']>0)]
#number of lines in Bench is 214
df_Bench=df[(df['Bench. Weight']>0)]
#Delta distribution
x = df_Fund['Delta']
y = df_Bench['Delta']
plt.hist([x,y],bins=10, density=True, range=(0,100), label=['Fund','Bench'])
plt.legend(loc='upper right')
plt.gca().yaxis.set_major_formatter(PercentFormatter(1))
plt.title='Delta Breakdown'
plt.show()
图表:
如果你想让它和为一,那么你就除以总和
例如,如果将某些组件求和,则求和为一个数
X
所以如果你这样做的话,你就可以把每个成分除以你得到的总量
这就是对任何分布进行正态化的方法(如果分布是连续的,那么和就变成了整数)
希望这能有所帮助
从documentation
密度也不受料仓宽度的影响。由于它看起来像一个大约10的binning,我希望您的数据总和为
0.1
,而不是1
解释图表的方法是“对于50到60之间的每x,概率为1.75%”
因此,为了将其“调整”为1,您可以使用
1
的bin大小或者——正如其他答案中提到的那样——将概率标准化
相关问题 更多 >
编程相关推荐