diff options
Diffstat (limited to 'app/trading/models.py')
-rw-r--r-- | app/trading/models.py | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/app/trading/models.py b/app/trading/models.py index f0f332c..212d196 100644 --- a/app/trading/models.py +++ b/app/trading/models.py @@ -205,6 +205,77 @@ class LuxOptionsTradeStatsManager(models.Manager): return self.filter(close_date__range=(start_date, end_date)).aggregate(Sum('pl')) +class LuxOptionPurchase(models.Model): + symbol = models.CharField(max_length=256) + open_date = models.DateTimeField(auto_now_add=True) + close_date = models.DateTimeField(null=True, blank=True) + pl = models.FloatField(null=True, blank=True) + STATUS = ( + (0, 'Open'), + (1, 'Closed'), + ) + status = models.IntegerField(choices=STATUS, default=1) + + class Meta: + ordering = ('-open_date',) + get_latest_by = 'open_date' + + def __str__(self): + return str(self.symbol) + + def get_contract_count(self): + return self.luxoptioncontact_set.count() + + @property + def stop_price(self): + return (self.contract_price*.75) + + @property + def total_invested(self): + return round(self.get_contract_count()*(self.luxoptioncontact_set.first().contract_open_price*100)) + + @property + def trade_risk(self): + return round(self.total_invested*.25) + + @property + def portfolio_risk(self): + return (self.trade_risk/10000)*100 + + @property + def sell_half_at(self): + return self.luxoptioncontact_set.first().contract_open_price*1.25 + + @property + def contract_price(self): + return self.luxoptioncontact_set.first().contract_open_price + + def save(self, *args, **kwargs): + if self.status == 1 and not self.close_date: + self.close_date = timezone.now() + if self.status == 1 and not self.pl: + pass + #self.pl = round((self.close_price*self.shares)-(self.entry_price*self.shares), 2) + super(LuxOptionPurchase, self).save() + + +class LuxOptionContact(models.Model): + symbol = models.CharField(max_length=256) + strike_price = models.FloatField() + expiration_date = models.DateField() + contract_open_price = models.FloatField() + contract_close_price = models.FloatField(null=True, blank=True) + CALL_PUT = ( + (0, 'Calls'), + (1, 'Puts'), + ) + call_put = models.IntegerField(choices=CALL_PUT, default=0) + options_purchase = models.ForeignKey(LuxOptionPurchase, null=True, on_delete=models.SET_NULL) + + def __str__(self): + return "%s - %s %s" %(self.symbol, round(self.strike_price), self.get_call_put_display()) + + class LuxOptionsTrade(models.Model): symbol = models.CharField(max_length=256) date = models.DateTimeField(auto_now_add=True) @@ -322,8 +393,6 @@ class LuxOptionsTrade(models.Model): super(LuxOptionsTrade, self).save() - - class TradeJrnl(models.Model): date = models.DateTimeField(auto_now_add=True) body_markdown = models.TextField(blank=True) |