def subscribe_funds(self, dt, amount): """ Credit funds to the portfolio. """ if dt < self.current_dt: raise ValueError('Subscription datetime (%s) is earlier than ' 'current portfolio datetime (%s). Cannot ' 'subscribe funds.' % (dt, self.current_dt)) self.current_dt = dt if amount < 0.0: raise ValueError('Cannot credit negative amount: ' '%s to the portfolio.' % amount) cash_position = self.pos_handler.positions[self.cash_position_key] new_quantity = cash_position.quantity + amount self.pos_handler.update_position(self.cash_position_key, quantity=new_quantity, current_dt=self.current_dt) self.history.append( PortfolioEvent.create_subscription(self.current_dt, amount, self.total_cash)) self.logger.info( '(%s) Funds subscribed to portfolio "%s" ' '- Credit: %0.2f, Balance: %0.2f' % (self.current_dt.strftime(settings.LOGGING["DATE_FORMAT"]), self.portfolio_id, round(amount, 2), round(self.total_cash, 2)))
def _initialise_portfolio_with_cash(self): """ Initialise the portfolio with a (default) currency Cash Asset with quantity equal to 'starting_cash'. """ self.cash = copy.copy(self.starting_cash) if self.starting_cash > 0.0: self.history.append( PortfolioEvent.create_subscription(self.current_dt, self.starting_cash, self.starting_cash)) self.logger.info( '(%s) Funds subscribed to portfolio "%s" ' '- Credit: %0.2f, Balance: %0.2f' % (self.current_dt.strftime( settings.LOGGING["DATE_FORMAT"]), self.portfolio_id, round(self.starting_cash, 2), round(self.starting_cash, 2)))
def _initialise_portfolio_with_cash(self): self.cash = copy.copy(self.starting_cash) if self.starting_cash > 0.0: self.history.append( PortfolioEvent.create_subscription( self.current_k, self.starting_cash, self.starting_cash ) ) self.logger.info( '(%s) Funds subscribed to portfolio "%s" ' '- Credit: %0.2f, Balance: %0.2f' % ( self.current_k, # self.current_k.strftime(settings.LOGGING["DATE_FORMAT"]), self.portfolio_id, round(self.starting_cash, 2), round(self.starting_cash, 2) ) )
def _initialise_portfolio_with_cash(self): """ Initialise the portfolio with a (default) currency Cash Asset with quantity equal to 'starting_cash'. """ cash_position = Position(self.cash_position_key, self.starting_cash, book_cost_pu=1.0, current_price=1.0, current_dt=self.current_dt) self.pos_handler.positions[self.cash_position_key] = cash_position if self.starting_cash > 0.0: self.history.append( PortfolioEvent.create_subscription(self.current_dt, self.starting_cash, self.starting_cash)) self.logger.info( '(%s) Funds subscribed to portfolio "%s" ' '- Credit: %0.2f, Balance: %0.2f' % (self.current_dt.strftime( settings.LOGGING["DATE_FORMAT"]), self.portfolio_id, round(self.starting_cash, 2), round(self.starting_cash, 2)))