agiprolabs/claude-trading-skills/cost-basis-engine
Claude Code and agent skill by agiprolabs/claude-trading-skills
- community
Checking that the SKILL.md file is still in the repository.
Multi-method cost basis computation including specific identification, FIFO, LIFO, HIFO, and proportional average cost with partial sell handling
Install
npx vskill@latest install agiprolabs/claude-trading-skills/cost-basis-engineSKILL.md
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.
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.
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.
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 Identification
The trader explicitly selects which lots to sell. Provides maximum control but requires meticulous record-keeping. Each lot must be uniquely identifiable (e.g., by purchase date and time, or a lot ID).
5. Proportional / Average Cost Method
Compute a single weighted-average cost per unit across all held lots. Every sell uses that average cost. The average updates after each buy.
Partial sell with average cost
Lots: 100 @ $1.00, 50 @ $2.00, 75 @ $1.50. Total: 225 units, total cost $312.50.
Average cost = $312.50 / 225 = $1.3889/unit
Sell 120 at $3.00: gain = (3.00 - 1.3889) * 120 = $193.33
After the sell, 105 units remain at the same $1.3889 average.
6. Special Events
Airdrops
Airdrops are treated as income at fair market value (FMV) on the date received. The FMV becomes the cost basis for future sales.
Staking Rewards
Staking rewards are income at FMV when received (similar to airdrops). Each reward event creates a new lot.
Token Splits and Migrations
A token split or migration (old token to new token 1:1 or N:M) is generally not a taxable event. The total cost basis transfers to the new tokens.
For a 1:10 split of 100 tokens @ $5.00: result is 1000 tokens @ $0.50. Total basis unchanged at $500.
7. LP Entry/Exit as Token Swaps
Entering an LP position is treated as selling the deposited tokens and receiving LP tokens. Exiting is the reverse.
LP Entry (deposit 10 SOL + 1500 USDC into SOL/USDC pool):
- Dispose of 10 SOL at current FMV → capital gain/loss event
- Dispose of 1500 USDC at current FMV → usually negligible gain/loss
- Receive LP tokens with cost basis = FMV of deposited assets
LP Exit (redeem LP tokens for 12 SOL + 1400 USDC):
- Dispose of LP tokens at FMV of received assets → capital gain/loss
- Receive 12 SOL with cost basis = FMV at redemption
- Receive 1400 USDC with cost basis = FMV at redemption
8. Multi-Hop Swaps
A multi-hop swap (e.g., SOL -> USDC -> TOKEN) creates multiple taxable events, one for each intermediate step. Jupiter often routes through intermediate tokens.
Example: Swap 1 SOL ($150) -> 150 USDC -> 10,000 TOKEN ($0.015 each)
- Event 1: Dispose 1 SOL (basis vs. $150 proceeds) → gain/loss on SOL
- Event 2: Dispose 150 USDC (basis vs. $150 proceeds) → usually ~$0 gain
- Result: 10,000 TOKEN with cost basis = $0.015/unit
9. Comparison View
The core value of this skill: run the same trade history through all five methods and compare total realized gain and estimated tax liability.
See scripts/cost_basis_calculator.py for a full runnable comparison with realistic trade data including partial sells.
Quick Start
Use Cases
- Tax season preparation: Run your full year of trades through all methods before choosing one to report.
- Accumulation strategy: Track partial sells during DCA accumulation, see how each method affects remaining basis.
- LP position tracking: Model LP entry/exit as swaps and capture the associated gain/loss events.
- Airdrop and staking income: Properly record income events and set cost basis for future disposals.
- Multi-hop swap decomposition: Break down Jupiter routes into individual taxable events.
Files
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cost-basis-engine/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/agiprolabs/claude-trading-skills/cost-basis-engine)