I would like to do a lot of analysis/performance/statistics on my stock portfolio, which I plan to track with my app. E.g.:
- Week performance
- Month performance
- Year performance
- Best performer
- and a lot of other things I can't imagine right now...
Where I'm struggling right now:
- What is a good/the best way to archive this? - Also to show this info on a dashboard
--> I think I should store this information somehow... But how to do this on a daily/weekly/whatever basis?
--> I don't see a way to do such things while runtime?
--> furthermore I need to know, when do do such thinks... It's end of the week so do weekly performance calculations...
--> Maybe there is also an MVP solution, that can evolve into a top-notch solution?
My models are locking like this at the moment - The position is the clamp around my orders and my EOD data. Right now I'm working with yfinance to get range financial data + finnhub API to get real time prices:
class Position(models.Model):
name = models.CharField(max_length=100)
shares = models.FloatField(default=0.0)
symbol = models.CharField(max_length=100, default="")
transaction_fee_sum = models.FloatField(default=0.0)
profit = models.FloatField(default=0.0)
average_price = models.FloatField(default=0.0)
cost_value = models.FloatField(default=0.0)
last_price = models.FloatField(default=0.0)
position_value = models.FloatField(default=0.0)
last_update = models.DateTimeField(default=datetime.now(), blank=True)
position_started = models.DateTimeField(default=datetime.now(), blank=True)
position_ended = models.DateTimeField(default=datetime.now(), blank=True)
isin = models.CharField(max_length=12)
depot = models.ForeignKey("Depot", blank=True, null=True, on_delete=models.SET_NULL)
def __str__(self):
return self.name
class PriceHistoryEOD(models.Model):
price = models.DecimalField(max_digits=8, decimal_places=2)
position = models.ForeignKey("Position", blank=True, null=True, on_delete=models.CASCADE)
price_date = models.DateField(default=date.today)
class Inventory_Position(models.Model):
shares = models.FloatField(default=0.0)
price = models.FloatField(default=0.0)
position = models.ForeignKey("Position", blank=True, null=True, on_delete=models.CASCADE)
def __str__(self):
return str(self.position.name) + "_Inventory_" + str(self.id)
class Order(models.Model):
ORDER_PLACES = (
('TRADEGATE', 'Tradegate'),
('FRANKFURT', 'Frankfurt'),
('STUTTGART', 'Stuttgart'),
)
ORDER_TYPE = (
('buy', 'buy'),
('sell', 'sell'),
)
name = models.CharField(max_length=100)
depot = models.ForeignKey("Depot", blank=True, null=True, on_delete=models.SET_NULL)
position = models.ForeignKey("Position", blank=True, null=True, on_delete=models.SET_NULL)
ko_identifier = models.BooleanField()
order_price = models.FloatField()
quantity = models.FloatField()
order_value = models.FloatField()
order_fees = models.DecimalField(decimal_places=2,max_digits=5,default=0.0, null=True)
order_date = models.DateTimeField('order date')
order_wkn = models.CharField(max_length=6)
order_isin = models.CharField(max_length=12)
order_TYPE = models.CharField(max_length=100, choices=ORDER_TYPE)
order_place = models.CharField(max_length=100, choices=ORDER_PLACES)
def __str__(self):
return self.name