cost-basis-engine
Multi-method cost basis computation including specific identification, FIFO, LIFO, HIFO, and proportional average cost with partial sell handling
Skill by agipro
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/serennity007-cost-basis-engine
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: finance
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
- Runs as
- Python package
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/cost-basis-engine
What's inside
- Skill name
cost-basis-engine- Description
- Multi-method cost basis computation including specific identification, FIFO, LIFO, HIFO, and proportional average cost with partial sell handling
- License
- MIT
- Metadata
- author: agipro · version: 0.1.0 · category: trading
- Instructions
- 350 lines in SKILL.md · view on GitHub
Before installing
- Ships executable scripts
Files (3)
- SKILL.md
- planned_features.md · references/
- cost_basis_calculator.py · scripts/
SKILL.md (first lines)
# Cost Basis Engine
Compute cost basis for crypto trades using multiple accounting methods and compare the resulting tax liability across methods. This skill handles the full complexity of on-chain activity: partial sells, token migrations, airdrops, staking rewards, LP entry/exit, and multi-hop swaps.
> **Disclaimer**: This skill provides computational tools for informational purposes only. It does not constitute tax, legal, or financial advice. Consult a qualified tax professional for your specific situation. Tax law varies by jurisdiction and changes frequently.
## Prerequisites
- Python 3.10+
- No external dependencies required (standard library only)
- Trade history as a list of dicts or CSV with columns: `date`, `action`, `token`, `quantity`, `price_usd`, `fee_usd`
## Methods Overview
| Method | Logic | Best For |
|--------|-------|----------|
| **FIFO** | First lots purchased are sold first | Simplicity, many jurisdictions' default |
| **LIFO** | Last lots purchased are sold first | Deferring gains when prices rise over time |
| **HIFO** | Highest-cost lots are sold first | Minimizing current tax liability |
| **Specific ID** | Trader selects which lots to sell | Maximum control, requires record-keeping |
| **Average Cost** | Weighted average of all held lots | Simplicity, required in some jurisdictions |
---
## 1. FIFO (First-In, First-Out)
Sell the oldest lots first. This is the default method in the US if no other method is elected.
```python
def fifo_sell(lots: list[dict], sell_qty: float, sell_price: float) -> list[dict]:
"""Sell using FIFO. lots sorted oldest-first."""
remaining = sell_qty
realized = []
while remaining > 0 and lots:
lot = lots[0]
used = min(lot["qty"], remaining)
gain = (sell_price - lot["cost_per_unit"]) * used
realized.append({"qty": used, "basis": lot["cost_per_unit"], "gain": gain})
lot["qty"] -= used
remaining -= used
if lot["qty"] <= 0:
lots.pop(0)
return realized
```
### Partial sell example
You hold three lots of TOKEN:
- Lot A: 100 units @ $1.00 (oldest)
- Lot B: 50 units @ $2.00
- Lot C: 75 units @ $1.50
You sell 120 units at $3.00:
- 100 from Lot A: gain = (3.00 - 1.00) * 100 = $200
- 20 from Lot B: gain = (3.00 - 2.00) * 20 = $20
- Total realized gain: **$220**
- Lot B remainder: 30 units @ $2.00
---
## 2. LIFO (Last-In, First-Out)
Sell the newest lots first. Reverses the order compared to FIFO.
```python
def lifo_sell(lots: list[dict], sell_qty: float, sell_price: float) -> list[dict]:
"""Sell using LIFO. Pops from end (newest first)."""
remaining = sell_qty
realized = []
while remaining > 0 and lots:
lot = lots[-1]
used = min(lot["qty"], remaining)
gain = (sell_price - lot["cost_per_unit"]) * used
realized.append({"qty": used, "basis": lot["cost_per_unit"], "gain": gain})
lot["qty"] -= used
remaining -= used
if lot["qty"] <= 0:
lots.pop()
return realized
```
Using the same lots and selling 120 at $3.00 with LIFO:
- 75 from Lot C: gain = (3.00 - 1.50) * 75 = $112.50
- 45 from Lot B: gain = (3.00 - 2.00) * 45 = $45
- Total realized gain: **$157.50**
---
## 3. HIFO (Highest-In, First-Out)
Sell the highest-cost lots first to minimize realized gains.
```python
def hifo_sell(lots: list[dict], sell_qty: float, sell_price: float) -> list[dict]:
"""Sell using HIFO. Sort by cost descending, consume highest first."""
lots.sort(key=lambda x: x["cost_per_unit"], reverse=True)
remaining = sell_qty
realized = []
for lot in lots:
if remaining <= 0:
break
used = min(lot["qty"], remaining)
gain = (sell_price - lot["cost_per_unit"]) * used
realized.append({"qty": used, "basis": lot["cost_per_unit"], "gain": gain})
lot["qty"] -= used
remaining -= used
lots[:] = [l for l in lots if l["qty"] > 0]
return realized
```
Same lots, selling 120 at $3.00 with HIFO:
- 50 from Lot B ($2.00, highest): gain = (3.00 - 2.00) * 50 = $50
- 70 from Lot C ($1.50, next highest): gain = (3.00 - 1.50) * 70 = $105
- Total realized gain: **$155**
- Remaining: Lot A 100 @ $1.00, Lot C 5 @ $1.50
---
## 4. Specific IdentificationFrom Serennity007/awesome-stock-quant-skills, MIT.
More from Serennity007/awesome-stock-quant-skills
- 0.618score
correlation-analysis
Serennity007
Cross-asset correlation analysis including rolling correlation, hierarchical clustering, tail dependence, and regime-dependent correlation
SkillBFreshness: B★ 41Claude Code +9 - 0.618score
coingecko-api
Serennity007
Broad crypto market data from CoinGecko covering 13,000+ tokens.
SkillBFreshness: B★ 41Claude Code +9 - 0.618score
feature-engineering
Serennity007
Feature construction from market data for ML trading models including price, volume, on-chain, and microstructure features
SkillBFreshness: B★ 41Claude Code +9 - 0.618score
crypto-tax-export
agipro
Export trade history and tax calculations in formats compatible with Koinly, CoinTracker, CoinLedger, TokenTax, and IRS Form 8949
SkillBFreshness: B★ 41Claude Code +9 - 0.618score
dex-pool-analysis
Serennity007
AMM pool mechanics comparison across Raydium, Orca, and Meteora including fee structures, pool types, creation patterns, and volume efficiency
SkillBFreshness: B★ 41Claude Code +9 - 0.618score
custom-indicators
Serennity007
Crypto-native indicators including NVT ratio, exchange flow, funding rate signals, holder momentum, and smart money flow
SkillBFreshness: B★ 41Claude Code +9 - 0.617score
ibkr-options-assistant
Serennity007
Interactive Brokers options & stock trading assistant.
SkillBFreshness: B★ 41Claude Code +9 - 0.615score
helius-api
Serennity007
Enhanced Solana RPC with DAS API, parsed transactions, webhooks, and priority fee estimation via Helius
SkillBFreshness: B★ 41Claude Code +9 - 0.615score
birdeye-api
Serennity007
Solana token market data via Birdeye — prices, OHLCV, trades, token metadata, security checks, and trader activity
SkillBFreshness: B★ 41Claude Code +9 - 0.615score
cointegration-analysis
Serennity007
Cointegration testing for pairs trading using Engle-Granger, Johansen, and rolling stability analysis
SkillBFreshness: B★ 41Claude Code +9 - 0.615score
defillama-api
Serennity007
Free DeFi analytics across all chains — TVL, token prices, DEX volumes, fees/revenue, stablecoins, and bridges
SkillBFreshness: B★ 41Claude Code +9 - 0.615score
dex-execution
Serennity007
Solana DEX swap execution via Jupiter aggregator including quoting, transaction building, signing, and confirmation
SkillBFreshness: B★ 41Claude Code +9
Signals
- Stars
- 41
- Forks
- 8
- Open issues
- 1
- Last commit (this folder)
- Aug 25, 2026 (2 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- Version
- 0.1.0
- License
- MIT
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from agipro
Cite this page
cost-basis-engine skill. Agent Mart. https://agentmart.dev/skills/serennity007-cost-basis-engine (last updated 2026-10-24)