If there are losses for a stock in a month, add fund for the loss portion to buy the stock to bring the investment to the stock back to the fixed amount for the next month. ''' if __name__=='__main__': industry_name="Electronic Equipment & Instruments" industry_code="452030" con = sqlite3.connect('qse_test.db') security_data = SecurityData(con) account_manager = AccountManager(con) account_metrics = AccountMetrics(con) dates = security_data.get_dates() stock_ids=security_data.get_security() stock_info=security_data.get_company_info(stock_ids, ['ticker', 'company_name', 'gics_code', 'gics_name']) new_id=account_manager.new_account() #print new_id industry_ids=[] for i in range(len(stock_ids)): if stock_info[i][2]==industry_code: industry_ids.append(stock_ids[i]) if len(industry_ids)<1: print("The database contains no stocks in the sector: %s" %industry_name) print "...The target stock ids..." pprint(industry_ids) print