बेस्ट Sharpe ratio के साथ efficient frontier प्लॉट करें
आइए अब efficient frontier को फिर से प्लॉट करें, लेकिन इस बार सर्वश्रेष्ठ Sharpe इंडेक्स वाले पोर्टफोलियो के लिए एक मार्कर जोड़ें. डेटा को विज़ुअलाइज़ करना उसे बेहतर समझने के लिए हमेशा अच्छा होता है.
याद रखें, efficient frontier एक स्कैटर प्लॉट के रूप में बनता है जिसमें x-axis पर पोर्टफोलियो volatility और y-axis पर पोर्टफोलियो returns होते हैं. हम covariances.keys() से अपने डेटा की नवीनतम तिथि लेंगे, हालाँकि तिथि पाने के लिए portfolio_returns आदि में से कोई भी dictionary इस्तेमाल की जा सकती है. फिर हम उसी नवीनतम तिथि के लिए portfolio_volatility और portfolio_returns से volatilities और returns लेंगे. अंत में, max_sharpe_idxs[date] से सर्वश्रेष्ठ Sharpe इंडेक्स वाले पोर्टफोलियो का इंडेक्स लेंगे और सब कुछ plt.scatter() से प्लॉट करेंगे.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Finance के लिए Machine Learning
अभ्यास निर्देश
cur_volatilityको नवीनतमdateके लिए पोर्टफोलियो volatilities पर सेट करें.- x-axis पर volatility और y-axis पर returns रखकर "efficient frontier" प्लॉट बनाइए.
- नवीनतम
dateके लिएmax_sharpe_idxsसे best पोर्टफोलियो का इंडेक्स लीजिए.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Get most recent (current) returns and volatility
date = sorted(covariances.keys())[-1]
cur_returns = portfolio_returns[date]
cur_volatility = ____
# Plot efficient frontier with sharpe as point
plt.scatter(x=____, y=____, alpha=0.1, color='blue')
best_idx = max_sharpe_idxs[____]
# Place an orange "X" on the point with the best Sharpe ratio
plt.scatter(x=cur_volatility[best_idx], y=cur_returns[best_idx], marker='x', color='orange')
plt.xlabel('Volatility')
plt.ylabel('Returns')
plt.show()