Пример #1
0
class PortfolioView(FinPositionBase):
    name = orm.SymbolField()
    user = orm.SymbolField(required=False)
    portfolio = orm.ForeignKey(Portfolio, related_name='views')

    def __str__(self):
        return '%s: %s' % (self.portfolio, self.name)

    def customAttribute(self, name):
        return getattr(self.portfolio, name)

    def addfolder(self, name):
        '''Add folder for portfolio view. Self must have holder attribute available.'''
        return PortfolioViewFolder(name=name, view=self).save()

    def get_tree(self):
        return [p.alldata() for p in self.folders.all()]

    def isdefault(self, user):
        defaults = UserViewDefault.objects.filter(user=str(user),
                                                  portfolio=self.portfolio)
        if defaults:
            return defaults[0].view == self
        else:
            return False

    @property
    def dt(self):
        return self.portfolio.dt
Пример #2
0
class Base(orm.StdModel):
    name = orm.SymbolField(unique=True)
    ccy = orm.SymbolField()

    def __str__(self):
        return str(self.name)

    class Meta:
        abstract = True
Пример #3
0
class Calendar(orm.StdModel):
    name = orm.SymbolField(unique=True)
    data = orm.SetField(model=DateValue, ordered=True)

    def add(self, dt, value):
        event = DateValue(dt, value).save()
        self.data.add(event)
Пример #4
0
class PortfolioViewFolder(FinPositionBase):
    '''A Folder within a portfolio view'''
    name = orm.SymbolField()
    parent = orm.ForeignKey('self', required=False, related_name='children')
    view = orm.ForeignKey(PortfolioView,
                          required=False,
                          related_name='folders')
    positions = orm.SetField(Position)

    def get_tree(self):
        tree = [p.alldata() for p in self.children.all()]
        [tree.append(p.alldata()) for p in self.positions.all()]
        return tree

    @property
    def reference(self):
        if self.view:
            return self.view
        else:
            return self.parent

    @property
    def user(self):
        return self.reference.user

    @property
    def dt(self):
        return self.reference.dt
Пример #5
0
class PortfolioHolder(orm.StdModel):
    name = orm.SymbolField(unique=True)
    group = orm.SymbolField()
    ccy = orm.SymbolField()
    parent = orm.ForeignKey('self', required=False, related_name='children')

    def __init__(self, description='', **kwargs):
        super(PortfolioHolder, self).__init__(**kwargs)
        self.description = description

    def __str__(self):
        return self.name

    def root(self):
        '''Return Root Portfolio'''
        if self.parent:
            return self.parent.root()
        else:
            return self
Пример #6
0
class FinIns(orm.StdModel):
    '''Financial instrument base class. Contains a time-serie field.                
    '''
    code = orm.SymbolField(unique=True)
    firm_code = orm.SymbolField()
    curncy = orm.SymbolField()
    country = orm.SymbolField()
    type = orm.SymbolField(required=False)
    data = orm.ForeignKey(MktData)

    def __str__(self):
        return self.code

    def pv01(self):
        '''Present value of a basis point. This is a Fixed Income notation which we try to extrapolate to
        all financial instruments'''
        return 0

    def price_to_value(self, price, size, dt):
        raise NotImplementedError("Cannot convert price and size to value")
Пример #7
0
class MktData(orm.StdModel):
    code = orm.SymbolField(unique=True)
    vendors = orm.HashField(VendorTicker)

    def get_ticker_and_provider(self, field, provider, providers):
        '''Given a field a provider and a dictionary of available providers, return the best possible
match as 3 elements tuple (provider ticker, provider field, provider object)'''
        pass

    def __str__(self):
        return self.code
Пример #8
0
class User(orm.StdModel):
    '''A model for holding information about users'''
    username = orm.SymbolField(unique=True)
    password = orm.CharField(required=True)
    updates = orm.ListField(model=Post)
    following = orm.ManyToManyField(model='self', related_name='followers')

    def __str__(self):
        return self.username

    def newupdate(self, data):
        p = Post(data=data).save()
        #p  = Post(data = data, user = "******").save()
        self.updates.push_front(p)
        return p
Пример #9
0
class TestDateModel(orm.StdModel):
    name = orm.SymbolField()
    dt = orm.DateField()
Пример #10
0
class Dictionary(orm.StdModel):
    name = orm.SymbolField(unique=True)
    data = orm.HashField()
Пример #11
0
class SimpleModel(orm.StdModel):
    code = orm.SymbolField(unique=True)
Пример #12
0
class UserDefaultView(orm.StdModel):
    user = orm.SymbolField()
    view = orm.ForeignKey(PortfolioView)
Пример #13
0
class PortfolioView(orm.StdModel):
    name = orm.SymbolField()
    portfolio = orm.ForeignKey(Fund)
Пример #14
0
class Instrument(Base):
    type = orm.SymbolField()
Пример #15
0
class UserViewDefault(orm.StdModel):
    user = orm.SymbolField()
    portfolio = orm.ForeignKey(Portfolio, related_name='user_defaults')
    view = orm.ForeignKey(PortfolioView, related_name='user_defaults')
Пример #16
0
class VendorTicker(TimeSeries):
    code = orm.SymbolField(index=False)

    def __str__(self):
        return self.code