Пример #1
0
 def __init__(self, quote_id, start_y, start_m, start_d, stop_y, stop_m, stop_d, step = "d", row_n = 10):
     #dati per plot
     self.chrono_linegen = self.file_to_datagen(query_yahoo_finance(quote_id, start_y, start_m, start_d, stop_y, stop_m, stop_d, step))
     #plot
     self.plot = DataTable(
         source = ColumnDataSource(dict(
                 dates = ["-" for i in range(row_n)], 
                 close = [0 for i in range(row_n)], 
                 delta = [0 for i in range(row_n)])), #se inizializzazione in tipo non numerico non riesce a calcolare il primo delta
         columns = [TableColumn(field="dates", title="Date", formatter = StringFormatter(text_align = "center")), 
                    TableColumn(field="close", title="Close", formatter=NumberFormatter(format = "0.000")),
                    TableColumn(field="delta", title="Delta Close", formatter=NumberFormatter(format = "0.000"))],
         width=400,
         height=280,
         row_headers = False
     )
 def __init__(self, quote_id, start_y, start_m, start_d, stop_y, stop_m, stop_d, step = "d", candle_visualized_n = 15, quadwidth_percentual = 0.5):
     #inizializza dati per plot
     if step == "m": self.tmscale = 1000*60*60*24*30 #30 giorni in ms
     elif step == "w": self.tmscale = 1000*60*60*24*7 #30 giorni in ms
     else: self.tmscale = 1000*60*60*24 #1 giorno in ms
     self.quadwidth = self.tmscale * quadwidth_percentual
     self.chrono_linegen = self.file_to_datagen(query_yahoo_finance(quote_id, start_y, start_m, start_d, stop_y, stop_m, stop_d, step))
     #inizializza plot
     self.plot = figure(plot_width = 1000, plot_height = 500)
     self.plot.xaxis[0].formatter = DatetimeTickFormatter(
         formats = dict(
             hours = ["d %b %Y"], #numero giorno, sigla mese, ora come intero da 00 a 23
             days = ["%d %b %Y"], #numero giorno, sigla mese, numero anno
             months = ["%d %b %Y"], #numero giorno, sigla mese, numero anno
             years = ["%d %b %Y"]) #numero giorno, sigla mese, numero anno
         )
     self.plot.quad(top = [], bottom = [], left = [], right = [], fill_color = [], name = "quads")
     self.plot.segment(x0 = [], x1 = [], y0 = [], y1 = [], name = "segments")
     self.ds_quads = self.plot.select({"name":"quads"})[0].data_source
     self.ds_segments = self.plot.select({"name":"segments"})[0].data_source