Пример #1
0
    def render(self):
        if self.props.side == "bid":
            color = "rgba(50, 50, 255, 1)"
        else:
            color = "rgba(255, 50, 50, 1)"

        price_box_style = dict(stylesheet.price_box)
        size_box_style = dict(stylesheet.size_box)
        size_bar_style = dict(stylesheet.size_bar)

        size_box_style["background-color"] = color
        size_bar_style.update({
            "background-color": color,
            "width": "%spx" % (self.props.size / 5),
        })
        if self.props.last:
            price_box_style["border-bottom"] = "1px solid black"
            size_box_style["border-bottom"] = "1px solid black"

        return ed.View(layout="row",
                       style={
                           "padding": "0px",
                           "width": "360px",
                           "align": "left"
                       })(ed.Label(self.props.price,
                                   style=price_box_style).set_key("price"),
                          ed.Label(self.props.size,
                                   style=size_box_style).set_key("size"),
                          ed.Label("",
                                   style=size_bar_style).set_key("vis_size"))
Пример #2
0
    def render(self):
        component = self.props.component
        module = inspect.getmodule(component.__class__)
        lineno = None
        try:
            lineno = inspect.getsourcelines(component.__class__)[1]
        except:
            pass
        heading_style = {"font-size": "16px", "margin": 10, "margin-bottom": 0}

        return ed.View(
            layout="column",
            style={
                "align": "top",
                "min-width": 450,
                "min-height": 450
            })(
                ed.Label(component.__class__.__name__,
                         selectable=True,
                         style={
                             "font-size": "20px",
                             "margin": 10
                         }).set_key("class_name"),
                ed.Label("Class defined in " + module.__file__ + ":" +
                         str(lineno),
                         selectable=True,
                         style={
                             "margin-left": 10
                         }).set_key("file"),
                ed.Label("Props", style=heading_style).set_key("props_header"),
                PropsView(component.props).set_key("_props_view"),
                ed.Label("State", style=heading_style).set_key("state_header"),
                StateView(component).set_key("_state_view"),
            )
Пример #3
0
 def render(self):
     return ed.View()(
         ed.Label(self.a),
         ed.Label(self.b),
         ed.Slider(self.a,
                   min_value=0,
                   max_value=1,
                   on_change=self._on_change),
         ed.Button("Update b",
                   on_click=lambda e: self.set_state(b=self.b + 1)),
     )
Пример #4
0
 def render(self):
     return ed.View(layout="row")(
         ed.View(layout="column", style={
             "width": 720,
             "margin": 10
         })(
             ed.View(layout="row")(
                 ed.IconButton("pause" if self.is_playing else "play",
                               on_click=lambda e: self.set_state(
                                   is_playing=not self.is_playing)),
                 ed.Button(
                     "Reset",
                     on_click=lambda e: self.set_state(simulation_time=0)),
             ),
             plotting.Figure(lambda figure: self.plot(figure)),
             ed.View(layout="row", style={"margin": 10})(
                 ed.Label("Angular Frequency"),
                 ed.Slider(value=self.angular_frequency,
                           min_value=1,
                           max_value=10,
                           on_change=lambda value: self.set_state(
                               angular_frequency=value, simulation_time=0)),
                 ed.Label("Damping Factor"),
                 ed.Slider(value=self.damping,
                           min_value=-3,
                           max_value=0,
                           on_change=lambda value: self.set_state(
                               damping=value, simulation_time=0)),
             ),
             # We position the ball and the centroid using absolute positioning.
             # The label and ball offsets are different since we have to take into-account the size of the ball
             ed.View(layout="none",
                     style={
                         "width": 720,
                         "height": 10,
                         "margin-top": 40
                     })
             (
                 ed.Icon("bowling-ball",
                         size=20,
                         color=(255, 0, 0, 255),
                         style={
                             "left":
                             350 + 200 * self.calculate_harmonic_motion(
                                 self.simulation_time)
                         }),
                 ed.Label("|",
                          style={
                              "left": 356,
                              "font-size": 20,
                              "color": "blue"
                          }),
             )))
Пример #5
0
 def render(self):
     return ed.View()(
         ed.View(
             style={
                 "height": 200,
                 "width": 200,
                 "background-color": "red"
             },
             on_mouse_enter=lambda e: self.set_state(entered=True),
             on_mouse_leave=lambda e: self.set_state(entered=False),
             on_mouse_down=lambda e: self.set_state(pressed=True),
             on_mouse_up=lambda e: self.set_state(pressed=False),
             on_mouse_move=lambda e: self.set_state(pos=(e.x(), e.y())))(
                 ed.Label("TESTING"), ),
         ed.Label("Entered" if self.entered else ""),
         ed.Label("Pressed" if self.pressed else ""),
         ed.Label(self.pos),
     )
Пример #6
0
 def render(self):
     state = dict((k, v) for (k, v) in vars(self.props.component).items()
                  if k[0] != "_")
     return ed.ScrollView(
         layout="column", style={
             "align": "top",
             "margin-left": 15
         })(*[
             ed.View(layout="row", style={"align": "left"})(
                 ed.Label(key + ":",
                          selectable=True,
                          style={
                              "font-weight": 600,
                              "width": 140
                          }).set_key("key"),
                 ed.Label(state[key], selectable=True, style={}).set_key(
                     "value"),
             ).set_key(key) for key in state
         ])
Пример #7
0
 def render(self):
     root = self.props.root
     on_click = self.props.on_click
     try:
         selected = current_selection.subscribe(self, id(root)).value
     except KeyError:
         selected = False
     return ed.Label(
         root.__class__.__name__,
         style={"background-color": SELECTION_COLOR} if selected else {},
         on_click=on_click)
Пример #8
0
 def render(self):
     props = self.props.props
     return ed.ScrollView(
         layout="column", style={
             "align": "top",
             "margin-left": 15
         })(*[
             ed.View(layout="row", style={"align": "left"})(
                 ed.Label(
                     key + ":",
                     selectable=True,
                     style={
                         "font-weight": 600,
                         "width": 140
                     },
                 ).set_key("key"),
                 ed.Label(props[key], selectable=True, style={}).set_key(
                     "value"),
             ).set_key(key) for key in props._keys
         ])
Пример #9
0
 def render(self):
     try:
         selected = current_selection.subscribe(self,
                                                id(self.props.root)).value
     except KeyError:
         selected = False
     root_style = {"margin-left": 5}
     if selected:
         root_style["background-color"] = SELECTION_COLOR
     return ed.View(layout="row", style={"align": "left"})(
         ed.Icon(
             "caret-right",
             rotation=0 if self.props.collapsed else 90,
             on_click=self.props.toggle,
         ).set_key("caret"),
         ed.Label(self.props.root.__class__.__name__,
                  style=root_style,
                  on_click=self.props.on_click).set_key("title"),
     )
Пример #10
0
 def render(self):
     return ed.View(layout="column")(
         ed.View(layout="row",
                 style={
                     "align": "left",
                     "margin-left": "10px"
                 })(
                     ed.Icon(name="chart-line", size=14).set_key("Icon"),
                     ed.Label("Market Data Viewer",
                              style={
                                  "margin-left": "5px"
                              }).set_key("Label"),
                     ed.IconButton(
                         name="pause" if self.playing else "play",
                         style=stylesheet.play_button,
                         size=10,
                         on_click=self.play,
                     ).set_key("Play"),
                 ).set_key("Controls"),
         Book(self.book).set_key("Book"),
     )
Пример #11
0
 def render(self):
     if self.props.level > 0:
         layout = "row" if self.props.level % 2 == 0 else "column"
         return ed.View(layout=layout)(
             RecurseTree(level=self.props.level - 1,
                         t=self.props.t).set_key("0"),
             RecurseTree(level=self.props.level - 1,
                         t=self.props.t).set_key("1"),
         )
     else:
         return ed.View(layout="row")(
             ed.View(
                 style={
                     "background-color": "rgba(255, 255, 0, 1)",
                     "width": "25px",
                     "height": "25px",
                     "min-height": "25px",
                     "min-width": "25px",
                     "max-width": "25px"
                 }).set_key("0"),
             ed.Label("%.02f" % self.props.t).set_key("1"),
         )
Пример #12
0
 def render(self):
     if self.must_refresh or self._cached_tree is None:
         self._cached_tree = self._build_tree(self.root_component)
     return ed.View(layout="row")(
         ed.View(layout="column",
                 style={
                     "align": "top",
                     "width": 251,
                     "border-right": "1px solid gray"
                 })(
                     ed.View(layout="row",
                             style={
                                 "align": "left",
                                 "height": 30
                             })(ed.Label("Edifice Inspector",
                                         style={
                                             "font-size": 18,
                                             "margin-left": 10,
                                             "width": 160
                                         }).set_key("title"),
                                ed.Icon("sync-alt",
                                        size=20,
                                        on_click=lambda e: self._refresh,
                                        tool_tip="Reload component tree").
                                set_key("refresh")).set_key("heading"),
                     ed.ScrollView(layout="column",
                                   style={
                                       "width": 250,
                                       "min-height": 450,
                                       "margin-top": 10
                                   })(self._cached_tree).set_key("tree"),
                 ).set_key("left_pane"),
         ed.View(
             layout="column", style={
                 "min-width": 450,
                 "min-height": 450
             })(self.selected
                and ComponentView(self.selected).set_key("component_view")).
         set_key("right_pane"))
Пример #13
0
 def render(self):
     return ed.View(on_key_down=self.key_down)(ed.Label(self.text))
Пример #14
0
 def render(self):
     return edifice.Label("Test")
Пример #15
0
    def render(self):
        window_style = {
            "background-color": "#404040",
            "height": 300,
            "width": 242
        }
        button_style = {
            "font-size": 20,
            "color": "white",
            "height": 60,
            "width": 60,
            "border": "1px solid #333333"
        }
        digits_style = button_style | {"background-color": "#777777"}
        binary_style = button_style | {
            "background-color": "#ff9e00",
            "font-size": 30
        }
        unary_style = button_style | {"background-color": "#595959"}
        display_style = {
            "font-size": 50,
            "height": 70,
            "color": "white",
            "width": 240,
            "align": "right",
            "padding-right": 10
        }

        def make_add_digit(digit):
            def add_digit(e):
                with self.render_changes():
                    if self.clear_display:
                        self.display = "0"
                        self.clear_display = False
                    if digit == ".":
                        try:
                            # See if adding a decimal is allowed at this point
                            _ = float(self.display + ".")
                            self.display += "."
                        except ValueError:
                            pass
                    else:
                        if self.display == "0":
                            self.display = str(digit)
                        else:
                            self.display += str(digit)

            return add_digit

        def digit_button(digit, double_width=False):
            # Create digits buttons, include the decimal point
            button_style = digits_style.copy()
            if double_width:
                button_style["width"] = 2 * button_style["width"]
            return ed.Button(str(digit),
                             style=button_style,
                             on_click=make_add_digit(digit))

        def apply_binary_operand(operator):
            with self.render_changes():
                self.clear_display = True
                if self.previous_operator is None or self.previous_operator == "=":
                    self.stored_value = float(self.display)
                else:
                    self.stored_value = OPERATORS[self.previous_operator](
                        self.stored_value, float(self.display))
                    self.display = "%.4f" % self.stored_value
                self.previous_operator = operator

        def binary_button(symbol):
            # Qt layout is sometimes unintuitive, but you can definitely hack around it!
            button_style = binary_style.copy()
            return ed.Button(symbol,
                             style=button_style,
                             on_click=lambda e: apply_binary_operand(symbol))

        def unary_button(symbol):
            def apply_unary_operand(operator):
                with self.render_changes():
                    self.clear_display = True
                    self.display = "%.4f" % OPERATORS[operator](float(
                        self.display))

            return ed.Button(symbol,
                             style=unary_style,
                             on_click=lambda e: apply_unary_operand(symbol))

        def key_press(e):
            if ord('0') <= e.key() <= ord('9'):
                make_add_digit(e.key() - ord('0'))(None)
            elif e.text() in ['+', '-', '*', '/']:
                apply_binary_operand(e.text())
            elif e.key() == ed.Key.Key_Return:
                apply_binary_operand("=")

        return ed.Window(title="Calculator")(ed.View(
            layout="column", style=window_style, on_key_down=key_press)(
                ed.Label(self.display, style=display_style),
                ed.GridView(layout="""cs%/
                                      789*
                                      456-
                                      123+
                                      00.=""")(
                    unary_button("AC").set_key("c"),
                    unary_button("+/-").set_key("s"),
                    unary_button("%").set_key("%"),
                    binary_button("÷").set_key("/"),
                    digit_button(7).set_key("7"),
                    digit_button(8).set_key("8"),
                    digit_button(9).set_key("9"),
                    binary_button("×").set_key("*"),
                    digit_button(4).set_key("4"),
                    digit_button(5).set_key("5"),
                    digit_button(6).set_key("6"),
                    binary_button("-").set_key("-"),
                    digit_button(1).set_key("1"),
                    digit_button(2).set_key("2"),
                    digit_button(3).set_key("3"),
                    binary_button("+").set_key("+"),
                    digit_button(0, double_width=True).set_key("0"),
                    digit_button(".").set_key("."),
                    binary_button("=").set_key("="),
                )))
Пример #16
0
    def render(self):
        values = ["option_price", "delta", "gamma", "theta", "vega",]
        days_to_maturity = None
        if self.expiry:
            days_to_maturity = int(days_till_expiration(self.expiry)) - 1
        expiry_loaded = self.ticker is not None and self.expiries != [] and not self.loading_expiries
        option_chain_loaded = (self.ticker is not None and self.option_chain is not None
                               and not self.loading_option_chain)

        if expiry_loaded and option_chain_loaded:
            option_chain = self.get_option_chain()
            implied_vol = option_chain[option_chain.strike == float(self.strike_price)].impliedVolatility.iloc[0] * 100
            if math.isnan(implied_vol):
                implied_vol = 1000.0
            args = [float(self.strike_price), -float(days_to_maturity),
                    float(self.last_close_price), 0.01 / 365, implied_vol]
            greeks = {
                "gamma": black_scholes.gamma(*args),
                "theta": black_scholes.theta(*args),
                "vega": black_scholes.vega(*args),
            }
            if self.option_type == "Call":
                greeks.update({
                    "delta": black_scholes.delta(*args),
                    "option_price": black_scholes.call_price(*args),
                })
            else:
                greeks.update({
                    "delta": black_scholes.delta(*args) - 1,
                    "option_price": black_scholes.put_price(*args),
                })

        return ed.View(style={"align": "top", "margin": 10})(
            ed.Label("Loading..." if self.loading_expiries or self.loading_option_chain else "",
                     style={"margin-bottom": 5}),
            ed.View(layout="row", style={"align": "left"})(
                ed.View(layout="row", style={"width": 200})(
                    ed.Label("Ticker"),
                    ed.TextInput(self.ticker, on_change=self.ticker_changed),
                    ed.Dropdown(str(self.option_type), options=["Call", "Put"],
                                on_select=lambda text: self.set_state(option_type=text)),
                ),
                expiry_loaded and ed.View(layout="row", style={"width": 170, "margin-left": 5})(
                    ed.Label("Expiry"),
                    ed.Dropdown(str(self.expiry), options=self.expiries, on_select=self.expiry_changed),
                ),
                option_chain_loaded and ed.View(layout="row", style={"width": 150, "margin-left": 5})(
                    ed.Label("Strike Price"),
                    ed.Dropdown(str(self.strike_price),
                            options=list(map(str, self.get_option_chain().strike)) if self.option_chain else [],
                            on_select=self.strike_changed),
                ),
            ),
            expiry_loaded and option_chain_loaded and ed.View(layout="row", style={"align": "left"})(
                ed.Label("X"),
                ed.Dropdown(selection=self.xaxis, options=["days_to_expiration", "stock_price", "implied_vol"],
                            on_select=lambda text: self.set_state(xaxis=text)),
                ed.Label("Y"),
                ed.Dropdown(selection=self.yaxis, options=values,
                            on_select=lambda text: self.set_state(yaxis=text)),
                self.xaxis != "stock_price" and ed.Label(f"Stock Price ({self.stock_price:.2f})"),
                self.xaxis != "stock_price" and ed.Slider(
                    self.stock_price, min_value=self.last_close_price / 3, max_value=self.last_close_price * 3 + 1,
                    on_change=lambda val: self.set_state(stock_price=val),
                ).set_key("stock_price_slider"),
                self.xaxis != "days_to_expiration" and ed.Label(f"Days to Maturity ({self.days_to_maturity:.1f})"),
                self.xaxis != "days_to_expiration" and ed.Slider(
                    self.days_to_maturity, min_value=days_to_maturity, max_value=-0.1,
                    on_change=lambda val: self.set_state(days_to_maturity=val),
                ).set_key("maturity_slider"),
                self.xaxis != "implied_vol" and ed.Label(f"Implied Vol ({self.implied_vol:.1f})"),
                self.xaxis != "implied_vol" and ed.Slider(
                    self.implied_vol, min_value=implied_vol/2, max_value=implied_vol*2 + 10,
                    on_change=lambda val: self.set_state(implied_vol=val),
                ).set_key("vol_slider"),
            ),
            expiry_loaded and option_chain_loaded and ed.View()(
                ed.Label("Option Greeks:", style={"font-size": 18}),
                ed.View(layout="row")(
                    ed.Label(f"<b>Days to maturity:</b> {days_to_maturity}"),
                    ed.Label(f"<b>Stock price:</b> ${self.last_close_price:.2f}\t"),
                    ed.Label(f"<b>Option price:</b> ${greeks['option_price']:.2f}\t\n"),
                    ed.Label(f"<b>Implied Vol:</b> {implied_vol:.0f}%\t"),
                ),
                ed.View(layout="row")(
                    ed.Label(f"<b>Delta:</b> {greeks['delta']:.2f}\t"),
                    ed.Label(f"<b>Gamma:</b> {greeks['gamma']:.3f}\t"),
                    ed.Label(f"<b>Theta:</b> {greeks['theta']:.3f}\t"),
                    ed.Label(f"<b>Vega:</b> {greeks['vega']:.2f}\t"),
                )
            ),
            expiry_loaded and option_chain_loaded and plotting.Figure(plot_fun=lambda ax: self.plot(ax)),
        )