def reset_app(): ''' Deletes all portfolios and respective holdings that are of type 'user_portfolio', 'benchmark', and 'root' (instrument universe) ''' portfolios = investmentportfolio.Get_Portfolios_by_Selector('type','user_portfolio')['portfolios'] portfolios += investmentportfolio.Get_Portfolios_by_Selector('type','benchmark')['portfolios'] portfolios += investmentportfolio.Get_Portfolios_by_Selector('type','root')['portfolios'] for p in portfolios: holdings = investmentportfolio.Get_Portfolio_Holdings(p['name'],False) # delete all holdings for h in holdings['holdings']: timestamp = h['timestamp'] rev = h['_rev'] investmentportfolio.Delete_Portfolio_Holdings(p['name'],timestamp,rev) investmentportfolio.Delete_Portfolio(p['name'],p['timestamp'],p['_rev']) return "Portfolios deleted successfully."
def get_unit_test_delete(): ''' Deletes all portfolios and respective holdings that are of type 'unit test' ''' portfolios = investmentportfolio.Get_Portfolios_by_Selector('type','unit test portfolio')['portfolios'] print(portfolios) for p in portfolios: holdings = investmentportfolio.Get_Portfolio_Holdings(p['name'],False) # delete all holdings for h in holdings['holdings']: timestamp = h['timestamp'] rev = h['_rev'] investmentportfolio.Delete_Portfolio_Holdings(p['name'],timestamp,rev) investmentportfolio.Delete_Portfolio(p['name'],p['timestamp'],p['_rev']) return "Portfolios deleted successfully."
def get_unit_test_portfolios(): ''' Returns the available user portfolio names in the Investment Portfolio service. Uses type='user_portfolio' to specify. ''' portfolio_names = [] res = investmentportfolio.Get_Portfolios_by_Selector('type','unit test portfolio') try: for portfolios in res['portfolios']: portfolio_names.append(portfolios['name']) #returns the portfolio names as list print("Portfolio_names:" + str(portfolio_names)) return json.dumps(portfolio_names) except: return "No portfolios found."
def get_look_through_portfolios(): ''' Returns the available user portfolio names in the Investment Portfolio service. Uses type='user_portfolio' to specify. ''' portfolio_names = [] res = investmentportfolio.Get_Portfolios_by_Selector('type','User Portfolio') #Filters out look-through portfolios try: for portfolios in res['portfolios']: portfolio_names.append(portfolios['name']) #returns the portfolio names as list print("Portfolio_names:" + str(portfolio_names)) return Response(json.dumps(portfolio_names), mimetype='application/json') except: return "No portfolios found."
def get_benchmark_list(): ''' Returns the available benchmark portfolio names in the Investment Portfolio service. Uses type='bechmark' to specify. ''' names = [] res = investmentportfolio.Get_Portfolios_by_Selector('type','benchmark') p = json.loads(json.dumps(res)) try: for b in p['portfolios']: names.append(b['name']) #Gather only unique names, as there's likely history for the benchmarks. names = list(set(names)) return names except: return names