Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 def remove_one_item(self, recommendations, asset_type, allSecurities):
     stocks_alloc, bonds_alloc = self.current_allocation(allSecurities)
     if (asset_type == 'Equity' or asset_type == 'equity'
             or asset_type == 'stock'):
         if stocks_alloc == 0:
             print("You have no stocks to delete")
         else:
             pop = recom.reverse_recommend_stock(recommendations)
             security = next(pop)
             while not self.check_security_in_portfolio(
                     self.portfolio, security):
                 security = next(pop)
             self.deleteSecurity(security, allSecurities)
             print("You now have {} % exposure in CASH.".format(
                 self.extra_exposure))
     elif (asset_type == 'Bond' or asset_type == 'bond'):
         if bonds_alloc == 0:
             print("You have no bonds to delete")
         else:
             recommendations = recom.rank_etfs()
             pop = recom.reverse_recommend_stock(recommendations)
             security = next(pop)
             while not self.check_security_in_portfolio(
                     self.portfolio, security):
                 security = next(pop)
             self.deleteSecurity(security, allSecurities)
             print("You now have {} % exposure in CASH.".format(
                 self.extra_exposure))
Ejemplo n.º 3
0
 def removeBondsToBalance(self,
                          security_dict,
                          bonds_alloc,
                          recommended_bonds_alloc,
                          exposure=True):
     recommendations = recom.rank_etfs()
     pop = recom.reversed_recommend_etf(recommendations)
     while (bonds_alloc > recommended_bonds_alloc):
         security = next(pop)
         while (not self.check_security_in_portfolio(
                 self.portfolio, security)):
             security = next(pop)
         security_exposure = self.portfolio[security]
         if (exposure):
             fit_exposure = min(security_exposure,
                                bonds_alloc - recommended_bonds_alloc)
         else:
             fit_exposure = bonds_alloc - recommended_bonds_alloc
         if (fit_exposure <= security_exposure):
             # delete dictionary entry
             self.deleteSecurity(security, security_dict)
             bonds_alloc -= security_exposure
         elif (fit_exposure < security_exposure):
             # delete some of the shares
             self.setExposure(security, security_exposure - fit_exposure)
             bonds_alloc -= fit_exposure
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 def removeBondsToBalance(self, security_dict, bonds_alloc,
                          recommended_bonds_alloc):
     recommendations = recom.rank_etfs('Mid')
     pop = recom.reversed_recommend_etf(recommendations)
     while (bonds_alloc > recommended_bonds_alloc):
         security = next(pop)
         while (not ut.check_security_in_portfolio(self.portfolio,
                                                   security)):
             security = next(pop)
         security_exposure = self.portfolio[security] * security_dict[
             security]['Price'] / self.client['Capital'] * 100
         fit_exposure = min(security_exposure,
                            bonds_alloc - recommended_bonds_alloc)
         if (fit_exposure == security_exposure):
             # delete dictionary entry
             self.deteleSecurity(security)
             bonds_alloc -= fit_exposure
         elif (fit_exposure < security_exposure):
             # delete some of the shares
             shares_to_delete = fit_exposure / 100 * self.client[
                 'Capital'] / security_dict[security]['Price']
             self.deleteSharesFromSecurity(shares_to_delete, security)
             bonds_alloc -= fit_exposure