Investment Portfolio Sync #974
Reference in New Issue
Block a user
Delete Branch "zachgoll/trade-type"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is a backend-only PR that introduces the necessary models required to support investment portfolios and integrates these models into the
Account::Syncprocess.Overview
Below are a few important notes about the domain changes:
Mental model
An
Accountcan have variousAccount::Entrys.An
Account::Entrycan be either anAccount::Valuation,Account::Transaction, orAccount::Trade.Account::Valuation- sets the new account balance to the valuation amount (i.e. "the account is worth $X on Y date")Account::Transaction/Account::Trade- these are adjustments to the prior day balanceAn
Account::Balanceis a temporal value that represents the output of anAccount::Sync, which reads throughAccount::Entryrecords and modifies the balance according to the signage of the entry.An
Account::Holdingis also a temporal value that represents the output of anAccount::Syncwhen an account has relevantAccount::Tradeentries. A holding represents aqtyof aSecurityon a specific date for a specificAccount, which is worthamount, based on theSecurity::Priceandqtyfordate.Total Account Value
The total value of an
Accountis equal toAccount::Balance+SUM(Account::Holding)for a givendate.Account::Balancerepresents the "cash" balance of an account on a date, whileAccount::Holdings are summed up on a date to derive the "investment value" based on current daySecurity::Priceof each owned holding.Trade signage
In the Maybe app, when an
Account::Entryhas a negativeamount, this indicates an "inflow" to anAccount::Balanceand will increase the account balance. For example, a transaction withamountof -500 would affect different accounts as follows:For
Account::Tradetypes, there are two components ofamount:qty- a positive quantity represents a "buy", and a negativeqtyrepresents a "sell"price- this is always a positive amountTherefore, if a user "buys" 10 shares of AAPL at $200 per share, the amount with be positive (outflow):
amount= 10 * 200 = $2,000Consistent with the convention that "positive equals outflow", we can say that $2,000 flowed out of the "cash balance" of the account and into the "Holdings Value" of the account.