Language:EN
Pages: 2
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
onecanthenworkwithmaybe orevenonly principalcompon

Onecanthenworkwithmaybe orevenonly principalcomponent forboththegermandaxindexandallstocksthatmakeuptheindex toderiveprincipalcomponents machinelearninglibrary importnumpyasnp importpandasaspd importpandas fromsklearn stocksthefollowinglistobjectcontainsthe symbolsforthestockscontainedinthegerman daxindex symbols toretrievestockdatawithpandas time data forsyminsymbols data cputimes

���������plt.grid(True)
���������plt.axhline(0,�color=‘k’,�ls=‘—’,�lw=2.0)���������plt.axvline(0,�color=‘k’,�ls=‘—’,�lw=2.0)���������plt.xlabel(‘expected�volatility’)
���������plt.ylabel(‘expected�return’)
���������plt.colorbar(label=‘Sharpe�ratio’)

Out[76]:�array([�0.684,��0.059,��0.257,�-0.���,��0.���])

Principal�Component�Analysis

The�example�of�this�section�illustrates�the�use�of�PCA�in�such�a�context.�We�retrieve�data for�both�the�German�DAX�index�and�all�stocks�that�make�up�the�index.�We�then�use�PCA to�derive�principal�components,�which�we�use�to�construct�what�we�call�a�pca_index.

First,�some�imports.�In�particular,�we�use�the�KernelPCA�function�of�the�scikit-learn machine�learning�library�(cf.�the�):

We�work�only�with�the�closing�values�of�each�data�set�that�we�retrieve�(for�details�on�how to�retrieve�stock�data�with�pandas,�see�Chapter�6):

In�[3]:�%%time
��������data�=�pd.DataFrame()
��������for�sym�in�symbols:
������������data[sym]�=�web.DataReader(sym,�data_source=‘yahoo’)[‘Close’]��������data�=�data.dropna()

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Elliott Williams

PageId: ELI21E13F2