def make_plot(yscale='linear'):
    # configure the tools
    width_zoom={'dimensions':['width']}
    tools = [tool(**width_zoom) for tool in [BoxZoomTool, WheelZoomTool]]

    hover_pos = HoverTool(
            names=['buy','sell'],
            tooltips=[
              ('Position','@pos'),
              ('Date','@date'),
              ('Price','@price')
            ]
    )
    hover_pos.name = 'Postions'


    tools.extend([PanTool(), hover_pos, ResetTool(), CrosshairTool()])

    # prepare plot
    p = Figure(plot_height=600, plot_width=800, title="Moving Average Positions",
            x_axis_type='datetime', y_axis_type=yscale, tools=tools)

    p.line(x='date', y='price', alpha=0.3, color='Black', line_width=2, source=source, legend='Close', name='price')
    p.line(x='date', y='mav_short', color='DarkBlue', line_width=2, source=source, legend='Short MAV')
    p.line(x='date', y='mav_long', color='FireBrick', line_width=2, source=source, legend='Long MAV')
    p.inverted_triangle(x='x', y='y', color='Crimson', size=20, alpha=0.7, source=sell, legend='Sell', name='sell')
    p.triangle(x='x', y='y', color='ForestGreen', size=20, alpha=0.7, source=buy, legend='Buy', name='buy')

    return p
Example #2
0
def plot_crossover_signals(data, signals, ticker=None, notebook=False):
    # create a new plot with a title and axis labels
    p = Figure(title=ticker + ' Moving Crossover Strategy',
               x_axis_label='Date',
               x_axis_type='datetime',
               y_axis_label='Price in $',
               plot_height=500,
               plot_width=950,
               tools=['pan', 'wheel_zoom'],
               toolbar_location='below')

    # configure so that Bokeh chooses what (if any) scroll tool is active
    p.toolbar.active_scroll = "auto"

    # add a line renderer with legend and line thickness
    p.line(data.index,
           data['Close'],
           line_width=2,
           legend='Close',
           line_color='black')
    p.line(signals.index,
           signals['short_mavg'],
           line_width=2,
           legend='Slow MA',
           line_color='orange')
    p.line(signals.index,
           signals['long_mavg'],
           line_width=2,
           legend='Fast MA',
           line_color='blue')

    p.triangle(signals.loc[signals.positions == 1.0].index,
               signals.short_mavg[signals.positions == 1.0],
               size=15,
               fill_color='green',
               legend='Bullish Crossover')
    p.inverted_triangle(signals.loc[signals.positions == -1.0].index,
                        signals.short_mavg[signals.positions == -1.0],
                        size=15,
                        fill_color='red',
                        legend='Bearish Crossover')

    p.legend.location = "top_left"
    p.legend.click_policy = "hide"

    if notebook:
        # show the results
        show(p, notebook_handle=True)
        push_notebook()
    else:
        # output the results
        output_file('%s Moving Crossover Strategy.html' % ticker)
        save(p)
Example #3
0
                    x = [phototime[i] for i in indye],
                    y = [photoAB[i] for i in indye],
                    err = [photoerrs[i] for i in indye],
                    desc = [photoband[i] for i in indye],
                    instr = [photoinstru[i] for i in indye],
                    src = [photosource[i] for i in indye]
                )
            )
            p1.multi_line([err_xs[x] for x in indye], [err_ys[x] for x in indye], color=bandcolorf(band))
            p1.circle('x', 'y', source = source, color=bandcolorf(band), legend=bandname, size=4)

            upplimlegend = bandname if len(indye) == 0 and len(indne) == 0 else ''

            indt = [i for i, j in enumerate(phototype) if j]
            ind = set(indb).intersection(indt)
            p1.inverted_triangle([phototime[x] for x in ind], [photoAB[x] for x in ind],
                color=bandcolorf(band), legend=upplimlegend, size=7)

    if spectraavail and dohtml and args.writehtml:
        spectrumwave = []
        spectrumflux = []
        spectrumerrs = []
        for spectrum in catalog[entry]['spectra']:
            spectrumdata = deepcopy(spectrum['data'])
            spectrumdata = [x for x in spectrumdata if is_number(x[1]) and not isnan(float(x[1]))]
            specrange = range(len(spectrumdata))
            spectrumwave.append([float(spectrumdata[x][0]) for x in specrange])
            spectrumflux.append([float(spectrumdata[x][1]) for x in specrange])
            if 'errorunit' in spectrum:
                spectrumerrs.append([float(spectrumdata[x][2]) for x in specrange])
                spectrumerrs[-1] = [x if is_number(x) and not isnan(float(x)) else 0. for x in spectrumerrs[-1]]
        nspec = len(catalog[entry]['spectra'])
Example #4
0
def plot_bollinger_signals(data, signals, ticker=None, notebook=False):
    # create a new plot with a title and axis labels
    p = Figure(title=ticker + ' Bollinger Bands Strategy',
               x_axis_label='Date',
               x_axis_type='datetime',
               y_axis_label='Price in $',
               plot_height=500,
               plot_width=950,
               tools=['pan', 'wheel_zoom'],
               toolbar_location='below')

    inc = data['Close'] > data['Open']
    dec = data['Open'] > data['Close']
    w = 12 * 60 * 60 * 1000  # half day in ms

    p.segment(data.index, data['High'], data.index, data['Low'], color="black")
    p.vbar(data.index[inc],
           w,
           data['Open'][inc],
           data['Close'][inc],
           fill_color="#D5E1DD",
           line_color="black")
    p.vbar(data.index[dec],
           w,
           data['Open'][dec],
           data['Close'][dec],
           fill_color="#F2583E",
           line_color="black")

    # configure so that Bokeh chooses what (if any) scroll tool is active
    p.toolbar.active_scroll = "auto"

    # add a line renderer with legend and line thickness
    p.line(signals.index,
           signals['mediumband'],
           line_width=2,
           legend='Mediumband',
           line_color='black')
    p.line(signals.index,
           signals['upperband'],
           line_width=2,
           legend='Upperband',
           line_color='orange')
    p.line(signals.index,
           signals['lowerband'],
           line_width=2,
           legend='Lowerband',
           line_color='blue')

    p.triangle(signals.loc[signals.positions == 1.0].index,
               signals.lowerband[signals.positions == 1.0],
               size=15,
               fill_color='green',
               legend='Buy')
    p.inverted_triangle(signals.loc[signals.positions == -1.0].index,
                        signals.upperband[signals.positions == -1.0],
                        size=15,
                        fill_color='red',
                        legend='Sell')

    p.legend.location = "top_left"
    p.legend.click_policy = "hide"

    if notebook:
        # show the results
        show(p, notebook_handle=True)
        push_notebook()
    else:
        # output the results
        output_file('%s Bollinger Bands Strategy.html' % ticker)
        save(p)
Example #5
0
def createPlot(height=600, width=1200):
    """
    Create and return a plot for visualizing transcripts.
    """
    TOOLS = "pan, wheel_zoom, save, reset, tap"
    p = Figure(title="",
               y_range=[],
               webgl=True,
               tools=TOOLS,
               toolbar_location="above",
               plot_height=height,
               plot_width=width)
    # This causes title to overlap plot substantially:
    #p.title.text_font_size = TITLE_FONT_SIZE
    p.xgrid.grid_line_color = None  # get rid of the grid in bokeh
    p.ygrid.grid_line_color = None
    # the block of exons, there's mouse hover effect on that
    quad = p.quad(top="top",
                  bottom="bottom",
                  left="left",
                  right="right",
                  source=blockSource,
                  fill_alpha=0,
                  line_dash="dotted",
                  line_alpha=0.4,
                  line_color='black',
                  hover_fill_color="red",
                  hover_alpha=0.3,
                  hover_line_color="white",
                  nonselection_fill_alpha=0,
                  nonselection_line_alpha=0.4,
                  nonselection_line_color='black')
    # the block of each vertical transcript, each one can be selected
    p.quad(top="top",
           bottom="bottom",
           right="right",
           left="left",
           source=tranSource,
           fill_alpha=0,
           line_alpha=0,
           nonselection_fill_alpha=0,
           nonselection_line_alpha=0)
    # what exons really is
    # Cannot use line_width="height" because it is broken.
    p.multi_line(xs="xs",
                 ys="ys",
                 line_width=opt.height,
                 color="color",
                 line_alpha="line_alpha",
                 source=source)
    # the start/stop codon
    p.inverted_triangle(x="x",
                        y="y",
                        color="color",
                        source=codonSource,
                        size='size',
                        alpha=0.5)
    # mouse hover on the block
    p.add_tools(
        HoverTool(tooltips=[("chromosome", "@chromosome"), ("exon", "@exon"),
                            ("start", "@start"), ("end", "@end")],
                  renderers=[quad]))
    return p