Exemplo n.º 1
0
Arquivo: models.py Projeto: smhjn/flow
class Depo(InstrumentInterface):
    curncy = models.CharField(max_length=3,
                              choices=geo.currency_tuples(),
                              verbose_name="currency")
    value_date = models.DateField()

    objects = managers.FwdCashManager()

    def description(self):
        return '%s Deposit: expiry %s' % (self.curncy, self.value_date)

    def name(self):
        return self.description()

    def ccy(self):
        return self.curncy

    def iscash(self):
        return True

    def make_position(self, **kwargs):
        return FACTORY.cash(inst=self, value_date=self.value_date, **kwargs)

    def metadata(self):
        return {'value_date': self.value_date}
Exemplo n.º 2
0
Arquivo: models.py Projeto: smhjn/flow
class EquityBase(Security):
    curncy = models.CharField(max_length=3,
                              choices=geo.currency_tuples(),
                              verbose_name="currency")
    multiplier = models.FloatField(default=1)
    settlement_delay = models.SmallIntegerField(default=2)

    class Meta:
        abstract = True

    def ccy(self):
        return self.curncy

    def sett_delay(self):
        return self.settlement_delay

    def isotc(self):
        return False

    def get_multiplier(self):
        return self.multiplier

    def metadata(self):
        data = super(EquityBase, self).metadata()
        data['settlement_delay'] = self.settlement_delay
        return data

    def infodict(self):
        df = settings.DATE_FORMAT
        r = super(Security, self).infodict()
        if self.ISIN:
            r['ISIN'] = self.ISIN
        if self.exchange:
            r['Exchange'] = self.exchange.code
        return r
Exemplo n.º 3
0
Arquivo: models.py Projeto: smhjn/flow
class FutureContract(models.Model):
    code = models.CharField(unique=True, max_length=12)
    curncy = models.CharField(max_length=3,
                              choices=geo.currency_tuples(),
                              verbose_name="currency")
    country = models.CharField(max_length=2, choices=geo.country_tuples())
    exchange = models.ForeignKey(Exchange, null=True, blank=True)
    description = models.CharField(max_length=60, blank=True)
    price_type = models.CharField(max_length=10,
                                  choices=Future_Price_Types,
                                  blank=True)
    index = models.ForeignKey(DataId, null=True, blank=True)
    expiry_months = models.CharField(max_length=24, blank=True)
    trading_unit = models.CharField(max_length=32, blank=True)
    tick_size = models.FloatField()
    tick_value = models.FloatField()
    ticket_cost = models.FloatField(default=0.0)
    term_structure = models.IntegerField(default=0)
    type = models.CharField(max_length=12, choices=future_type_choice)

    def __unicode__(self):
        return u'%s - %s' % (self.code, self.description)

    def tonotional(self, size):
        return self.tick_value * size / self.tick_size

    def blbcom(self):
        ac = str(self.asset_class.code)
        if ac == 'EQ':
            return 'Index'
        else:
            return 'Comdty'
Exemplo n.º 4
0
class Fund(models.Model):
    code = models.CharField(unique=True, max_length=10)
    firm_code = models.CharField(unique=True, max_length=50)
    description = models.CharField(max_length=255, blank=True)
    fund_holder = models.ForeignKey(FundHolder, verbose_name='team')
    curncy = models.CharField(max_length=3,
                              choices=geo.currency_tuples(),
                              verbose_name="currency")
    parent = models.ForeignKey('self', null=True, blank=True)
    dataid = models.ForeignKey('instdata.DataId',
                               blank=True,
                               null=True,
                               related_name='TheFundDataId')

    objects = FundManager()

    class Meta:
        app_label = current_app_label
        ordering = ('code', )

    def name(self):
        return self.description

    def get_description(self):
        return self.description

    def __unicode__(self):
        return u'%s' % self.code

    def ccy(self):
        return self.curncy

    def accounts(self):
        return CustodyAccount.objects.filter(fund=self)

    def portfolios(self, **kwargs):
        return Portfolio.objects.filter(fund=self, **kwargs)

    def defaultview(self):
        defo = self.portfolioview_set.filter(default=True)
        if defo.count():
            return defo[0]
        else:
            defo = self.portfolioview_set.all()
            if defo.count():
                defo = defo[0]
                defo.default = True
                defo.save()
                return defo
            else:
                p = PortfolioView(fund=self, default=True, code='default')
                p.save()
                return p

    def can_have_folders(self):
        return self.fund_set.all().count() == 0

    def rootfolders(self, view):
        return self.portfolio_set.filter(Q(view=view), Q(parent__isnull=True))
Exemplo n.º 5
0
Arquivo: models.py Projeto: smhjn/flow
class BondClass(models.Model):
    code = models.CharField(unique=True, max_length=12)
    curncy = models.CharField(max_length=3,
                              choices=geo.currency_tuples(),
                              verbose_name="currency")
    country = models.CharField(max_length=2, choices=geo.country_tuples())
    description = models.CharField(max_length=60, blank=True)
    price_type = models.CharField(max_length=10,
                                  choices=Future_Price_Types,
                                  blank=True)
    index = models.ForeignKey('DataId', null=True, blank=True)
    sovereign = models.BooleanField(default=False)
    convertible = models.BooleanField(default=False)
    bondcode = models.CharField(null=True, max_length=12)

    class Meta:
        verbose_name_plural = 'Bond Classes'
        ordering = ('code', )

    def fulldescription(self):
        return '%s bond. %s' % (self.description, self.coupon_type)

    def __unicode__(self):
        return self.code

    def settlement(self):
        return 'T + %s' % self.settlement_delay

    def issuer(self, dt=None):
        dt = dt or datetime.date.today()
        iss = self.issuers.filter(dt__lte=dt)
        if iss:
            return iss.latest().issuer
        else:
            iss = self.issuers.all()
            if iss:
                #TODO: this should not be latest, but the earliest!
                return iss.latest().issuer
            else:
                return None

    def add_issuer(self, issuer, dt=None):
        if not issuer:
            return
        dt = dt or datetime.date.today()
        old_issuer = self.issuer(dt)
        if old_issuer == issuer:
            return
        bi, created = BondIssuer.objects.get_or_create(dt=dt,
                                                       issuer=issuer,
                                                       bond_class=self)
        bi.save()

        return bi
Exemplo n.º 6
0
Arquivo: forms.py Projeto: smhjn/flow
class CashTradeForm(ManualTradeForm):
    currency = forms.ChoiceField(choices=geo.currency_tuples())

    layout = FormLayout(
        Fieldset('currency',
                 'fund',
                 'open_date',
                 'quantity',
                 css_class=inlineLabels))

    class Meta:
        fields = ['fund', 'open_date', 'quantity']

    def save(self, commit=True):
        if commit:
            dataid = Cash.objects.create(curncy=self.cleaned_data['currency'])
            self.instance.dataid = dataid
        return super(CashTradeForm, self).save(commit=commit)
Exemplo n.º 7
0
Arquivo: models.py Projeto: smhjn/flow
class Cash(InstrumentInterface):
    curncy = models.CharField(max_length=3,
                              choices=geo.currency_tuples(),
                              verbose_name="currency")
    cash_type = models.IntegerField(choices=cash_tuple(), default=1)
    extended = models.TextField(blank=True)

    objects = managers.CashManager()

    def codeinfo(self):
        return cash_codes.get(self.type, None)

    def has_firm_code(self):
        return False

    def name(self):
        return self.description()

    def description(self):
        ci = self.codeinfo()
        va = 'Cash %s' % self.curncy
        if ci:
            return '%s %s' % (va, ci['name'])
        else:
            return va

    class Meta:
        verbose_name = 'cash'
        verbose_name_plural = 'cash'

    def ccy(self):
        return self.curncy

    def iscash(self):
        return True

    def make_position(self, **kwargs):
        return FACTORY.cash(inst=self, **kwargs)

    def metadata(self):
        return {'cash_type': self.cash_type, 'extended': self.extended}