def create(self, test, use_transaction = True): session = test.session() if use_transaction: with session.begin(): for name,typ,ccy in zip(self.inst_names,self.inst_types,\ self.inst_ccys): session.add(Instrument(name = name, type = typ, ccy = ccy)) for name,ccy in zip(self.fund_names,self.fund_ccys): session.add(Fund(name = name, ccy = ccy)) else: self.register() for name,typ,ccy in zip(self.inst_names,self.inst_types,\ self.inst_ccys): Instrument(name = name, type = typ, ccy = ccy).save() for name,ccy in zip(self.fund_names,self.fund_ccys): Fund(name = name, ccy = ccy).save() self.num_insts = session.query(Instrument).count() self.num_funds = session.query(Fund).count()
def makePositions(self, test, use_transaction = True): self.create(test, use_transaction) session = test.session() instruments = session.query(Instrument).all() if use_transaction: with session.begin(): for f in session.query(Fund): insts = populate('choice', self.pos_len, choice_from = instruments) for dt in self.dates: for inst in insts: session.add(Position(instrument = inst, dt = dt, fund = f)) else: for f in Fund.objects.query(Fund): insts = populate('choice', self.pos_len, choice_from = instruments) for dt in self.dates: for inst in insts: Position(instrument = inst, dt = dt, fund = f).save() self.num_pos = session.query(Position).count()