<s> """<STR_LIT>""" <EOL> print ( __doc__ ) <EOL> import datetime <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> try : <EOL> from matplotlib . finance import quotes_historical_yahoo_ochl <EOL> except ImportError : <EOL> from matplotlib . finance import quotes_historical_yahoo as quotes_historical_yahoo_ochl <EOL> from matplotlib . collections import LineCollection <EOL> from sklearn import cluster , covariance , manifold <EOL> d1 = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> d2 = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> symbol_dict = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:F>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:R>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> symbols , names = np . array ( list ( symbol_dict . items ( ) ) ) . T <EOL> quotes = [ quotes_historical_yahoo_ochl ( symbol , d1 , d2 , asobject = True ) <EOL> for symbol in symbols ] <EOL> open = np . array ( [ q . open for q in quotes ] ) . astype ( np . float ) <EOL> close = np . array ( [ q . close for q in quotes ] ) . astype ( np . float ) <EOL> variation = close - open <EOL> edge_model = covariance . GraphLassoCV ( ) <EOL> X = variation . copy ( ) . T <EOL> X /= X . std ( axis = <NUM_LIT:0> ) <EOL> edge_model . fit ( X ) <EOL> _ , labels = cluster . affinity_propagation ( edge_model . covariance_ ) <EOL> n_labels = labels . max ( ) <EOL> for i in range ( n_labels + <NUM_LIT:1> ) : <EOL> print ( '<STR_LIT>' % ( ( i + <NUM_LIT:1> ) , '<STR_LIT:U+002CU+0020>' . join ( names [ labels == i ] ) ) ) <EOL> node_position_model = manifold . LocallyLinearEmbedding ( <EOL> n_components = <NUM_LIT:2> , eigen_solver = '<STR_LIT>' , n_neighbors = <NUM_LIT:6> ) <EOL> embedding = node_position_model . fit_transform ( X . T ) . T <EOL> plt . figure ( <NUM_LIT:1> , facecolor = '<STR_LIT:w>' , figsize = ( <NUM_LIT:10> , <NUM_LIT:8> ) ) <EOL> plt . clf ( ) <EOL> ax = plt . axes ( [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:1.> ] ) <EOL> plt . axis ( '<STR_LIT>' ) <EOL> partial_correlations = edge_model . precision_ . copy ( ) <EOL> d = <NUM_LIT:1> / np . sqrt ( np . diag ( partial_correlations ) ) <EOL> partial_correlations *= d <EOL> partial_correlations *= d [ : , np . newaxis ] <EOL> non_zero = ( np . abs ( np . triu ( partial_correlations , k = <NUM_LIT:1> ) ) > <NUM_LIT> ) <EOL> plt . scatter ( embedding [ <NUM_LIT:0> ] , embedding [ <NUM_LIT:1> ] , s = <NUM_LIT:100> * d ** <NUM_LIT:2> , c = labels , <EOL> cmap = plt . cm . spectral ) <EOL> start_idx , end_idx = np . where ( non_zero ) <EOL> segments = [ [ embedding [ : , start ] , embedding [ : , stop ] ] <EOL> for start , stop in zip ( start_idx , end_idx ) ] <EOL> values = np . abs ( partial_correlations [ non_zero ] ) <EOL> lc = LineCollection ( segments , <EOL> zorder = <NUM_LIT:0> , cmap = plt . cm . hot_r , <EOL> norm = plt . Normalize ( <NUM_LIT:0> , <NUM_LIT> * values . max ( ) ) ) <EOL> lc . set_array ( values ) <EOL> lc . set_linewidths ( <NUM_LIT:15> * values ) <EOL> ax . add_collection ( lc ) <EOL> for index , ( name , label , ( x , y ) ) in enumerate ( <EOL> zip ( names , labels , embedding . T ) ) : <EOL> dx = x - embedding [ <NUM_LIT:0> ] <EOL> dx [ index ] = <NUM_LIT:1> <EOL> dy = y - embedding [ <NUM_LIT:1> ] <EOL> dy [ index ] = <NUM_LIT:1> <EOL> this_dx = dx [ np . argmin ( np . abs ( dy ) ) ] <EOL> this_dy = dy [ np . argmin ( np . abs ( dx ) ) ] <EOL> if this_dx > <NUM_LIT:0> : <EOL> horizontalalignment = '<STR_LIT:left>' <EOL> x = x + <NUM_LIT> <EOL> else : <EOL> horizontalalignment = '<STR_LIT:right>' <EOL> x = x - <NUM_LIT> <EOL> if this_dy > <NUM_LIT:0> : <EOL> verticalalignment = '<STR_LIT>' <EOL> y = y + <NUM_LIT> <EOL> else : <EOL> verticalalignment = '<STR_LIT>' <EOL> y = y - <NUM_LIT> <EOL> plt . text ( x , y , name , size = <NUM_LIT:10> , <EOL> horizontalalignment = horizontalalignment , <EOL> verticalalignment = verticalalignment , <EOL> bbox = dict ( facecolor = '<STR_LIT:w>' , <EOL> edgecolor = plt . cm . spectral ( label / float ( n_labels ) ) , <EOL> alpha = <NUM_LIT> ) ) <EOL> plt . xlim ( embedding [ <NUM_LIT:0> ] . min ( ) - <NUM_LIT> * embedding [ <NUM_LIT:0> ] . ptp ( ) , <EOL> embedding [ <NUM_LIT:0> ] . max ( ) + <NUM_LIT> * embedding [ <NUM_LIT:0> ] . ptp ( ) , ) <EOL> plt . ylim ( embedding [ <NUM_LIT:1> ] . min ( ) - <NUM_LIT> * embedding [ <NUM_LIT:1> ] . ptp ( ) , <EOL> embedding [ <NUM_LIT:1> ] . max ( ) + <NUM_LIT> * embedding [ <NUM_LIT:1> ] . ptp ( ) ) <EOL> plt . show ( ) </s>
