难以将pf_stats
输出转换为4位小数:
def run_simulation(H, P, B, C, mu, sigma, T, L):
x = normal(mu, sigma, (L, T))
pf_all = []
for xs in x:
pf = calc(xs, H, P, B, C)
pf_all.append(pf)
pf_means = np.mean(pf_all, axis=1)
funcs = [np.average, np.median, np.min, np.max]
func_names = ["Average", "Median", "Min", "Max"]
pf_stats= [f(pf_means) for f in funcs]
return json.dumps({
'functions' : func_names,
'pf_stats' : pf_stats
})