calculate the amount of money to buy stock
356750
def __getCashToBuyStock(self):
        '''  '''
        account=self.__strategy.getAccountCopy()
        if (account.getCash() >= account.getTotalValue() / self.buying_ratio):
            return account.getTotalValue() / self.buying_ratio
        else:
            return 0
198754
def T_stock(self, V_stock):
        
        return Stock.T_stock(self, V_stock, self.Q_stock()).to(u.hr)
984931
def calculate_fee(self, input_values):
        '''
        
        '''
        return \
            sum(input_values) \
            - sum([utils.le2i(o.value) for o in self.tx_outs])
1104593
def market_value(self):
        
        if self.account.daily_hold is not None:
            if self.if_fq:

                return (
                    self.market_data.to_qfq().pivot('close').fillna(
                        method='ffill'
                    ) * self.account.daily_hold.apply(abs)
                ).fillna(method='ffill')
            else:
                return (
                    self.market_data.pivot('close').fillna(method='ffill') *
                    self.account.daily_hold.apply(abs)
                ).fillna(method='ffill')
        else:
            return None
1094037
def _calculate_price_by_slippage(self, action: str, price: float) -> float:
        
        if action == "buy":
            return price * (1 + self.slippage)
        if action == "sell":
            return price * (1 - self.slippage)
        return price
914888
def validate(self,
                 asset,
                 amount,
                 portfolio,
                 algo_datetime,
                 algo_current_data):
        

        if self.asset is not None and self.asset != asset:
            return

        if self.max_shares is not None and abs(amount) > self.max_shares:
            self.handle_violation(asset, amount, algo_datetime)

        current_asset_price = algo_current_data.current(asset, "price")
        order_value = amount * current_asset_price

        too_much_value = (self.max_notional is not None and
                          abs(order_value) > self.max_notional)

        if too_much_value:
            self.handle_violation(asset, amount, algo_datetime)
1234712
public function calculate()
    {
        $this->init();

        foreach ($this->getPaymentList() as $payment) {
            $status = $payment->getStatus();
            $action = $payment->getAction();
            $amount = $payment->getAmount();

            $this->aggregateAmounts($action, $status, $amount);
        }
    }
1150330
def get_num_shares(self) -> Decimal:
        
        from pydatum import Datum
        today = Datum().today()
        return self.get_num_shares_on(today)
782301
def calculate_fee(self, input_values):
        '''
        
        '''
        total_in = sum(input_values)
        total_out = sum([utils.le2i(tx_out.value) for tx_out in self.tx_outs])
        for js in self.tx_joinsplits:
            total_in += utils.le2i(js.vpub_new)
            total_out += utils.le2i(js.vpub_old)
        return total_in - total_out
514082
def calculate_current_allocation(self):
        
        for ac in self.asset_classes:
            ac.curr_alloc = ac.curr_value * 100 / self.total_amount
1117844
def earn_stock_dividend(self, stock_dividend):
        
        return {
            'payment_asset': stock_dividend.payment_asset,
            'share_count': np.floor(
                self.amount * float(stock_dividend.ratio)
            )
        }
256938
def current_hold_price(self):
        
        
        def weights(x):
            n=len(x)
            res=1
            while res>0 or res<0:
                res=sum(x[:n]['amount'])
                n=n-1
            
            x=x[n+1:]     
            
            if sum(x['amount']) != 0:
                return np.average(
                    x['price'],
                    weights=x['amount'],
                    returned=True
                )
            else:
                return np.nan
        return self.history_table.set_index(
            'datetime',
            drop=False
        ).sort_index().groupby('code').apply(weights).dropna()
859946
def value_percent(self):
        
        accounts = Environment.get_instance().portfolio.accounts
        if DEFAULT_ACCOUNT_TYPE.STOCK.name not in accounts:
            return 0
        total_value = accounts[DEFAULT_ACCOUNT_TYPE.STOCK.name].total_value
        return 0 if total_value == 0 else self.market_value / total_value
1104842
def write_dividend_data(self, dividends, stock_dividends=None):
        

        # First write the dividend payouts.
        self._write_dividends(dividends)
        self._write_stock_dividends(stock_dividends)

        # Second from the dividend payouts, calculate ratios.
        dividend_ratios = self.calc_dividend_ratios(dividends)
        self.write_frame('dividends', dividend_ratios)
144887
def select_inputs(self, amount):
      ''''''
      sorted_txin = sorted(self.ins, key=lambda x:-x['input']['confirmations'])
      total_amount = 0
      for (idx, tx_in) in enumerate(sorted_txin):
        total_amount += tx_in['input']['amount']
        if (total_amount >= amount):
          break
      sorted_txin = sorted(sorted_txin[:idx+1], key=lambda x:x['input']['amount'])
      for (idx, tx_in) in enumerate(sorted_txin):
        value = tx_in['input']['amount']
        if (total_amount - value < amount):
          break
        else:
          total_amount -= value
      self.ins = sorted_txin[idx:]
      return total_amount
1088599
def balance(self):
        """"""
        sin = Decimal("0.00")
        sout = Decimal("0.00")

        for t in self.trans:
            if t.amount < Decimal("0.00"):
                sout += t.amount
            else:
                sin += t.amount

        return sin, sout
658732
public function calculatePriceTaxable()
    {
        $money = new Money(round($this->price, 2, PHP_ROUND_HALF_UP) * 100, new Currency($this->invoice->currency));

        return $money;
    }