Python ipywidgets.IntSlider() Examples

The following are 30 code examples of ipywidgets.IntSlider(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ipywidgets , or try the search function .
Example #1
Source File: test_interaction.py    From pySINDy with MIT License 7 votes vote down vote up
def test_single_value_int():
    for a in (1, 5, -3, 0):
        if not a:
            expected_min = 0
            expected_max = 1
        elif a > 0:
            expected_min = -a
            expected_max = 3*a
        else:
            expected_min = 3*a
            expected_max = -a
        c = interactive(f, a=a)
        nt.assert_equal(len(c.children), 2)
        w = c.children[0]
        check_widget(w,
            cls=widgets.IntSlider,
            description='a',
            value=a,
            min=expected_min,
            max=expected_max,
            step=1,
            readout=True,
        ) 
Example #2
Source File: ABuWGBuyFactor.py    From abu with GNU General Public License v3.0 6 votes vote down vote up
def _init_widget(self):
        """构建AbuFactorBuyBreak策略参数界面"""

        self.description = widgets.Textarea(
            value=u'海龟向上趋势突破买入策略:\n'
                  u'趋势突破定义为当天收盘价格超过N天内的最高价,超过最高价格作为买入信号买入股票持有',
            description=u'海龟买入',
            disabled=False,
            layout=self.description_layout
        )
        self.xd_label = widgets.Label(u'突破周期参数:比如21,30,42天....突破', layout=self.label_layout)
        self.xd = widgets.IntSlider(
            value=21,
            min=3,
            max=120,
            step=1,
            description=u'周期',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        self.xd_box = widgets.VBox([self.xd_label, self.xd])
        self.widget = widgets.VBox([self.description, self.xd_box, self.add],  # border='solid 1px',
                                   layout=self.widget_layout) 
Example #3
Source File: visualization_ply.py    From minian with GNU General Public License v3.0 6 votes vote down vote up
def _widgets(self):
        dfrange = self.varr_hv.range('frame')
        w_frame = iwgt.IntSlider(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            continuous_update=False,
            description="Frame:")
        w_paly = iwgt.Play(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            interval=1000 / self.framerate)
        iwgt.jslink((w_paly, 'value'), (w_frame, 'value'))
        iwgt.interactive(self.stream.event, f=w_frame)
        return iwgt.HBox([w_paly, w_frame]) 
Example #4
Source File: visualization_ply.py    From minian with GNU General Public License v3.0 6 votes vote down vote up
def _widgets(self):
        dfrange = self.ds.range('frame')
        w_frame = iwgt.IntSlider(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            continuous_update=False,
            description="Frame:")
        w_paly = iwgt.Play(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            interval=1000 / self.framerate)
        iwgt.jslink((w_paly, 'value'), (w_frame, 'value'))
        iwgt.interactive(self.stream.event, f=w_frame)
        return iwgt.HBox([w_paly, w_frame]) 
Example #5
Source File: visualization.py    From minian with GNU General Public License v3.0 6 votes vote down vote up
def _widgets(self):
        dfrange = self.varr.range('frame')
        w_frame = iwgt.IntSlider(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            continuous_update=False,
            description="Frame:")
        w_paly = iwgt.Play(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            interval=1000 / self.framerate)
        iwgt.jslink((w_paly, 'value'), (w_frame, 'value'))
        iwgt.interactive(self.stream.event, f=w_frame)
        return iwgt.HBox([w_paly, w_frame]) 
Example #6
Source File: test_interaction.py    From pySINDy with MIT License 6 votes vote down vote up
def test_defaults():
    @annotate(n=10)
    def f(n, f=4.5, g=1):
        pass

    c = interactive(f)
    check_widgets(c,
        n=dict(
            cls=widgets.IntSlider,
            value=10,
        ),
        f=dict(
            cls=widgets.FloatSlider,
            value=4.5,
        ),
        g=dict(
            cls=widgets.IntSlider,
            value=1,
        ),
    ) 
Example #7
Source File: ABuWGPSBase.py    From abu with GNU General Public License v3.0 6 votes vote down vote up
def _pick_stock_base_ui(self):
        """选股策略中通用ui: xd, reversed初始构建"""
        xd_tip = widgets.Label(u'设置选股策略生效周期,默认252天',
                               layout=widgets.Layout(width='300px', align_items='stretch'))
        self.xd = widgets.IntSlider(
            value=252,
            min=1,
            max=252,
            step=1,
            description=u'周期',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        self.xd_box = widgets.VBox([xd_tip, self.xd])

        reversed_tip = widgets.Label(u'反转选股结果,默认不反转',
                                     layout=widgets.Layout(width='300px', align_items='stretch'))
        self.reversed = widgets.Checkbox(
            value=False,
            description=u'反转结果',
            disabled=False,
        )
        self.reversed_box = widgets.VBox([reversed_tip, self.reversed]) 
Example #8
Source File: jupyter.py    From GraphvizAnim with GNU General Public License v3.0 5 votes vote down vote up
def interactive( animation, size = 320 ):
	basedir = mkdtemp()
	basename = join( basedir, 'graph' )
	steps = [ Image( path ) for path in render( animation.graphs(), basename, 'png', size ) ]
	rmtree( basedir )
	slider = widgets.IntSlider( min = 0, max = len( steps ) - 1, step = 1, value = 0 )
	return widgets.interactive( lambda n: display(steps[ n ]), n = slider ) 
Example #9
Source File: ABuWGTLTool.py    From abu with GNU General Public License v3.0 5 votes vote down vote up
def init_pair_speed_ui(self):
        """趋势敏感速度分析ui"""
        with self._init_tip_label_with_step_x(
                self._pair_speed_analyse, u'趋势敏感速度分析', with_step_x=False) as (widget_list, _):
            self.pair_speed_mode = widgets.RadioButtons(
                options={u'对比收盘敏感速度': 'close', u'对比涨跌敏感速度': 'p_change',
                         u'对比最高敏感速度': 'high', u'对比最低敏感速度': 'low'},
                value='close',
                description=u'对比模式:',
                disabled=False
            )
            widget_list.append(self.pair_speed_mode)
            resample_tip_label = widgets.Label(u'趋势敏感速度计算重采样周期', layout=self.label_layout)
            self.pair_resample = widgets.IntSlider(
                value=5,
                min=3,
                max=10,
                step=1,
                description=u'重采样',
                disabled=False,
                orientation='horizontal',
                readout=True,
                readout_format='d'
            )
            resample_box = widgets.VBox([resample_tip_label, self.pair_resample])
            widget_list.append(resample_box)
        return widgets.VBox(widget_list,
                            # border='solid 1px',
                            layout=self.tool_layout) 
Example #10
Source File: visualization.py    From minian with GNU General Public License v3.0 5 votes vote down vote up
def _widgets(self):
        dfrange = [0, self._f]
        w_frame = iwgt.IntSlider(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            continuous_update=False,
            description="Frame:",
            layout=iwgt.Layout(width='50%'))
        w_play = iwgt.Play(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            interval=1000 / self.framerate)
        iwgt.jslink((w_play, 'value'), (w_frame, 'value'))
        iwgt.interactive(self.strm_f.event, x=w_frame)
        uidrange = [0, self._u]
        w_select = iwgt.IntRangeSlider(
            value=self._cur_sel,
            min=uidrange[0],
            max=uidrange[1],
            continuous_update=False,
            description="Unit ID:",
            layout=iwgt.Layout(width='50%'))
        w_select.observe(self._set_sel, names='value')
        w_update = iwgt.Button(description="Update")
        w_update.on_click(self._update_plot)
        w_update_mov = iwgt.Checkbox(
            value=self._update_mov, description="Update Movies")
        w_update_mov.observe(self._set_update, names='value')
        w_overlay = iwgt.Checkbox(value=self._overlay, description="Overlay")
        w_overlay.observe(self._set_overlay, names='value')
        return iwgt.VBox([
            iwgt.HBox([w_frame, w_play, w_update_mov]),
            iwgt.HBox([w_select, w_update, w_overlay])
        ]) 
Example #11
Source File: trajectory_viewer.py    From notebook-molecular-visualization with Apache License 2.0 5 votes vote down vote up
def make_controls(self):
        self.playbutton = ipy.Play(value=0,
                                   min=0,
                                   max=self.traj.num_frames-1)

        self.slider = ipy.IntSlider(value_selects='framenum', value=0,
                                    description='Frame:', min=0, max=len(self.traj)-1,
                                    readout=False)
        self.readout = ipy.HTML(value='/%d' % (self.traj.num_frames - 1))
        self.annotation = ipy.HTML()

        traitlets.link((self.playbutton, 'value'), (self.slider, 'value'))
        traitlets.link((self.slider, 'value'), (self, 'current_frame'))
        return VBox((self.annotation,
                     HBox((self.playbutton, self.slider, self.readout)))) 
Example #12
Source File: initialize.py    From qkit with GNU General Public License v2.0 5 votes vote down vote up
def crop_recording_window(self):
        self._sample.mspec.spec_stop()
        self._sample.mspec.set_averages(1e4)
        self._sample.mspec.set_window(0,512)
        self._sample.mspec.set_segments(1)
        msp = self._sample.mspec.acquire()
        
        def pltfunc(start,end,done):
            if done:
                self._sample.acqu_window = [start,end]
                self._sample.mspec.set_window(start,end)
                self._sw.disabled = True
                self._ew.disabled = True
                self._dw.disabled = True
                self._dw.description = "acqu_window set to [{:d}:{:d}]".format(start,end)
            else:
                plt.figure(figsize=(15,5))
                plt.plot(msp)
                plt.axvspan(0,start,color='k',alpha=.2)
                plt.axvspan(end,len(msp),color='k',alpha=.2)
                plt.xlim(0,len(msp))
                plt.show()
        self._sw =  widgets.IntSlider(min=0,max=len(msp),step=1,value=self._sample.acqu_window[0],continuous_update=True)
        self._ew = widgets.IntSlider(min=0,max=len(msp),step=1,value=self._sample.acqu_window[1],continuous_update=True)
        self._dw = widgets.Checkbox(value=False,description="Done!",indent=True)
        self._wgt = widgets.interact(pltfunc,start=self._sw,end=self._ew,done=self._dw)
        self._sample.mspec.set_window(*self._sample.acqu_window) 
Example #13
Source File: test_widget_box.py    From pySINDy with MIT License 5 votes vote down vote up
def test_construction_with_children(self):
        html = widgets.HTML('some html')
        slider = widgets.IntSlider()
        box = widgets.Box([html, slider])
        children_state = box.get_state()['children']
        assert children_state == [
            widgets.widget._widget_to_json(html, None),
            widgets.widget._widget_to_json(slider, None),
        ] 
Example #14
Source File: test_interaction.py    From pySINDy with MIT License 5 votes vote down vote up
def test_state_schema():
    from ipywidgets.widgets import IntSlider, Widget
    import json
    import jsonschema
    s = IntSlider()
    state = Widget.get_manager_state(drop_defaults=True)
    with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../', 'state.schema.json')) as f:
        schema = json.load(f)
    jsonschema.validate(state, schema) 
Example #15
Source File: test_interaction.py    From pySINDy with MIT License 5 votes vote down vote up
def test_call_interact_kwargs():
    def foo(a='default'):
        pass
    with patch.object(interaction, 'display', record_display):
        ifoo = interact(foo, a=10)
    nt.assert_equal(len(displayed), 1)
    w = displayed[0].children[0]
    check_widget(w,
        cls=widgets.IntSlider,
        value=10,
    ) 
Example #16
Source File: test_interaction.py    From pySINDy with MIT License 5 votes vote down vote up
def test_decorator_kwarg():
    with patch.object(interaction, 'display', record_display):
        @interact(a=5)
        def foo(a):
            pass
    nt.assert_equal(len(displayed), 1)
    w = displayed[0].children[0]
    check_widget(w,
        cls=widgets.IntSlider,
        value=5,
    ) 
Example #17
Source File: test_interaction.py    From pySINDy with MIT License 5 votes vote down vote up
def test_annotations():
    @annotate(n=10, f=widgets.FloatText())
    def f(n, f):
        pass

    c = interactive(f)
    check_widgets(c,
        n=dict(
            cls=widgets.IntSlider,
            value=10,
        ),
        f=dict(
            cls=widgets.FloatText,
        ),
    ) 
Example #18
Source File: test_interaction.py    From pySINDy with MIT License 5 votes vote down vote up
def test_default_values():
    @annotate(n=10, f=(0, 10.), g=5, h=OrderedDict([('a',1), ('b',2)]), j=['hi', 'there'])
    def f(n, f=4.5, g=1, h=2, j='there'):
        pass

    c = interactive(f)
    check_widgets(c,
        n=dict(
            cls=widgets.IntSlider,
            value=10,
        ),
        f=dict(
            cls=widgets.FloatSlider,
            value=4.5,
        ),
        g=dict(
            cls=widgets.IntSlider,
            value=5,
        ),
        h=dict(
            cls=widgets.Dropdown,
            options=OrderedDict([('a',1), ('b',2)]),
            value=2
        ),
        j=dict(
            cls=widgets.Dropdown,
            options=('hi', 'there'),
            value='there'
        ),
    ) 
Example #19
Source File: explorer.py    From scqubits with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def interact(self):
        """Drives the interactive display of the plot explorer panels"""
        param_min = self.param_vals[0]
        param_max = self.param_vals[-1]
        param_step = self.param_vals[1] - self.param_vals[0]

        qbt_indices = [index for (index, subsystem) in self.sweep.qbt_subsys_list]
        osc_indices = [index for (index, subsystem) in self.sweep.osc_subsys_list]

        param_slider = ipywidgets.FloatSlider(min=param_min, max=param_max, step=param_step,
                                              description=self.param_name, continuous_update=False)
        photon_slider = ipywidgets.IntSlider(value=1, min=1, max=4, description='photon number')
        initial_slider = ipywidgets.IntSlider(value=0, min=0, max=self.evals_count, description='initial state index')
        final_slider = ipywidgets.IntSlider(value=1, min=1, max=self.evals_count, description='final state index')

        qbt_dropdown = ipywidgets.Dropdown(options=qbt_indices, description='qubit subsys')
        osc_dropdown = ipywidgets.Dropdown(options=osc_indices, description='oscillator subsys')

        def update_min_final_index(*args):
            final_slider.min = initial_slider.value + 1

        initial_slider.observe(update_min_final_index, 'value')

        out = ipywidgets.interactive_output(self.plot_explorer_panels,
                                            {'param_val': param_slider,
                                             'photonnumber': photon_slider,
                                             'initial_index': initial_slider,
                                             'final_index': final_slider,
                                             'qbt_index': qbt_dropdown,
                                             'osc_index': osc_dropdown
                                             })

        left_box = ipywidgets.VBox([param_slider])
        mid_box = ipywidgets.VBox([initial_slider, final_slider, photon_slider])
        right_box = ipywidgets.VBox([qbt_dropdown, osc_dropdown])

        user_interface = ipywidgets.HBox([left_box, mid_box, right_box])
        display(user_interface, out) 
Example #20
Source File: visualize.py    From deep_pipe with MIT License 5 votes vote down vote up
def _slice_base(data: [np.ndarray], axis: int = -1, scale: int = 5, max_columns: int = None, colorbar: bool = False,
                show_axes: bool = False, cmap: Union[Colormap, str] = 'gray', vlim: AxesParams = None,
                callback: Callable = None, sliders: dict = None):
    from ipywidgets import interact, IntSlider
    check_shape_along_axis(*data, axis=axis)
    vlim = np.broadcast_to(vlim, [len(data), 2]).tolist()
    rows, columns = _get_rows_cols(max_columns, data)
    sliders = sliders or {}
    if 'idx' in sliders:
        raise ValueError(f'Overriding "idx" is not allowed.')

    def update(idx, **kwargs):
        fig, axes = plt.subplots(rows, columns, figsize=(scale * columns, scale * rows))
        for ax, x, (vmin, vmax) in zip(np.array(axes).flatten(), data, vlim):
            im = ax.imshow(x.take(idx, axis=axis), cmap=cmap, vmin=vmin, vmax=vmax)
            if colorbar:
                fig.colorbar(im, ax=ax, orientation='horizontal')
            if not show_axes:
                ax.set_axis_off()

        if callback is not None:
            callback(axes, idx=idx, **kwargs)

        plt.tight_layout()
        plt.show()

    interact(update, idx=IntSlider(min=0, max=data[0].shape[axis] - 1, continuous_update=False), **sliders) 
Example #21
Source File: dataset.py    From avocado with MIT License 5 votes vote down vote up
def plot_interactive(self):
        """Make an interactive plot of the light curves in the dataset.

        This requires the ipywidgets package to be set up, and has only been
        tested in jupyter-lab.
        """
        from ipywidgets import interact, IntSlider, Dropdown

        object_classes = {"": None}
        for object_class in np.unique(self.metadata["class"]):
            object_classes[object_class] = object_class

        idx_widget = IntSlider(min=0, max=1)
        class_widget = Dropdown(options=object_classes, index=0)

        def update_idx_range(*args):
            if class_widget.value is None:
                idx_widget.max = len(self.metadata) - 1
            else:
                idx_widget.max = (
                    np.sum(self.metadata["class"] == class_widget.value) - 1
                )

        class_widget.observe(update_idx_range, "value")

        update_idx_range()

        interact(
            self.plot_light_curve,
            index=idx_widget,
            object_class=class_widget,
            show_gp=True,
            uncertainties=True,
            verbose=False,
            subtract_background=True,
        ) 
Example #22
Source File: fywidgets.py    From fygimbal with MIT License 5 votes vote down vote up
def __init__(self, gimbal):
        self.gimbal = gimbal
        self.controlPacket = None

        xw = ipywidgets.IntSlider(value=0, min=-0x8000, max=0x7fff, step=1, layout=dict(width='100%'))
        yw = ipywidgets.IntSlider(value=0, min=-0x8000, max=0x7fff, step=1, layout=dict(width='100%'))
        zw = ipywidgets.IntSlider(value=0, min=-0x8000, max=0x7fff, step=1, layout=dict(width='100%'))
        mw = ipywidgets.IntSlider(value=1, min=0, max=255, step=1, layout=dict(width='100%'))
        ipywidgets.interact(self.setFn, x=xw, y=yw, z=zw, m=mw)

        ThreadToggle(self.loopFn, description='Controller thread')

        self.rate = ipywidgets.IntSlider(description='Update rate',
            value=25, min=1, max=400, step=1, layout=dict(width='100%'))
        display(self.rate) 
Example #23
Source File: fywidgets.py    From fygimbal with MIT License 5 votes vote down vote up
def __init__(self, gimbal, number, axes=range(3), min=-0x8000, max=0x7fff, step=1):
        self.gimbal = gimbal
        self.number = number
        self.axes = axes
        self.widgets = [None] * 3

        ThreadToggle(self._update, description='Refresh param %02x' % number)

        for t in self.axes:
            v = self.gimbal.getParam(number=number, target=t)
            self.widgets[t] = ipywidgets.IntSlider(description='Param %02x t=%d' % (self.number, t),
                value=v, min=min, max=max, step=step,layout=dict(width='100%'))
            ipywidgets.interact(self._set, x=self.widgets[t], target=ipywidgets.fixed(t)) 
Example #24
Source File: ABuWGBuyFactor.py    From abu with GNU General Public License v3.0 4 votes vote down vote up
def _init_widget(self):
        """构建AbuDownUpTrend策略参数界面"""

        self.description = widgets.Textarea(
            value=u'整个择时周期分成两部分,长的为长线择时,短的为短线择时:\n'
                  u'1. 寻找长线下跌的股票,比如一个季度(4个月)整体趋势为下跌趋势\n'
                  u'2. 短线走势上涨的股票,比如一个月整体趋势为上涨趋势\n,'
                  u'3. 最后使用海龟突破的N日突破策略作为策略最终买入信号',
            description=u'长跌短涨',
            disabled=False,
            layout=self.description_layout
        )

        xd_label = widgets.Label(u'短线周期:比如20,30,40天,短线以及突破参数',
                                 layout=self.label_layout)
        self.xd = widgets.IntSlider(
            value=20,
            min=5,
            max=120,
            step=5,
            description=u'xd',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        xd_box = widgets.VBox([xd_label, self.xd])

        past_factor_label = widgets.Label(u'长线乘数:短线基础 x 长线乘数 = 长线周期',
                                          layout=self.label_layout)
        self.past_factor = widgets.IntSlider(
            value=4,
            min=1,
            max=10,
            step=1,
            description=u'长线乘数',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        past_factor_box = widgets.VBox([past_factor_label, self.past_factor])

        down_deg_threshold_label = widgets.Label(u'拟合趋势角度阀值:如-2,-3,-4',
                                                 layout=self.label_layout)
        self.down_deg_threshold = widgets.IntSlider(
            value=-3,
            min=-10,
            max=0,
            step=1,
            description=u'角度阀值',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        down_deg_threshold_box = widgets.VBox([down_deg_threshold_label, self.down_deg_threshold])

        self.widget = widgets.VBox([self.description, xd_box, past_factor_box, down_deg_threshold_box, self.add],
                                   layout=self.widget_layout) 
Example #25
Source File: innotaterwidget.py    From jupyter-innotater with MIT License 4 votes vote down vote up
def __init__(self, inputs, targets, indexes=None, keyboard_shortcuts=True, save_hook=None):

        self.path = ''

        self.dirty_uindexes = set()

        self.save_hook = save_hook

        self.datamanager = DataManager(inputs, targets, indexes)

        slider = IntSlider(min=0, max=0)

        self.slider = slider

        self.prevbtn = Button(description='< Previous')
        self.nextbtn = Button(description='Next >')

        self.input_widgets = [dw.get_widget() for dw in self.datamanager.get_inputs()]
        self.target_widgets = [dw.get_widget() for dw in self.datamanager.get_targets()]

        self.add_class('innotater-base')

        cbar_widgets = [self.prevbtn, slider, self.nextbtn]
        if self.save_hook:
            self.savebtn = Button(description='Save', disabled=True)
            cbar_widgets.append(self.savebtn)

        controlbar_widget = HBox(cbar_widgets)
        controlbar_widget.add_class('innotater-controlbar')

        super().__init__([HBox([VBox(self.input_widgets), VBox(self.target_widgets)]),
                          controlbar_widget])

        widgets.jslink((slider, 'value'), (self, 'index'))

        self._observe_targets(self.datamanager.get_targets())

        for dw in list(self.datamanager.get_all()):
            dw.post_widget_create(self.datamanager)

        self.prevbtn.on_click(lambda c: self.move_slider(-1))
        self.nextbtn.on_click(lambda c: self.move_slider(1))

        if self.save_hook:
            self.savebtn.on_click(lambda c: self.save_hook_fire())

        self.slider.max = self.datamanager.get_data_len()-1

        self.index = 0
        self.keyboard_shortcuts = keyboard_shortcuts

        self.on_msg(self.handle_message)

        self.suspend_observed_changes = False
        self.update_ui() 
Example #26
Source File: test_all.py    From ipysheet with MIT License 4 votes vote down vote up
def test_calculation():
    ipysheet.sheet()
    a = ipysheet.cell(0, 0, value=1)
    b = ipysheet.cell(0, 0, value=2)
    c = ipysheet.cell(0, 0, value=0)

    @ipysheet.calculation(inputs=[a, (b, 'value')], output=c)
    def add(a, b):  # pylint: disable=unused-variable
        return a + b

    assert c.value == 3
    a.value = 10
    assert c.value == 10 + 2
    b.value = 20
    assert c.value == 10 + 20

    a.value = 1
    b.value = 2
    assert c.row_start == 0

    @ipysheet.calculation(inputs=[a, b], output=(c, 'type'))
    def add2(a, b):  # pylint: disable=unused-variable
        return 'abcdefg'[a + b]

    assert c.type == 'd'
    b.value = 1
    assert c.type == 'c'

    ipysheet.sheet()
    a = ipysheet.cell(0, 0, value=1)
    b = ipysheet.cell(0, 0, value=widgets.IntSlider(value=2))
    c = widgets.IntSlider(max=0)
    d = ipysheet.cell(0, 0, value=1)

    @ipysheet.calculation(inputs=[a, (b, 'value'), (c, 'max')], output=d)
    def add3(a, b, c):  # pylint: disable=unused-variable
        return a + b + c

    assert d.value == 3
    a.value = 10
    assert d.value == 10+2
    b.value.value = 20
    assert d.value == 10+20
    c.max = 30
    assert d.value == 10+20+30

    b.value = widgets.IntSlider(value=2)
    assert d.value == 10+2+30
    b.value = 20
    assert d.value == 10+20+30

    a.value = widgets.IntSlider(value=100)
    assert d.value == 100+20+30
    a.value.value = 10
    assert d.value == 10+20+30 
Example #27
Source File: ABuWGBuyFactor.py    From abu with GNU General Public License v3.0 4 votes vote down vote up
def _init_widget(self):
        """构建AbuFactorBuyWD策略参数界面"""

        self.description = widgets.Textarea(
            value=u'日胜率均值回复策略:\n'
                  u'1. 默认以40天为周期(8周)结合涨跌阀值计算周几适合买入\n'
                  u'2. 回测运行中每一月重新计算一次上述的周几适合买入\n'
                  u'3. 在策略日任务中买入信号为:昨天下跌,今天开盘也下跌,且明天是计算出来的上涨概率大的\'周几\'',
            description=u'周涨胜率',
            disabled=False,
            layout=self.description_layout
        )

        self.buy_dw_label = widgets.Label(u'代表周期胜率阀值,默认0.55即55%的胜率',
                                          layout=self.label_layout)
        self.buy_dw = widgets.FloatSlider(
            value=0.55,
            min=0.50,
            max=0.99,
            step=0.01,
            description=u'胜率',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='.2f',
        )
        self.buy_dw_box = widgets.VBox([self.buy_dw_label, self.buy_dw])

        self.buy_dwm_label = widgets.Label(u'代表涨幅比例阀值系数,默认0.618',
                                           layout=self.label_layout)
        self.buy_dwm = widgets.FloatSlider(
            value=0.618,
            min=0.50,
            max=1.0,
            step=0.01,
            description=u'系数',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='.3f'
        )
        self.buy_dwm_box = widgets.VBox([self.buy_dwm_label, self.buy_dwm])

        self.dw_period_label = widgets.Label(u'代表分所使用的交易周期,默认40天周期(8周)',
                                             layout=self.label_layout)
        self.dw_period = widgets.IntSlider(
            value=40,
            min=20,
            max=120,
            step=1,
            description=u'周期',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        self.dw_period_box = widgets.VBox([self.dw_period_label, self.dw_period])
        self.widget = widgets.VBox([self.description, self.buy_dw_box,
                                    self.buy_dwm_box, self.dw_period_box, self.add],  # border='solid 1px',
                                   layout=self.widget_layout) 
Example #28
Source File: ABuWGBuyFactor.py    From abu with GNU General Public License v3.0 4 votes vote down vote up
def _init_widget(self):
        """构建AbuSDBreak策略参数界面"""

        self.description = widgets.Textarea(
            value=u'参照大盘走势向上趋势突破买入策略:\n'
                  u'在海龟突破基础上,参照大盘走势,进行降低交易频率,提高系统的稳定性处理,当大盘走势震荡时封锁交易,'
                  u'当大盘走势平稳时再次打开交易,每一个月计算一次大盘走势是否平稳',
            description=u'平稳突破',
            disabled=False,
            layout=self.description_layout
        )
        self.poly_label = widgets.Label(u'大盘走势拟合次数阀值,poly大于阀值=震荡',
                                        layout=self.label_layout)
        self.poly = widgets.IntSlider(
            value=2,
            min=1,
            max=5,
            step=1,
            description=u'拟合',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        self.poly_box = widgets.VBox([self.poly_label, self.poly])
        self.xd_label = widgets.Label(u'突破周期参数:比如21,30,42天....突破',
                                      layout=self.label_layout)
        self.xd = widgets.IntSlider(
            value=21,
            min=3,
            max=120,
            step=1,
            description=u'周期',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        self.xd_box = widgets.VBox([self.xd_label, self.xd])
        self.widget = widgets.VBox([self.description, self.poly_box,
                                    self.xd_box, self.add],  # border='solid 1px',
                                   layout=self.widget_layout) 
Example #29
Source File: ABuWGSellFactor.py    From abu with GNU General Public License v3.0 4 votes vote down vote up
def _init_widget(self):
        """构建AbuDoubleMaSell策略参数界面"""

        self.description = widgets.Textarea(
            value=u'双均线卖出策略:\n'
                  u'双均线策略是量化策略中经典的策略之一,其属于趋势跟踪策略: \n'
                  u'1. 预设两条均线:如一个ma=5,一个ma=60, 5的均线被称作快线,60的均线被称作慢线\n'
                  u'2. 择时卖出策略中当快线下穿慢线(ma5下穿ma60)称为形成死叉卖点信号,卖出股票\n',
            description=u'双均线卖',
            disabled=False,
            layout=self.description_layout
        )

        self.slow_label = widgets.Label(u'默认慢线ma=60:当快线下穿慢线称为形成死叉', layout=self.label_layout)
        self.slow_int = widgets.IntSlider(
            value=60,
            min=10,
            max=120,
            step=1,
            description=u'慢线',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        self.slow_box = widgets.VBox([self.slow_label, self.slow_int])

        self.fast_label = widgets.Label(u'默认快线ma=5:当快线下穿慢线称为形成死叉', layout=self.label_layout)
        self.fast_int = widgets.IntSlider(
            value=5,
            min=1,
            max=90,
            step=1,
            description=u'快线',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        self.fast_box = widgets.VBox([self.fast_label, self.fast_int])
        self.widget = widgets.VBox([self.description, self.slow_box, self.fast_box, self.add_box],
                                   # border='solid 1px',
                                   layout=self.widget_layout) 
Example #30
Source File: ABuWGCrossVal.py    From abu with GNU General Public License v3.0 4 votes vote down vote up
def __init__(self):
        """构建回测需要的各个组件形成tab"""

        tip_label1 = widgets.Label(u'策略相关性交叉验证暂不支持实时网络数据模式', layout=widgets.Layout(width='300px'))
        tip_label2 = widgets.Label(u'需先用\'数据下载界面操作\'进行下载', layout=widgets.Layout(width='300px'))

        self.bf = BuyFactorWGManager()
        self.sf = SellFactorWGManager(show_add_buy=True)

        sub_widget_tab = widgets.Tab()
        sub_widget_tab.children = [self.bf.widget, self.sf.widget]
        for ind, name in enumerate([u'买策', u'卖策']):
            sub_widget_tab.set_title(ind, name)

        self.begin_cross_val = widgets.Button(description=u'开始交叉相关性验证策略有效性',
                                              layout=widgets.Layout(width='98%'),
                                              button_style='danger')
        self.begin_cross_val.on_click(self.run_cross_val)

        self.market = widgets.Dropdown(
            options={u'美股': EMarketTargetType.E_MARKET_TARGET_US.value,
                     u'A股': EMarketTargetType.E_MARKET_TARGET_CN.value,
                     u'港股': EMarketTargetType.E_MARKET_TARGET_HK.value,
                     u'国内期货': EMarketTargetType.E_MARKET_TARGET_FUTURES_CN.value,
                     u'国际期货': EMarketTargetType.E_MARKET_TARGET_FUTURES_GLOBAL.value,
                     u'数字货币': EMarketTargetType.E_MARKET_TARGET_TC.value},
            value=ABuEnv.g_market_target.value,
            description=u'验证市场:',
        )

        cv_label1 = widgets.Label(u'交叉验证的数量级:默认10', layout=widgets.Layout(width='300px'))
        cv_label2 = widgets.Label(u'cv次相关度范围随机抽取cv个symbol进行回测', layout=widgets.Layout(width='300px'))
        self.cv = widgets.IntSlider(
            value=10,
            min=4,
            max=50,
            step=1,
            description=u'cv',
            disabled=False,
            orientation='horizontal',
            readout=True,
            readout_format='d'
        )
        cv_box = widgets.VBox([cv_label1, cv_label2, self.cv])

        self.widget = widgets.VBox([tip_label1, tip_label2, sub_widget_tab, self.market, cv_box,
                                    self.begin_cross_val])

        # 初始化就new处理,每次运行都使用它,可以缓存similar数据
        self.cross_val = AbuCrossVal()

    # noinspection PyUnusedLocal