Swiftpack.co -  openalloc/AllocData as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
openalloc/AllocData
Data Model for Financial Applications
.package(url: "https://github.com/openalloc/AllocData.git", from: "1.0.6")

AllocData

An open data model for financial applications, typically those used by the do-it-yourself investor.

Entities

The following entities are defined in the AllocData data model.

MAccount

This is the ‘openalloc/account’ schema.

Each row of the Accounts table describes a unique account.

Name Type IsRequired IsKey Descript
accountID string true true The account number of the account.
title string false false The title of the account.
isActive bool false false Is the account active? (NOTE: no longer used by FlowAllocator)
isTaxable bool false false Is the account taxable?
canTrade bool false false Can you trade securities in the account?
accountStrategyID string false false The strategy associated with this account, if any.

MAllocation

This is the ‘openalloc/allocation’ schema.

Each row of the Allocations table describes a ‘slice’ of a strategy’s allocation pie.

Name Type IsRequired IsKey Descript
allocationStrategyID string true true The strategy associated with this allocation.
allocationAssetID string true true The asset of the allocation.
targetPct double false false The fraction of the asset in the strategy.
isLocked bool false false Whether the targetPct is locked (or floating).

MAsset

This is the ‘openalloc/asset’ schema.

Each row of the Assets table describes a unique asset class.

It also establishes relations between assets.

Name Type IsRequired IsKey Descript
assetID string true true The id of the asset.
title string false false The title of the asset.
colorCode int false false The code for the asset's color palette.
parentAssetID string false false The id of the parent of the asset.

MCap

This is the ‘openalloc/cap’ schema.

This table describes limits on allocation for an asset class within an account.

Name Type IsRequired IsKey Descript
capAccountID string true true The account in which the limit will be imposed.
capAssetID string true true The asset in which the limit will be imposed.
limitPct double false false Allocate no more than this fraction of the account's capacity to the asset.

MHistory

This is the ‘openalloc/history’ schema.

A table of recent transaction history, including purchases and sales.

Name Type IsRequired IsKey Descript
transactionID string false true Unique transaction identifier for the history record.
historyAccountID string true false The account in which the transaction occurred.
historySecurityID string true false The security involved in the transaction.
shareCount double false false The number of shares transacted.
sharePrice double false false The price at which the share(s) transacted.
realizedGainShort double false false The total short-term realized gain (or loss) from a sale.
realizedGainLong double false false The total long-term realized gain (or loss) from a sale.
transactedAt date false false The date of the transaction.

MHolding

This is the ‘openalloc/holding’ schema.

A table where each row describes an individual position, with account, ticker, share count, share basis, etc.

Name Type IsRequired IsKey Descript
holdingAccountID string true true The account hosting the position.
holdingSecurityID string true true The security of the position.
holdingLotID string true true The lot of the position, if any.
shareCount double false false The number of shares held in the position.
shareBasis double false false The price paid per share of the security.
acquiredAt date false false The date of the acquisition.

MSecurity

This is the ‘openalloc/security’ schema.

Table where each row describes a unique security, with its ticker, asset class and latest price.

Name Type IsRequired IsKey Descript
securityID string true true The symbol/securityID of the security.
securityAssetID string false false The asset class of the security.
sharePrice double false false The reported price of one share of the security.
updatedAt date false false The timestamp of the the reported price.
securityTrackerID string false false The index the security is tracking.

MStrategy

This is the ‘openalloc/strategy’ schema.

Each row of the Strategies table describes a single allocation strategy.

Name Type IsRequired IsKey Descript
strategyID string true true The name of the strategy.
title string false false The title of the strategy.

MTracker

This is the ‘openalloc/tracker’ schema.

Each row of the Tracker table describes a many-to-many relationship between Securities.

Name Type IsRequired IsKey Descript
trackerID string true true The name of the tracking index.
title string false false The title of the tracking index.

MRebalanceAllocation

This is the ‘openalloc/rebalance/allocation’ schema.

Each row of the RebalanceAllocation table describes an allocation that drives a rebalance.

Name Type IsRequired IsKey Descript
allocationAccountID string true true The account to which the asset is allocated.
allocationAssetID string true true The asset class of the allocation.
amount double true false The amount in dollars allocated.

MRebalancePurchase

This is the ‘openalloc/rebalance/purchase’ schema.

Each row of the RebalancePurchase table describes an acquisition of a position to satisfy a rebalance.

Name Type IsRequired IsKey Descript
purchaseAccountID string true true The account to host the position.
purchaseAssetID string true true The asset class of the position to acquire.
amount double true false The amount in dollars to acquire.

MRebalanceSale

This is the ‘openalloc/rebalance/sale’ schema.

Each row of the RebalanceSale table describes a liquidation of a position to satisfy a rebalance.

Name Type IsRequired IsKey Descript
saleAccountID string true true The account hosting the position.
saleSecurityID string true true The security of the position.
saleLotID string true true The lot of the position, if any.
amount double true false The amount in dollars to liquidate from this position.
shareCount double false false Estimated number of shares to liquidate from this position.
liquidateAll bool false false If true, the entire position can be liquidated.

API

Entities in the data model all conform to AllocBase protocol.

public protocol AllocBase: Codable {
    // pre-decoded row, without strong typing
    typealias RawRow = [String: String]

    // decoded row, with strong typing
    typealias Row = [String: AnyHashable?]

    static var schema: AllocSchema { get }
    static var attributes: [AllocAttribute] { get }

    var primaryKey: AllocKey { get }

    // create object from row
    init(from row: Row) throws

    // additive update from row
    mutating func update(from row: Row) throws

    static func getPrimaryKey(_ row: Row) throws -> AllocKey

    static func decode(_ rawRows: [RawRow], rejectedRows: inout [Row]) throws -> [Row]
}

Applications using AllocData

  • FINporter - a library and command-line tool to transform various specialized formats to the standardized schema of AllocData

  • FlowAllocator - a new portfolio rebalancing tool for macOS

License

Copyright 2021 FlowAllocator LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributing

Contributions are welcome. You are encouraged to submit pull requests to fix bugs, improve documentation, or offer new features.

The pull request need not be a production-ready feature or fix. It can be a draft of proposed changes, or simply a test to show that expected behavior is buggy. Discussion on the pull request can proceed from there.

Contributions should ultimately have adequate test coverage. See tests for current entities to see what coverage is expected.

GitHub

link
Stars: 0
Last commit: 2 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

row utils now public to make extending easier
2 days ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API