summaryrefslogtreecommitdiff
path: root/app/trading/models.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2021-07-20 21:49:09 -0400
committerluxagraf <sng@luxagraf.net>2021-07-20 21:49:09 -0400
commit4e64ac45ad91b79b9fc0cd80abab51fc50e8be76 (patch)
tree0f84543e0d7eb538dbd47ca45cd3b340704a5e7f /app/trading/models.py
parent538481a01b39a73f1590cf9910b3c884270bd204 (diff)
trad: added options tracking and calculator
Diffstat (limited to 'app/trading/models.py')
-rw-r--r--app/trading/models.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/app/trading/models.py b/app/trading/models.py
index 75476fd..551a4de 100644
--- a/app/trading/models.py
+++ b/app/trading/models.py
@@ -127,6 +127,10 @@ class LuxTrade(models.Model):
is_wanderer = models.BooleanField(default=True)
pl = models.FloatField(null=True)
+ class Meta:
+ ordering = ('-open_date',)
+ get_latest_by = 'open_date'
+
def __str__(self):
return str(self.symbol)
@@ -179,6 +183,87 @@ class LuxTrade(models.Model):
self.pl = round((self.close_price*self.shares)-(self.entry_price*self.shares), 2)
super(LuxTrade, self).save()
+
+class LuxOptionsTrade(models.Model):
+ symbol = models.CharField(max_length=256)
+ date = models.DateTimeField(auto_now_add=True)
+ close_date = models.DateTimeField(null=True, blank=True)
+ open_date = models.DateTimeField(null=True, blank=True)
+ entry_price = models.FloatField()
+ stop_price = models.FloatField()
+ target_price = models.FloatField()
+ strike_price = models.FloatField()
+ CALL_PUT = (
+ (0, 'Call'),
+ (1, 'Put'),
+ )
+ call_put = models.IntegerField(choices=CALL_PUT, default=2)
+ contract_price = models.FloatField()
+ number_contracts = models.FloatField()
+ delta = models.FloatField()
+ expiration_date = models.DateField()
+
+ fees = models.FloatField(blank=True)
+ STATUS = (
+ (0, 'Open'),
+ (1, 'Closed'),
+ (2, 'Watching'),
+ )
+ status = models.IntegerField(choices=STATUS, default=2)
+ notes = models.TextField(null=True, blank=True)
+ pl = models.FloatField(null=True)
+
+ class Meta:
+ ordering = ('-open_date',)
+ get_latest_by = 'open_date'
+
+ def __str__(self):
+ return str(self.symbol)
+
+ def get_absolute_url(self):
+ return reverse('luxtrade:optiondetail', kwargs={"pk": self.pk})
+
+ @property
+ def risk_per_contract(self):
+ return round(((self.entry_price-self.stop_price)*self.delta/self.contract_price)*self.contract_price*100, 2)
+
+ @property
+ def risk_total(self):
+ return round(self.risk_per_contract*self.number_contracts, 2)
+
+ @property
+ def risk_reward(self):
+ return round((self.target_price-self.entry_price)/(self.entry_price-self.stop_price), 2);
+
+ @property
+ def amount_invested(self):
+ return round(((self.contract_price * self.number_contracts)*100)+self.fees, 2)
+
+ @property
+ def profit_goal(self):
+ if self.call_put == 0:
+ return round((((self.target_price-(self.strike_price+self.contract_price))*100)*self.number_contracts)-self.fees, 3)
+
+ @property
+ def days_until_expiration(self):
+ td = self.expiration_date - datetime.date.today()
+ return td.days
+
+ def save(self, *args, **kwargs):
+ if self.status == 0 and not self.open_date:
+ self.open_date = timezone.now()
+ if self.number_contracts < 10:
+ self.fees = self.number_contracts + (.14*self.number_contracts)
+ else:
+ self.fees = 10 + (.14*self.number_contracts)
+ if self.status == 1 and not self.close_date:
+ self.close_date = timezone.now()
+ if self.status == 1 and not self.pl:
+ self.pl = 0 #round((self.close_price*self.shares)-(self.entry_price*self.shares), 2)
+ super(LuxOptionsTrade, self).save()
+
+
+
class TradeJrnl(models.Model):
date = models.DateTimeField(auto_now_add=True)