SHARE
TWEET

Untitled

a guest Sep 17th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import plotly
  2. import plotly.graph_objs
  3. import ipywidgets
  4. import pandas
  5. class Funds():
  6.     def nome_fundo(self, nome):
  7.         self.nome_fundo = nome
  8.     def historico(self,a):
  9.         self.historico = a
  10.        
  11. dados = pandas.read_csv('Projeto.csv', delimiter=';')
  12. fundos = list(dados.columns)
  13. datas = dados[fundos[0]].tolist()
  14. fundos[0]='Todos'
  15.  
  16. opcoes = fundos
  17. fuds = []
  18. m = len(opcoes)
  19. minimo = 300000
  20. for i in range(1,m):
  21.     d_i = dados[opcoes[i]].tolist()
  22.     f_i = Funds()
  23.     f_i.historico = d_i
  24.     f_i.nome_fundo = opcoes[i]
  25.     fuds.append(f_i)
  26.     if len(d_i) < minimo:
  27.         minimo = len(d_i)
  28.        
  29. dias=[]
  30. fig=plotly.graph_objs.Figure()
  31. for i in range(minimo):
  32.     dias.append(i-minimo)
  33. layout = plotly.graph_objs.Layout(
  34.     title='Desempenho Fundos',
  35.     yaxis_title='%CDI',
  36.     xaxis_title='D-')
  37. def up(fundos,periodo):
  38.     data = []
  39.     if 'Todos' in fundos:
  40.         n = 0
  41.         while n < m-1:
  42.             y_a = fuds[n].historico
  43.             traco=plotly.graph_objs.Scatter(
  44.                 x=dias[minimo-periodo[1]:minimo-periodo[0]+1],
  45.                 y=y_a[minimo-periodo[1]:minimo-periodo[0]+1],
  46.                 mode='lines',
  47.                 name=opcoes[n+1],
  48.                 line=plotly.graph_objs.scatter.Line(width=0.8),
  49.                 hoverlabel=plotly.graph_objs.scatter.Hoverlabel(bgcolor='blue'))
  50.             data.append(traco)
  51.             n +=1
  52.     else:
  53.         for i in fundos:
  54.             j = opcoes.index(i)-1
  55.             y_a=fuds[j].historico
  56.             traco=plotly.graph_objs.Scatter(
  57.                 x=dias[minimo-periodo[1]:minimo-periodo[0]+1],
  58.                 y=y_a[minimo-periodo[1]:minimo-periodo[0]+1],
  59.                 mode='lines',
  60.                 name=i,
  61.                 line=plotly.graph_objs.scatter.Line(width=0.8),
  62.                 hoverlabel=plotly.graph_objs.scatter.Hoverlabel(bgcolor='blue'))
  63.             data.append(traco)
  64.     traco_ct=plotly.graph_objs.Scatter(
  65.         x=dias[minimo-periodo[1]:minimo-periodo[0]+1],
  66.         y=['100']*(periodo[1]+1-periodo[0]), mode='lines',
  67.         name='Taxa CDI', opacity = 0.6, line=dict(
  68.         color='black',width=0.4))
  69.     data.append(traco_ct)
  70.     fig=plotly.graph_objs.Figure(data=data,layout=layout)
  71.     fig.show()
  72.  
  73. fundos=ipywidgets.SelectMultiple(options=opcoes,
  74.                              value=['Top'],
  75.                              description='Fundos:')
  76. periodo=ipywidgets.IntRangeSlider(value=[1,minimo], min=1,
  77.                           max=minimo,
  78.                            description='PerĂ­odo:',
  79.                          layout=ipywidgets.Layout(width='75%',
  80.                                       height='90%'),
  81.                          continuous_update=False)
  82. periodo.style.handle_color='green'
  83. ipywidgets.interactive(up,fundos=fundos,periodo=periodo)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top