boglehead/portfolio.py
def buy(self, buy_value):
        """Buy `value` from assets in a rebalanced way"""
        self.rebalance()
        current_value = self.value()
        if buy_value < 0:
            raise ValueError("can't buy negative, silly")
        buy_ratio = (buy_value + current_value) / current_value
        for fund in self.funds:
            fund.units *= buy_ratio
        if abs(self.value() - (current_value + buy_value)) > EPSILON:
            raise ValueError("#buyfail")
        return self.value()
Buy `value` from assets in a rebalanced way
Buy `value` from assets in a rebalanced way
Buy ` value ` from assets in a rebalanced way
def buy(self, buy_value):
        self.rebalance()
        current_value = self.value()
        if buy_value < 0:
            raise ValueError("can't buy negative, silly")
        buy_ratio = (buy_value + current_value) / current_value
        for fund in self.funds:
            fund.units *= buy_ratio
        if abs(self.value() - (current_value + buy_value)) > EPSILON:
            raise ValueError("#buyfail")
        return self.value()
def buy ( self , buy_value ) : self . rebalance ( ) current_value = self . value ( ) if buy_value < 0 : raise ValueError ( "can't buy negative, silly" ) buy_ratio = ( buy_value + current_value ) / current_value for fund in self . funds : fund . units *= buy_ratio if abs ( self . value ( ) - ( current_value + buy_value ) ) > EPSILON : raise ValueError ( "#buyfail" ) return self . value ( )
Buy `value` from assets in a rebalanced way
Buy ` value ` from assets in a rebalanced way
"""Buy `value` from assets in a rebalanced way"""
self
buy_value