Example #1
0
class StockReport(Report):
    def __init__(self, dao, date):
        super(self.__class__, self).__init__(dao, date)
        self.q = dao.get_stock_quote(date)
        self.stock_position = CalcPosition(date)
        self.stock_position.calc(dao)

    def stock_positions(self, positions=None):
        def calc_stock(instrument, position):
            v = position.shares * self.q[instrument].price
            r = {}
            r['instrument'] = instrument
            r['url'] = self.i[instrument].url
            r['symbol'] = position.name
            r['shares'] = position.shares
            r['price'] = self.q[instrument].price
            r['value'] = self.gen_price_with_xccy(v, self.i[instrument].currency, self.i[instrument].xccy_rate,
                                                  self.i[instrument].xccy_date)
            r['liquidated'] = self.gen_price_with_xccy(position.liquidated, self.i[instrument].currency,
                                                       self.i[instrument].xccy_rate, self.i[instrument].xccy_date)

            t = self.i[instrument].instrument_type.name
            if t in positions:
                by_instrument = positions[t]
            else:
                by_instrument = []

            by_instrument.append(r)
            positions[t] = by_instrument

        if positions is None:
            positions = {}
        self.stock_position.dump(calc_stock)
        return positions
Example #2
0
 def __init__(self, dao, date):
     super(self.__class__, self).__init__(dao, date)
     self.q = dao.get_stock_quote(date)
     self.stock_position = CalcPosition(date)
     self.stock_position.calc(dao)