Calculates the average price paid for the security.
        security = Commodity
        Returns Decimal value.
774859
def get_avg_price_fifo(self) -> Decimal:
        
        balance = self.get_quantity()
        if not balance:
            return Decimal(0)

        paid = Decimal(0)
        accounts = self.get_holding_accounts()
        # get unused splits (quantity and total paid) per account.
        for account in accounts:
            splits = self.get_available_splits_for_account(account)

            for split in splits:
                paid += split.value

        avg_price = paid / balance
        return avg_price
65289
def variance(arr):
  
  avg = average(arr)
  return sum([(float(x)-avg)**2 for x in arr])/float(len(arr)-1)
858585
def get_price(self):
        
        for cond in self.conditions:
            for p in cond.parameters:
                if p.name == '_amount':
                    return p.value
32699
def calculate_current_value(self):
        
        # must be recursive
        total = Decimal(0)
        for ac in self.classes:
            self.__calculate_current_value(ac)
            total += ac.curr_value
        self.total_amount = total
279336
def get_price_as_of(self, stock: Commodity, on_date: datetime):
        
        # return self.get_price_as_of_query(stock, on_date).first()
        prices = PriceDbApplication()
        prices.get_prices_on(on_date.date().isoformat(), stock.namespace, stock.mnemonic)
304298
def getTotalDiscountedBulkPrice(self):
        
        price = self.getDiscountedCorporatePrice()
        vat = self.getVAT()
        price = price and price or 0
        vat = vat and vat or 0
        return float(price) + (float(price) * float(vat)) / 100
158570
def marketPrice(self) -> float:
        
        price = self.last if (
            self.hasBidAsk() and self.bid <= self.last <= self.ask) else \
            self.midpoint()
        if isNan(price):
            price = self.close
        return price
473965
def fee(self, value=None, unit='satoshi'):
        
        convert = None
        if not value:
            # no fee was specified, use $0.02 as default.
            convert = get_current_price(self.crypto, "usd")
            self.fee_satoshi = int(0.02 / convert * 1e8)
            verbose = "Using default fee of:"

        elif value == 'optimal':
            self.fee_satoshi = get_optimal_fee(
                self.crypto, self.estimate_size(), verbose=self.verbose
            )
            verbose = "Using optimal fee of:"
        else:
            self.fee_satoshi = self.from_unit_to_satoshi(value, unit)
            verbose = "Using manually set fee of:"

        if self.verbose:
            if not convert:
                convert = get_current_price(self.crypto, "usd")
            fee_dollar = convert * self.fee_satoshi / 1e8
            print(verbose + " %s satoshis ($%.2f)" % (self.fee_satoshi, fee_dollar))
427098
def getSubtotal(self):
        
        if self.supplyorder_lineitems:
            return sum(
                [(Decimal(obj['Quantity']) * Decimal(obj['Price'])) for obj in self.supplyorder_lineitems])
        return 0
366108
def get_optimal_fee(crypto, tx_bytes, **modes):
    
    try:
        services = get_optimal_services(crypto, 'get_optimal_fee')
    except NoServicesDefined:
        convert = get_current_price(crypto, 'usd')
        fee = int(0.02 / convert * 1e8)

        if modes.get('report_services'):
            return [None], fee
        else:
            return fee

    fee = enforce_service_mode(
        services, OptimalFee, dict(crypto=crypto, tx_bytes=tx_bytes), modes=modes
    )
    if modes.get('report_services'):
        return fee[0], int(fee[1])
    else:
        return int(fee)
615823
public function calculateItemNetPrice($item, $currency = null, $useProductsPrice = null, $isGrossPrice = false)
    {
        $currency = $this->getCurrency($currency);

        if ($useProductsPrice === null) {
            $useProductsPrice = $item->getUseProductsPrice();
        }

        // Validate item
        $this->validateItem($item);

        $priceValue = $item->getPrice();

        if ($useProductsPrice && ($item->getCalcProduct() || $item->getAddon())) {
            $priceValue = $this->getValidProductNetPriceForItem($item, $currency);
        } elseif ($isGrossPrice) {
            // Handle gross prices.
            $tax = $item->getTax();
            if ($tax > 0) {
                $priceValue = ($priceValue / (100 + $tax)) * 100;
            }
        }

        return $priceValue;
    }
28034
def typical_price(close_data, high_data, low_data):
    
    catch_errors.check_for_input_len_diff(close_data, high_data, low_data)
    tp = [(high_data[idx] + low_data[idx] + close_data[idx]) / 3 for idx in range(0, len(close_data))]
    return np.array(tp)
441359
def _get_price(self, data, market, field):
        
        for m in data:
            if m["symbol"] == market:
                return m[field]
866149
def load_stock_prices(self):
        
        from pricedb import SecuritySymbol

        info = StocksInfo(self.config)
        for item in self.model.stocks:
            symbol = SecuritySymbol("", "")
            symbol.parse(item.symbol)

            price: PriceModel = info.load_latest_price(symbol)
            if not price:
                # Use a dummy price of 1, effectively keeping the original amount.
                price = PriceModel()
                price.currency = self.config.get(ConfigKeys.default_currency)
                price.value = Decimal(1)
            item.price = price.value
            if isinstance(item, Stock):
                item.currency = price.currency
                # Do not set currency for Cash balance records.
        info.close_databases()
494470
public double averageFalseAlarmRate() {
        double ret = 0.0;
        for (int i = 0; i < numLabels(); i++) {
            ret += falseAlarmRate(i);
        }

        ret /= (double) numLabels();
        return ret;
    }
984931
def calculate_fee(self, input_values):
        '''
        
        '''
        return \
            sum(input_values) \
            - sum([utils.le2i(o.value) for o in self.tx_outs])
687300
private function calculateProductsPriceByFlat(float $spread_value, $stock_price, $currency)
    {
        $calculatedPriceByCurrencyRate =  $this->getCalculatedPriceByCurrencyRate($stock_price, $currency);

        return $calculatedPriceByCurrencyRate + $spread_value;
    }