Add Data Models
144
Data-Models.md
Normal file
144
Data-Models.md
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
<html><head></head><body><h1>Data Models</h1>
|
||||||
|
<h2>Portfolio</h2>
|
||||||
|
<h3><code>Position</code></h3>
|
||||||
|
<p>Represents the current holding for a single symbol, derived by aggregating trades.</p>
|
||||||
|
<pre><code class="language-go">type Position struct {
|
||||||
|
CompanyID int
|
||||||
|
Symbol string
|
||||||
|
CurrencyCode string
|
||||||
|
CurrencyID int
|
||||||
|
Weight float64
|
||||||
|
CostBasis float64
|
||||||
|
Shares int
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h3><code>Trade</code></h3>
|
||||||
|
<p>A single executed trade.</p>
|
||||||
|
<pre><code class="language-go">type Trade struct {
|
||||||
|
Symbol string
|
||||||
|
CurrencyCode string
|
||||||
|
Shares int
|
||||||
|
Product TradeProduct
|
||||||
|
Type TradeType
|
||||||
|
Price float64
|
||||||
|
Date time.Time
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h3><code>TradeProduct</code> (int enum)</h3>
|
||||||
|
|
||||||
|
Value | Constant
|
||||||
|
-- | --
|
||||||
|
0 | StockTrade
|
||||||
|
1 | OptionCallTrade
|
||||||
|
2 | OptionPutTrade
|
||||||
|
3 | CurrencyTrade
|
||||||
|
4 | BondTrade
|
||||||
|
|
||||||
|
|
||||||
|
<h3><code>Portfolio</code></h3>
|
||||||
|
<p>Top-level aggregate — currently only stock positions are supported.</p>
|
||||||
|
<pre><code class="language-go">type Portfolio struct {
|
||||||
|
Positions []Position
|
||||||
|
Trades []Trade
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<hr>
|
||||||
|
<h2>Company</h2>
|
||||||
|
<pre><code class="language-go">type Company struct {
|
||||||
|
ID int
|
||||||
|
Name string
|
||||||
|
SharesOutstanding int
|
||||||
|
Price float64
|
||||||
|
CurrencyID int
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<hr>
|
||||||
|
<h2>Currency</h2>
|
||||||
|
<pre><code class="language-go">type Currency struct {
|
||||||
|
ID int
|
||||||
|
Code string
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<hr>
|
||||||
|
<h2>Period</h2>
|
||||||
|
<p>Periods are created automatically when revenue entries are added.</p>
|
||||||
|
<pre><code class="language-go">type Period struct {
|
||||||
|
ID int
|
||||||
|
Type string // "Q", "H", or "Y"
|
||||||
|
Year int
|
||||||
|
Index int
|
||||||
|
StartDate time.Time
|
||||||
|
EndDate time.Time
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<p>Helper constructors: <code>QuarterPeriod</code>, <code>HalfYearPeriod</code>, <code>FullYearPeriod</code>.</p>
|
||||||
|
<hr>
|
||||||
|
<h2>Revenue</h2>
|
||||||
|
<pre><code class="language-go">type RevenueEntry struct {
|
||||||
|
ID int
|
||||||
|
ReportID int
|
||||||
|
CurrencyID int
|
||||||
|
Category string
|
||||||
|
Label string
|
||||||
|
Value float64
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<hr>
|
||||||
|
<h2>Database Schema</h2>
|
||||||
|
<pre><code class="language-sql">CREATE TABLE currencies (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
code TEXT NOT NULL UNIQUE,
|
||||||
|
name TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE companies (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL UNIQUE,
|
||||||
|
shares_outstanding INTEGER NOT NULL,
|
||||||
|
price REAL NOT NULL,
|
||||||
|
currency_id INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY (currency_id) REFERENCES currencies(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE periods (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
type TEXT NOT NULL CHECK(type IN ('Q', 'H', 'Y')),
|
||||||
|
year INTEGER NOT NULL,
|
||||||
|
idx INTEGER NOT NULL,
|
||||||
|
start_date TEXT NOT NULL,
|
||||||
|
end_date TEXT NOT NULL,
|
||||||
|
UNIQUE(type, year, idx)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE revenue_reports (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
company_id INTEGER NOT NULL,
|
||||||
|
period_id INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY (company_id) REFERENCES companies(id),
|
||||||
|
FOREIGN KEY (period_id) REFERENCES periods(id),
|
||||||
|
UNIQUE(company_id, period_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE revenue_entries (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
report_id INTEGER NOT NULL,
|
||||||
|
currency_id INTEGER NOT NULL,
|
||||||
|
category TEXT NOT NULL,
|
||||||
|
label TEXT NOT NULL,
|
||||||
|
value REAL NOT NULL,
|
||||||
|
FOREIGN KEY (report_id) REFERENCES revenue_reports(id),
|
||||||
|
FOREIGN KEY (currency_id) REFERENCES currencies(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE trades (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
company_id INTEGER NOT NULL,
|
||||||
|
currency_id INTEGER NOT NULL,
|
||||||
|
shares INTEGER NOT NULL,
|
||||||
|
product INTEGER NOT NULL CHECK(product IN (0, 1, 2, 3)),
|
||||||
|
type INTEGER NOT NULL CHECK(type IN (0, 1)),
|
||||||
|
price REAL NOT NULL,
|
||||||
|
traded_at DATETIME NOT NULL
|
||||||
|
);
|
||||||
|
</code></pre></body></html>
|
||||||
Reference in New Issue
Block a user