Alter the stock price
767950
public void change()
    {
        float newChange = (random.nextFloat() * 4) - 2;
        newChange = Math.round(newChange * 100.0F) / 100.0F;

        if (last.floatValue() + newChange < 9)
        {
            newChange = -newChange;
        }

        change = new BigDecimal(newChange);
        change = change.setScale(2, BigDecimal.ROUND_UP);

        last = last.add(change);

        if (last.compareTo(max) > 0)
        {
            max = last;
        }

        if (last.compareTo(min) < 0)
        {
            min = last;
        }

        time = new Date();
    }
392762
def SetValue(self, value=None, act=True):
        "  "
        if value is None:
            value = wx.TextCtrl.GetValue(self).strip()
        self.__CheckValid(value)
        self.__GetMark()
        if value is not None:
            wx.TextCtrl.SetValue(self, self.format % set_float(value))

        if self.is_valid and hasattr(self.__action, '__call__') and act:
            self.__action(value=self.__val)
        elif not self.is_valid and self.bell_on_invalid:
            wx.Bell()

        self.__SetMark()
203052
def set_value(self, value):
        """"""
        if not isinstance(value, str):
            raise TypeError("A value must be a string, got %s." % value)
        self.__value = value
585545
def option_changed(self, option, value):
        """"""
        setattr(self, to_text_string(option), value)
        self.shellwidget.set_namespace_view_settings()
        self.refresh_table()
809348
def Task_display(self):
    
    re = """%(stock_name)s %(stock_no)s %(stock_date)s
Today: %(stock_price)s %(stock_range)s
=-=-=-=""" % {
        'stock_name': unicode(self.stock_name),
        'stock_no': unicode(self.stock_no),
        'stock_date': unicode(self.data_date[-1]),
        'stock_price': unicode(self.raw_data[-1]),
        'stock_range': unicode(self.stock_range[-1]),
      }
    return re
462265
public function updateTotalNetPrice()
    {
        if (!$this->getItems()) {
            return;
        }

        $sum = 0;
        foreach ($this->getItems() as $item) {
            $sum += $item->getTotalNetPrice();
        }
        $this->setTotalNetPrice($sum);
    }
77556
def adjust_weight(self, stock_code, weight):
        

        stock = self._search_stock_info(stock_code)
        if stock is None:
            raise exceptions.TradeError(u"没有查询要操作的股票信息")
        if stock["flag"] != 1:
            raise exceptions.TradeError(u"未上市、停牌、涨跌停、退市的股票无法操作。")

        # 仓位比例向下取两位数
        weight = round(weight, 2)
        # 获取原有仓位信息
        position_list = self._get_position()

        # 调整后的持仓
        for position in position_list:
            if position["stock_id"] == stock["stock_id"]:
                position["proactive"] = True
                position["weight"] = weight

        if weight != 0 and stock["stock_id"] not in [
            k["stock_id"] for k in position_list
        ]:
            position_list.append(
                {
                    "code": stock["code"],
                    "name": stock["name"],
                    "enName": stock["enName"],
                    "hasexist": stock["hasexist"],
                    "flag": stock["flag"],
                    "type": stock["type"],
                    "current": stock["current"],
                    "chg": stock["chg"],
                    "percent": str(stock["percent"]),
                    "stock_id": stock["stock_id"],
                    "ind_id": stock["ind_id"],
                    "ind_name": stock["ind_name"],
                    "ind_color": stock["ind_color"],
                    "textname": stock["name"],
                    "segment_name": stock["ind_name"],
                    "weight": weight,
                    "url": "/S/" + stock["code"],
                    "proactive": True,
                    "price": str(stock["current"]),
                }
            )

        remain_weight = 100 - sum(i.get("weight") for i in position_list)
        cash = round(remain_weight, 2)
        log.debug("调仓比例:%f, 剩余持仓 :%f", weight, remain_weight)
        data = {
            "cash": cash,
            "holdings": str(json.dumps(position_list)),
            "cube_symbol": str(self.account_config["portfolio_code"]),
            "segment": "true",
            "comment": "",
        }

        try:
            resp = self.s.post(self.config["rebalance_url"], data=data)
        # pylint: disable=broad-except
        except Exception as e:
            log.warning("调仓失败: %s ", e)
            return None
        log.debug("调仓 %s: 持仓比例%d", stock["name"], weight)
        resp_json = json.loads(resp.text)
        if "error_description" in resp_json and resp.status_code != 200:
            log.error("调仓错误: %s", resp_json["error_description"])
            return [
                {
                    "error_no": resp_json["error_code"],
                    "error_info": resp_json["error_description"],
                }
            ]
        log.debug("调仓成功 %s: 持仓比例%d", stock["name"], weight)
        return None
169788
def recalculate_stock_values_into_base(self):
        
        from .currency import CurrencyConverter

        conv = CurrencyConverter()
        cash = self.model.get_cash_asset_class()

        for stock in self.model.stocks:
            if stock.currency != self.base_currency:
                # Recalculate into base currency
                conv.load_currency(stock.currency)
                assert isinstance(stock.value, Decimal)
                val_base = stock.value * conv.rate.value
            else:
                # Already in base currency.
                val_base = stock.value

            stock.value_in_base_currency = val_base
561087
public function modifyCardStock($card_id, $increase_stock_value = 0, $reduce_stock_value = 0)
    {
        if (empty($card_id)) {
            return false;
        }
        $result = $this->httpPost(static::WECHAT_MODIFY_CARD_STOCK . 'access_token=' . $this->getAccessToken(), [
            'card_id' => $card_id,
            'increase_stock_value' => $increase_stock_value,
            'reduce_stock_value' => $reduce_stock_value
        ]);

        return isset($result['errmsg']) && $result['errmsg'] === 'ok' ? true : false;
    }
1340278
public void valueChanged(ListSelectionEvent lse) {
        int selectedIndex = list.getSelectedIndex();
        if (selectedIndex == -1) {
            editButton.setEnabled(false);
            removeButton.setEnabled(false);
            moveUpButton.setEnabled(false);
            moveDownButton.setEnabled(false);
            return;
        }

        editButton.setEnabled(true);
        removeButton.setEnabled(true);
        moveUpButton.setEnabled(selectedIndex != 0);
        moveDownButton.setEnabled(selectedIndex != list.getLastVisibleIndex());
    }
481472
def Cmd_display(self):
    
    re = "%(stock_no)s %(stock_name)s %(stock_date)s %(stock_price)s %(stock_range)s %(stock_range_per).2f%% %(RABC)s %(stock_vol)s" % {
        'stock_name': unicode(self.stock_name),
        'stock_no': unicode(self.stock_no),
        'stock_date': unicode(self.data_date[-1]),
        'stock_price': unicode(self.raw_data[-1]),
        'stock_range': unicode(self.stock_range[-1]),
        'stock_range_per': self.range_per,
        'stock_vol': self.stock_vol[-1]/1000,
        'RABC': self.RABC
      }
    return re
238689
def setValue(self, newText):
        """"""
        self.text = newText
        self.cursorPosition = len(self.text)
        self._updateImage()
1076525
def __set_unit_price(self, value):
        '''
        
        '''
        try:
            if value < 0:
                raise ValueError()

            self.__unit_price = Decimal(str(value))
        except ValueError:
            raise ValueError("Unit Price must be a positive number")
796974
def on_config_value_changed(self, config_m, prop_name, info):
        
        config_key = info['args'][1]

        if config_key in ["EXECUTION_TICKER_ENABLED"]:
            self.check_configuration()
151245
def forceValue(self, newVal, noteEdited=False):
        """"""
        if newVal is None:
            newVal = ""
        self.choice.set(newVal)
        if noteEdited:
            self.widgetEdited(val=newVal, skipDups=False)
1051173
def checkStock(self):
        """"""
        if not self.preferences:
            logger.debug("no preferences")
            return None
        soup = BeautifulSoup(
            self.xpath(path['stock-table'])[0].html, "html.parser")
        count = 0
        # iterate through product in left panel
        for product in soup.select("div.tradebox"):
            prod_name = product.select("span.instrument-name")[0].text
            stk_name = [x for x in self.preferences
                        if x.lower() in prod_name.lower()]
            if not stk_name:
                continue
            name = prod_name
            if not [x for x in self.stocks if x.product == name]:
                self.stocks.append(Stock(name))
            stock = [x for x in self.stocks if x.product == name][0]
            if 'tradebox-market-closed' in product['class']:
                stock.market = False
            if not stock.market:
                logger.debug("market closed for %s" % stock.product)
                continue
            sell_price = product.select("div.tradebox-price-sell")[0].text
            buy_price = product.select("div.tradebox-price-buy")[0].text
            sent = int(product.select(path['sent'])[0].text.strip('%')) / 100
            stock.new_rec([sell_price, buy_price, sent])
            count += 1
        logger.debug(f"added %d stocks" % count)
        return self.stocks
848127
def modify(self, vals):
        """"""
        self.vals = vals.view(np.ndarray).copy()
        y = self.model.predict(self.vals)[0]
        self.data_visualize.modify(y)
        self.latent_handle.set_data(self.vals[0,self.latent_index[0]], self.vals[0,self.latent_index[1]])
        self.axes.figure.canvas.draw()