कंपनी की सेंसिटिविटी एनालिसिस
अब आप पिछले अभ्यास वाली कंपनी के मुनाफे पर विभिन्न mean_inflation और mean_volume मानों का क्या असर होगा, यह जाँचेंगे। इससे कंपनी को अलग-अलग स्तरों की महँगाई और सेल्स वॉल्यूम के लिए तैयारी करने में मदद मिलेगी, क्योंकि भविष्य में महँगाई या सेल्स वॉल्यूम क्या होंगे, इसका कोई भी कंपनी निश्चित तौर पर अनुमान नहीं लगा सकती।
जिन औसत महँगाई प्रतिशतों को आप एक्सप्लोर करना चाहते हैं वे हैं 0, 1, 2, 5, 10, 15, 20, 50, जबकि औसत वॉल्यूम के रूप में इस्तेमाल करने के लिए सेल्स वैल्यू हैं 100, 200, 500, 800, 1000। याद दिलाने के लिए, यहाँ profit_next_year_mc() फंक्शन की परिभाषा दी गई है, जो आपके लिए पहले से लोड है।
def profit_next_year_mc(mean_inflation, mean_volume, n):
profits = []
for i in range(n):
# Generate inputs by sampling from the multivariate normal distribution
rate_sales_volume = st.multivariate_normal.rvs(mean=[mean_inflation,mean_volume], cov=cov_matrix,size=1000)
# Deterministic calculation of company profit
price = 100 * (100 + rate_sales_volume[:,0])/100
volume = rate_sales_volume[:,1]
loan_and_cost = 50 * volume + 45 * (100 + 3 * rate_sales_volume[:,0]) * (volume/100)
profit = (np.mean(price * volume - loan_and_cost))
profits.append(profit)
return profits
निम्न पैकेज इम्पोर्ट किए जा चुके हैं: pandas as pd, numpy as np, scipy.stats as st, matplotlib.pyplot as plt, और seaborn as sns.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Monte Carlo Simulations
अभ्यास निर्देश
- Monte Carlo सिम्युलेशन को पूरा करें: मुनाफा निकालने के लिए
profit_next_year_mc()चलाएँ ताकि 100 बार परिणाम मिलें, और हर बारinflमानों की सूची औरvolमानों की सूची पर लूप करें। - प्राप्त DataFrame के
Profitकॉलम में सेव सिम्युलेशन परिणामों को विज़ुअलाइज़ करने के लिएdisplotका उपयोग करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
x1 = []
x2 = []
y = []
for infl in [0, 1, 2, 5, 10, 15, 20, 50]:
for vol in [100, 200, 500, 800, 1000]:
# Run profit_next_year_mc so that it samples 100 times for each infl and vol combination
avg_prof = np.mean(____)
x1.append(infl)
x2.append(vol)
y.append(avg_prof)
df_sa = pd.concat([pd.Series(x1), pd.Series(x2), pd.Series(y)], axis=1)
df_sa.columns = ["Inflation", "Volume", "Profit"]
# Create a displot of the simulation results for "Profit"
____
plt.show()