def addBondsToBalance(self, security_dict, bonds_alloc, recommended_bonds_alloc, exposure_threshold=0.05): recommendations = recom.rank_etfs() pop = recom.recommend_etf(recommendations) while (bonds_alloc < recommended_bonds_alloc): # get a recommendation security = next(pop) print('Checking if bond {} exists in portfolio'.format(security)) # check if the recommended security is in the portfolio already and get the second best if it is while ut.check_security_in_portfolio(self.portfolio, security): print('Bond {} exists in portfolio'.format(security)) security = next(pop) print( 'Checking if bond {} exists in portfolio'.format(security)) # desired exposure fit_exposure = min(exposure_threshold, (recommended_bonds_alloc - bonds_alloc) / 100) # calculated desired shares to fit 0.05 exposure shares = fit_exposure * self.client['Capital'] / security_dict[ security]['Price'] current_exposure = shares * security_dict[security][ 'Price'] / self.client['Capital'] # add shares to portfolio self.addNewSecurity(security, shares) # increase bond allocation bonds_alloc += current_exposure * 100
def addBondsToBalance(self, security_dict, bonds_alloc, recommended_bonds_alloc, exposure=True, exposure_threshold=5): recommendations = recom.rank_etfs() pop = recom.recommend_etf(recommendations) while (bonds_alloc < recommended_bonds_alloc): # get a recommendation security = next(pop) print('Checking if bond {} exists in portfolio'.format(security)) # check if the recommended security is in the portfolio already and get the second best if it is while self.check_security_in_portfolio(self.portfolio, security): print('Bond {} exists in portfolio'.format(security)) security = next(pop) print( 'Checking if bond {} exists in portfolio'.format(security)) # desired exposure if (exposure): fit_exposure = min(exposure_threshold, (recommended_bonds_alloc - bonds_alloc)) else: fit_exposure = recommended_bonds_alloc - bonds_alloc # add shares to portfolio self.addNewSecurity(security, fit_exposure, security_dict) # increase bond allocation bonds_alloc += fit_exposure
def buy_bonds(self, budget, allSecurities): recommendations = recom.rank_etfs() pop = recom.recommend_etf(recommendations) security = next(pop) print('Checking if bond {} exists in portfolio'.format(security)) while self.check_security_in_portfolio(self.portfolio, security): print('Bond {} exists in portfolio'.format(security)) security = next(pop) self.addNewSecurity(security, budget, allSecurities)
def addBondsToBalance(self, security_dict, bonds_alloc, recommended_bonds_alloc, bonds_preferences, exposure=True, exposure_threshold=5): pop = recom.recommend_etf(bonds_preferences) while (bonds_alloc < recommended_bonds_alloc): security = next(pop) print('Checking if bond {} exists in portfolio'.format(security)) while self.security_exists_in_portfolio(self.portfolio, security): print('Bond {} exists in portfolio'.format(security)) security = next(pop) print( 'Checking if bond {} exists in portfolio'.format(security)) if (exposure): fit_exposure = min(exposure_threshold, (recommended_bonds_alloc - bonds_alloc)) else: fit_exposure = recommended_bonds_alloc - bonds_alloc self.addNewSecurity(security, fit_exposure, security_dict) bonds_alloc += fit_exposure