我想为10家不同的公司创建多个蒙特卡罗分析。MC函数有3个参数,根据公司的不同而变化,其代码如下所示:
import numpy as np
def monte_carlo(start_price, days, mu, sigma):
price = np.zeros(days)
price[0]= start_price
shock = np.zeros(days)
drift = np.zeros(days)
for x in range (1,days):
shock[x] = np.random.normal(loc = mu *dt, scale = sigma * np.sqrt(dt) )
drift[x] = mu*dt
price[x] = price[x-1] + (price[x-1] * (drift[x] + shock[x]) )
return price
然后,该函数被for循环绘制100次:
for run in range(100):
plt.plot(monte_carlo(start_price,days,mu,sigma))
plt.xlabel('Days')
plt.ylabel('Price')
plt.title('MCA for ')
这对于一组起始价格、mu、sigma的值来说都很好,但是我希望它循环10个不同的集合。
我有这样的东西:
for stock in start_price, sigma, mu:
for run in range(100):
plt.plot(monte_carlo(start_price[stock],days,mu[stock],sigma[stock]))
plt.xlabel('Days')
plt.ylabel('Price')
plt.title('MCA for %' %stock)
但这根本不起作用,我得到了一个“必须只传递布尔值的数据帧”错误。
我希望这是有道理的,我是个十足的傻瓜,所以任何帮助都是值得感谢的