summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2021-08-17 20:25:33 -0400
committerluxagraf <sng@luxagraf.net>2021-08-17 20:25:33 -0400
commit9a4c84cdcfcc33308e1092ad2464a81c29b84eb2 (patch)
tree10b3940747945d3937c06a12fbc9d86b2a59717e /app
parentc3907cd3e61161a264ab0daf6b26262a40876393 (diff)
trad: fixed all the profit loss calcs for puts
Diffstat (limited to 'app')
-rw-r--r--app/trading/migrations/0016_alter_luxoptionstrade_pl.py18
-rw-r--r--app/trading/models.py21
2 files changed, 32 insertions, 7 deletions
diff --git a/app/trading/migrations/0016_alter_luxoptionstrade_pl.py b/app/trading/migrations/0016_alter_luxoptionstrade_pl.py
new file mode 100644
index 0000000..4ee6523
--- /dev/null
+++ b/app/trading/migrations/0016_alter_luxoptionstrade_pl.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.5 on 2021-08-15 18:55
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('trading', '0015_auto_20210727_1141'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='luxoptionstrade',
+ name='pl',
+ field=models.FloatField(blank=True, null=True),
+ ),
+ ]
diff --git a/app/trading/models.py b/app/trading/models.py
index 2a71fb3..ad40c98 100644
--- a/app/trading/models.py
+++ b/app/trading/models.py
@@ -23,7 +23,6 @@ def get_upload_path(self, filename):
return "images/products/%s" % (filename)
-
class Ticker(models.Model):
symbol = models.CharField(max_length=9)
name = models.CharField(max_length=243, blank=True, null=True)
@@ -251,16 +250,18 @@ class LuxOptionsTrade(models.Model):
@property
def risk_per_contract(self):
- return round(((self.entry_price-self.stop_price)*self.delta/self.contract_price)*self.contract_price*100, 2)
-
+ if self.call_put == 0:
+ return round(((self.entry_price-self.stop_price)*self.delta/self.contract_price)*self.contract_price*100, 2)
+ else:
+ return round(((self.stop_price-self.entry_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):
- if self.call_put == 0:
- return round((self.target_price-self.entry_price)/(self.entry_price-self.stop_price), 2);
+ return round((self.target_price-self.entry_price)/(self.entry_price-self.stop_price), 2);
@property
def amount_invested(self):
@@ -269,7 +270,9 @@ class LuxOptionsTrade(models.Model):
@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)
+ return round((((self.target_price-(self.strike_price+self.contract_price))*100)*self.number_contracts)-self.fees, 2)
+ else:
+ return round((((self.strike_price-self.target_price)*self.number_contracts)*100)-self.fees, 2)
@property
def days_until_expiration(self):
@@ -278,7 +281,11 @@ class LuxOptionsTrade(models.Model):
@property
def realized_dollars(self):
- return round((((self.contract_close_price*self.number_contracts)*100) - ((self.contract_price*self.number_contracts)*100)-self.fees), 2)
+ if self.call_put == 0:
+ return round((((self.contract_close_price*self.number_contracts)*100) - ((self.contract_price*self.number_contracts)*100)-self.fees), 2)
+ else:
+ return round((((self.contract_price*self.number_contracts)*100)-((self.contract_close_price*self.number_contracts)*100)-self.fees), 2)
+
@property
def realized_percent(self):