@livefolio/sdk 0.5.0-rc.1 → 0.5.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +315 -50
- package/dist/index.js +209 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3286,34 +3286,34 @@ declare function isRebalanceDay(t: Date, freq: RebalanceFrequency, calendar: Cal
|
|
|
3286
3286
|
*/
|
|
3287
3287
|
declare function fromSpec(spec: TacticalSpec, opts: FromSpecOptions): Strategy<TacticalFeatures, RuleTreeState>;
|
|
3288
3288
|
|
|
3289
|
-
type index$
|
|
3290
|
-
type index$
|
|
3291
|
-
type index$
|
|
3292
|
-
type index$
|
|
3293
|
-
type index$
|
|
3294
|
-
type index$
|
|
3295
|
-
type index$
|
|
3296
|
-
type index$
|
|
3297
|
-
type index$
|
|
3298
|
-
type index$
|
|
3299
|
-
type index$
|
|
3300
|
-
type index$
|
|
3301
|
-
type index$
|
|
3302
|
-
type index$
|
|
3303
|
-
type index$
|
|
3304
|
-
type index$
|
|
3305
|
-
type index$
|
|
3306
|
-
type index$
|
|
3307
|
-
declare const index$
|
|
3308
|
-
declare const index$
|
|
3309
|
-
declare const index$
|
|
3310
|
-
declare const index$
|
|
3311
|
-
declare const index$
|
|
3312
|
-
declare const index$
|
|
3313
|
-
declare const index$
|
|
3314
|
-
declare const index$
|
|
3315
|
-
declare namespace index$
|
|
3316
|
-
export { type index$
|
|
3289
|
+
type index$2_AllocateNode = AllocateNode;
|
|
3290
|
+
type index$2_AssetRef = AssetRef;
|
|
3291
|
+
type index$2_Comparison = Comparison;
|
|
3292
|
+
type index$2_ComparisonOp = ComparisonOp;
|
|
3293
|
+
type index$2_FeatureRef = FeatureRef;
|
|
3294
|
+
type index$2_FromSpecOptions = FromSpecOptions;
|
|
3295
|
+
type index$2_IfNode = IfNode;
|
|
3296
|
+
type index$2_RebalanceConfig = RebalanceConfig;
|
|
3297
|
+
type index$2_RebalanceFrequency = RebalanceFrequency;
|
|
3298
|
+
type index$2_RuleNode = RuleNode;
|
|
3299
|
+
type index$2_RuleTreeState = RuleTreeState;
|
|
3300
|
+
type index$2_SyntheticAsset = SyntheticAsset;
|
|
3301
|
+
type index$2_TacticalFeatureKind = TacticalFeatureKind;
|
|
3302
|
+
type index$2_TacticalFeatureSpec = TacticalFeatureSpec;
|
|
3303
|
+
type index$2_TacticalFeatures = TacticalFeatures;
|
|
3304
|
+
type index$2_TacticalSpec = TacticalSpec;
|
|
3305
|
+
type index$2_Tolerance = Tolerance;
|
|
3306
|
+
type index$2_WithStreamingSyntheticsOptions = WithStreamingSyntheticsOptions;
|
|
3307
|
+
declare const index$2__resetTacticalDeprecationWarningForTesting: typeof _resetTacticalDeprecationWarningForTesting;
|
|
3308
|
+
declare const index$2_evaluateFeatureSpecs: typeof evaluateFeatureSpecs;
|
|
3309
|
+
declare const index$2_evaluateRuleTree: typeof evaluateRuleTree;
|
|
3310
|
+
declare const index$2_fromSpec: typeof fromSpec;
|
|
3311
|
+
declare const index$2_isRebalanceDay: typeof isRebalanceDay;
|
|
3312
|
+
declare const index$2_periodKey: typeof periodKey;
|
|
3313
|
+
declare const index$2_withStreamingSynthetics: typeof withStreamingSynthetics;
|
|
3314
|
+
declare const index$2_withSynthetics: typeof withSynthetics;
|
|
3315
|
+
declare namespace index$2 {
|
|
3316
|
+
export { type index$2_AllocateNode as AllocateNode, type index$2_AssetRef as AssetRef, type index$2_Comparison as Comparison, type index$2_ComparisonOp as ComparisonOp, type index$2_FeatureRef as FeatureRef, type index$2_FromSpecOptions as FromSpecOptions, type index$2_IfNode as IfNode, type index$2_RebalanceConfig as RebalanceConfig, type index$2_RebalanceFrequency as RebalanceFrequency, type index$2_RuleNode as RuleNode, type index$2_RuleTreeState as RuleTreeState, type index$2_SyntheticAsset as SyntheticAsset, type index$2_TacticalFeatureKind as TacticalFeatureKind, type index$2_TacticalFeatureSpec as TacticalFeatureSpec, type index$2_TacticalFeatures as TacticalFeatures, type index$2_TacticalSpec as TacticalSpec, type index$2_Tolerance as Tolerance, type index$2_WithStreamingSyntheticsOptions as WithStreamingSyntheticsOptions, index$2__resetTacticalDeprecationWarningForTesting as _resetTacticalDeprecationWarningForTesting, index$2_evaluateFeatureSpecs as evaluateFeatureSpecs, index$2_evaluateRuleTree as evaluateRuleTree, index$2_fromSpec as fromSpec, index$2_isRebalanceDay as isRebalanceDay, index$2_periodKey as periodKey, index$2_withStreamingSynthetics as withStreamingSynthetics, index$2_withSynthetics as withSynthetics };
|
|
3317
3317
|
}
|
|
3318
3318
|
|
|
3319
3319
|
/**
|
|
@@ -3575,28 +3575,293 @@ declare function volatility(series: Series, period: number): Series;
|
|
|
3575
3575
|
*/
|
|
3576
3576
|
declare function drawdown(series: Series, period: number): Series;
|
|
3577
3577
|
|
|
3578
|
-
type
|
|
3579
|
-
type
|
|
3580
|
-
type
|
|
3581
|
-
type
|
|
3582
|
-
declare const
|
|
3583
|
-
type
|
|
3584
|
-
type
|
|
3585
|
-
type
|
|
3586
|
-
declare const
|
|
3587
|
-
declare const
|
|
3588
|
-
declare const
|
|
3589
|
-
declare const
|
|
3590
|
-
declare const
|
|
3591
|
-
declare const
|
|
3592
|
-
declare const
|
|
3593
|
-
declare const
|
|
3594
|
-
declare const
|
|
3595
|
-
declare const
|
|
3596
|
-
declare const
|
|
3597
|
-
declare const
|
|
3578
|
+
type index$1_BarField = BarField;
|
|
3579
|
+
type index$1_ComputeFn = ComputeFn;
|
|
3580
|
+
type index$1_FeatureKind = FeatureKind;
|
|
3581
|
+
type index$1_FeatureRuntime = FeatureRuntime;
|
|
3582
|
+
declare const index$1_FeatureRuntime: typeof FeatureRuntime;
|
|
3583
|
+
type index$1_FeatureRuntimeOptions = FeatureRuntimeOptions;
|
|
3584
|
+
type index$1_FeatureSpec = FeatureSpec;
|
|
3585
|
+
type index$1_ReturnMode = ReturnMode;
|
|
3586
|
+
declare const index$1_barsToSeries: typeof barsToSeries;
|
|
3587
|
+
declare const index$1_collectBars: typeof collectBars;
|
|
3588
|
+
declare const index$1_defineFeature: typeof defineFeature;
|
|
3589
|
+
declare const index$1_drawdown: typeof drawdown;
|
|
3590
|
+
declare const index$1_ema: typeof ema;
|
|
3591
|
+
declare const index$1_getFeatureCompute: typeof getFeatureCompute;
|
|
3592
|
+
declare const index$1_paramsHash: typeof paramsHash;
|
|
3593
|
+
declare const index$1_returnSeries: typeof returnSeries;
|
|
3594
|
+
declare const index$1_rsi: typeof rsi;
|
|
3595
|
+
declare const index$1_seriesAt: typeof seriesAt;
|
|
3596
|
+
declare const index$1_sma: typeof sma;
|
|
3597
|
+
declare const index$1_volatility: typeof volatility;
|
|
3598
|
+
declare namespace index$1 {
|
|
3599
|
+
export { type index$1_BarField as BarField, type index$1_ComputeFn as ComputeFn, type index$1_FeatureKind as FeatureKind, index$1_FeatureRuntime as FeatureRuntime, type index$1_FeatureRuntimeOptions as FeatureRuntimeOptions, type index$1_FeatureSpec as FeatureSpec, type index$1_ReturnMode as ReturnMode, index$1_barsToSeries as barsToSeries, index$1_collectBars as collectBars, index$1_defineFeature as defineFeature, index$1_drawdown as drawdown, index$1_ema as ema, index$1_getFeatureCompute as getFeatureCompute, index$1_paramsHash as paramsHash, index$1_returnSeries as returnSeries, index$1_rsi as rsi, index$1_seriesAt as seriesAt, index$1_sma as sma, index$1_volatility as volatility };
|
|
3600
|
+
}
|
|
3601
|
+
|
|
3602
|
+
/**
|
|
3603
|
+
* Calendar days between a lot's open date and `asOf` (float; may be fractional
|
|
3604
|
+
* or negative if `asOf` precedes `openDate`). Callers may `Math.floor` it.
|
|
3605
|
+
*/
|
|
3606
|
+
declare function holdingPeriodDays(lot: Lot, asOf: Date): number;
|
|
3607
|
+
/** IRS §1222 rule: a holding period of strictly more than 365 calendar days is long-term. */
|
|
3608
|
+
declare function isLongTerm(days: number): boolean;
|
|
3609
|
+
/** Result of {@link realize}: the realized event plus what's left of the lot (`null` on a full sale). */
|
|
3610
|
+
type RealizeResult = {
|
|
3611
|
+
event: RealizedEvent;
|
|
3612
|
+
remainingLot: Lot | null;
|
|
3613
|
+
};
|
|
3614
|
+
/**
|
|
3615
|
+
* Realizes `qty` shares of `lot` at `salePrice` as of `asOf`, producing one
|
|
3616
|
+
* {@link RealizedEvent} and the remaining lot (or `null` on a full sale).
|
|
3617
|
+
*
|
|
3618
|
+
* Pure gain/loss primitive for estimation and lot ranking (e.g. selectMinTax,
|
|
3619
|
+
* TLH preview). It does **not** model transaction fees: pass a `salePrice` that
|
|
3620
|
+
* is already net of any per-share fee if you need fee-adjusted proceeds. The
|
|
3621
|
+
* stateful, fee-aware realization path used during execution lives in
|
|
3622
|
+
* `applyFills` (`consumeLots`), which pro-rates `fill.fees` across slices.
|
|
3623
|
+
*
|
|
3624
|
+
* Basis is pro-rated as `lot.basis / lot.quantity * qty` (so any
|
|
3625
|
+
* `washSaleAdjustment` already folded into `lot.basis` is carried through).
|
|
3626
|
+
*
|
|
3627
|
+
* @param lot - The lot to realize against.
|
|
3628
|
+
* @param qty - Shares to realize. Must be `> 0` and `<= lot.quantity`.
|
|
3629
|
+
* @param salePrice - Per-share sale price (net of fees if fee-adjustment is desired).
|
|
3630
|
+
* @param asOf - Sale date; drives short/long classification via the 365-day rule.
|
|
3631
|
+
* @returns `{ event, remainingLot }`; `remainingLot` is `null` when the whole lot is sold.
|
|
3632
|
+
* @throws {RangeError} if `qty <= 0` or `qty > lot.quantity`.
|
|
3633
|
+
*/
|
|
3634
|
+
declare function realize(lot: Lot, qty: number, salePrice: number, asOf: Date): RealizeResult;
|
|
3635
|
+
|
|
3636
|
+
/** A slice of a tax lot consumed to fulfill part of a sell order. */
|
|
3637
|
+
type LotSlice = {
|
|
3638
|
+
lotId: string;
|
|
3639
|
+
quantity: number;
|
|
3640
|
+
};
|
|
3641
|
+
/** Short-term and long-term capital-gains tax rates (as decimals, e.g. 0.37). */
|
|
3642
|
+
type TaxRates = {
|
|
3643
|
+
shortTerm: number;
|
|
3644
|
+
longTerm: number;
|
|
3645
|
+
};
|
|
3646
|
+
/**
|
|
3647
|
+
* First-In-First-Out lot selection.
|
|
3648
|
+
*
|
|
3649
|
+
* Selects lots in ascending `openDate` order, consuming oldest lots first.
|
|
3650
|
+
*/
|
|
3651
|
+
declare function selectFIFO(lots: readonly Lot[], qty: number): LotSlice[];
|
|
3652
|
+
/**
|
|
3653
|
+
* Last-In-First-Out lot selection.
|
|
3654
|
+
*
|
|
3655
|
+
* Selects lots in descending `openDate` order, consuming newest lots first.
|
|
3656
|
+
*/
|
|
3657
|
+
declare function selectLIFO(lots: readonly Lot[], qty: number): LotSlice[];
|
|
3658
|
+
/**
|
|
3659
|
+
* Highest-In-First-Out lot selection.
|
|
3660
|
+
*
|
|
3661
|
+
* Selects lots in descending per-share basis (`basis / quantity`) order,
|
|
3662
|
+
* realizing the highest-cost lots first to minimize gains.
|
|
3663
|
+
*/
|
|
3664
|
+
declare function selectHIFO(lots: readonly Lot[], qty: number): LotSlice[];
|
|
3665
|
+
/**
|
|
3666
|
+
* Tax-minimizing lot selection.
|
|
3667
|
+
*
|
|
3668
|
+
* Ranks lots by a 4-tier comparator designed to realize the least tax:
|
|
3669
|
+
* 1. Long-term losses (tier 0) — offsets LT gains at the lower LT rate
|
|
3670
|
+
* 2. Short-term losses (tier 1) — offsets ST gains at the higher ST rate
|
|
3671
|
+
* 3. Long-term gains (tier 2) — taxed at the lower LT rate
|
|
3672
|
+
* 4. Short-term gains (tier 3) — taxed at the higher ST rate
|
|
3673
|
+
*
|
|
3674
|
+
* Within a tier, lots are sorted by ascending gain-per-share so that the
|
|
3675
|
+
* largest losses (or smallest gains) are consumed first.
|
|
3676
|
+
*
|
|
3677
|
+
* Uses `isLongTerm(holdingPeriodDays(lot, ctx.asOf))` for term classification
|
|
3678
|
+
* and `ctx.price - lot.basis / lot.quantity` for gain-per-share.
|
|
3679
|
+
*
|
|
3680
|
+
* `ctx.rates` is accepted for forward-compatibility and signature stability
|
|
3681
|
+
* (the executor's min-tax `lotMethod` passes it through); the current 4-tier
|
|
3682
|
+
* ranking does not read the rate magnitudes.
|
|
3683
|
+
*
|
|
3684
|
+
* NOTE: this is a conservative, IRS-aligned *ordering* heuristic, not a literal
|
|
3685
|
+
* rate-weighted per-share tax minimum. The two can diverge: a $100/share LT gain
|
|
3686
|
+
* (tier 2, $20 tax at a 20% LT rate) is selected before a $50/share ST gain
|
|
3687
|
+
* (tier 3, $18.50 tax at a 37% ST rate), even though the ST lot realizes less
|
|
3688
|
+
* tax. The tier order favors the lower-rate bucket and sidesteps marginal-bracket
|
|
3689
|
+
* complexity; it does not compute `gain × rate` per lot.
|
|
3690
|
+
*/
|
|
3691
|
+
declare function selectMinTax(lots: readonly Lot[], qty: number, ctx: {
|
|
3692
|
+
price: number;
|
|
3693
|
+
asOf: Date;
|
|
3694
|
+
rates: TaxRates;
|
|
3695
|
+
}): LotSlice[];
|
|
3696
|
+
|
|
3697
|
+
/**
|
|
3698
|
+
* Maximum capital-loss deduction against ordinary income per IRS §1211(b).
|
|
3699
|
+
* In a given tax year, net capital losses above `ORDINARY_OFFSET_CAP` are
|
|
3700
|
+
* carried forward to future years rather than deducted immediately.
|
|
3701
|
+
*/
|
|
3702
|
+
declare const ORDINARY_OFFSET_CAP = 3000;
|
|
3703
|
+
/**
|
|
3704
|
+
* Year-level summary of taxable income across all categories.
|
|
3705
|
+
*
|
|
3706
|
+
* - `shortTermGains` / `longTermGains`: sum of positive `gain` values from
|
|
3707
|
+
* capital-gain events in each term bucket.
|
|
3708
|
+
* - `shortTermLosses` / `longTermLosses`: sum of |negative `gain`| values
|
|
3709
|
+
* (stored as **positive magnitudes**) from capital-gain events.
|
|
3710
|
+
* - `qualifiedDividends`: qualified dividend income (taxed at LT rate).
|
|
3711
|
+
* - `ordinaryDividends`: non-qualified dividend income (taxed at ST rate).
|
|
3712
|
+
* - `interestIncome`: interest income (taxed at ST rate).
|
|
3713
|
+
*
|
|
3714
|
+
* Capital losses **never** offset `qualifiedDividends` or `ordinaryDividends`.
|
|
3715
|
+
* The cross-offset logic in {@link crossOffset} operates only on the capital-
|
|
3716
|
+
* gain buckets; dividend/interest income is added post-offset at full value.
|
|
3717
|
+
*/
|
|
3718
|
+
type TaxableIncome = {
|
|
3719
|
+
shortTermGains: number;
|
|
3720
|
+
/** Positive magnitude of short-term capital losses. */
|
|
3721
|
+
shortTermLosses: number;
|
|
3722
|
+
longTermGains: number;
|
|
3723
|
+
/** Positive magnitude of long-term capital losses. */
|
|
3724
|
+
longTermLosses: number;
|
|
3725
|
+
qualifiedDividends: number;
|
|
3726
|
+
ordinaryDividends: number;
|
|
3727
|
+
interestIncome: number;
|
|
3728
|
+
};
|
|
3729
|
+
/**
|
|
3730
|
+
* Partitions `events` into short-term and long-term capital-gain buckets.
|
|
3731
|
+
*
|
|
3732
|
+
* Events with `incomeKind !== 'capital-gain'` (dividends, interest) are
|
|
3733
|
+
* excluded entirely — they are not subject to the capital-gain offset logic.
|
|
3734
|
+
*
|
|
3735
|
+
* @param events - Flat array of {@link RealizedEvent}s for a single year or
|
|
3736
|
+
* for the full history (caller selects the relevant slice).
|
|
3737
|
+
* @returns `{ short, long }` — two arrays of capital-gain events by term.
|
|
3738
|
+
*/
|
|
3739
|
+
declare function bucketByTerm(events: readonly RealizedEvent[]): {
|
|
3740
|
+
short: RealizedEvent[];
|
|
3741
|
+
long: RealizedEvent[];
|
|
3742
|
+
};
|
|
3743
|
+
/**
|
|
3744
|
+
* Nets gains and losses within a single bucket (all-short or all-long).
|
|
3745
|
+
*
|
|
3746
|
+
* Events with `gain >= 0` contribute to `gains`; events with `gain < 0`
|
|
3747
|
+
* contribute to `losses` as a **positive magnitude**.
|
|
3748
|
+
*
|
|
3749
|
+
* @param events - Capital-gain events for one term bucket.
|
|
3750
|
+
* @returns `{ gains, losses, net }` where `net = gains - losses`.
|
|
3751
|
+
*/
|
|
3752
|
+
declare function netWithinBucket(events: readonly RealizedEvent[]): {
|
|
3753
|
+
gains: number;
|
|
3754
|
+
losses: number;
|
|
3755
|
+
net: number;
|
|
3756
|
+
};
|
|
3757
|
+
/**
|
|
3758
|
+
* Applies IRS capital-gain cross-offset rules between short-term and long-term nets.
|
|
3759
|
+
*
|
|
3760
|
+
* Rules (in order of precedence):
|
|
3761
|
+
* 1. **Both non-negative**: no offset; return each net unchanged.
|
|
3762
|
+
* 2. **Both negative**: combine losses; apply up to `ORDINARY_OFFSET_CAP` ($3,000)
|
|
3763
|
+
* against ordinary income; remainder becomes `carryForward`.
|
|
3764
|
+
* 3. **Opposite signs, combined ≥ 0**: the loss bucket fully absorbs into the gain
|
|
3765
|
+
* bucket; the residual stays in the gain bucket's term (`taxableShort` if
|
|
3766
|
+
* `netShort > 0`, else `taxableLong`). No ordinary offset or carry-forward.
|
|
3767
|
+
* 4. **Opposite signs, combined < 0**: net loss after cross-offset;
|
|
3768
|
+
* up to `ORDINARY_OFFSET_CAP` deducted against ordinary income; remainder
|
|
3769
|
+
* becomes `carryForward`.
|
|
3770
|
+
*
|
|
3771
|
+
* **Important:** `ordinaryOffset` and `carryForward` apply only to capital
|
|
3772
|
+
* losses. Dividend and interest income is never offset by capital losses.
|
|
3773
|
+
*
|
|
3774
|
+
* @param netShort - Net short-term capital gain (negative = loss).
|
|
3775
|
+
* @param netLong - Net long-term capital gain (negative = loss).
|
|
3776
|
+
* @returns `{ taxableShort, taxableLong, ordinaryOffset, carryForward }`.
|
|
3777
|
+
*/
|
|
3778
|
+
declare function crossOffset(netShort: number, netLong: number): {
|
|
3779
|
+
taxableShort: number;
|
|
3780
|
+
taxableLong: number;
|
|
3781
|
+
ordinaryOffset: number;
|
|
3782
|
+
carryForward: number;
|
|
3783
|
+
};
|
|
3784
|
+
/**
|
|
3785
|
+
* Aggregates {@link RealizedEvent}s by UTC calendar year into a
|
|
3786
|
+
* {@link TaxableIncome} map.
|
|
3787
|
+
*
|
|
3788
|
+
* Keyed by `closeDate.getUTCFullYear()`. Each event is routed:
|
|
3789
|
+
* - `capital-gain`: bucketed into `shortTermGains`/`shortTermLosses` (ST) or
|
|
3790
|
+
* `longTermGains`/`longTermLosses` (LT) by `termType` and sign of `gain`.
|
|
3791
|
+
* Losses are stored as **positive magnitudes**.
|
|
3792
|
+
* - `qualified-dividend`: adds `proceeds` to `qualifiedDividends`.
|
|
3793
|
+
* - `ordinary-dividend`: adds `proceeds` to `ordinaryDividends`.
|
|
3794
|
+
* - `interest`: adds `proceeds` to `interestIncome`.
|
|
3795
|
+
*
|
|
3796
|
+
* Year boundaries use **UTC**. Backtests are unambiguous (daily bars are
|
|
3797
|
+
* UTC-midnight-anchored). Live-mode callers should normalize `closeDate` to the
|
|
3798
|
+
* tax jurisdiction's local time before passing events here if they need
|
|
3799
|
+
* calendar-year precision around year-end — e.g. a US fill on Dec 31 evening
|
|
3800
|
+
* Eastern has a UTC `closeDate` of Jan 1, which belongs to the *prior* US tax
|
|
3801
|
+
* year but would otherwise be counted in the next year.
|
|
3802
|
+
*
|
|
3803
|
+
* @param events - Full sequence of realized events (multiple years OK).
|
|
3804
|
+
* @returns `Map<year, TaxableIncome>` with one entry per UTC calendar year.
|
|
3805
|
+
*/
|
|
3806
|
+
declare function aggregateByYear(events: readonly RealizedEvent[]): Map<number, TaxableIncome>;
|
|
3807
|
+
/**
|
|
3808
|
+
* Computes the tax bill for a single year's {@link TaxableIncome}.
|
|
3809
|
+
*
|
|
3810
|
+
* Steps:
|
|
3811
|
+
* 1. Net each capital-gain bucket: `netShort = shortTermGains - shortTermLosses`,
|
|
3812
|
+
* `netLong = longTermGains - longTermLosses`.
|
|
3813
|
+
* 2. Apply {@link crossOffset} to get `taxableShort`, `taxableLong`,
|
|
3814
|
+
* `ordinaryOffset`, and `carryForward`.
|
|
3815
|
+
* 3. `ordinaryPortion = (taxableShort + ordinaryDividends + interestIncome) * shortTerm`.
|
|
3816
|
+
* 4. `ltPortion = (taxableLong + qualifiedDividends) * longTerm`.
|
|
3817
|
+
* 5. `total = ordinaryPortion + ltPortion`.
|
|
3818
|
+
*
|
|
3819
|
+
* **Critical invariant:** capital losses do **not** offset `qualifiedDividends`.
|
|
3820
|
+
* Qualified dividends are added to the LT pool *after* cross-offset, at their
|
|
3821
|
+
* full value, so a LT capital loss that wipes out `taxableLong` to zero still
|
|
3822
|
+
* leaves the qualified dividend income fully taxable at the LT rate.
|
|
3823
|
+
*
|
|
3824
|
+
* `carryForward` is surfaced as a return field for the caller to track across
|
|
3825
|
+
* years; this function does **not** consume carry-forward from prior years
|
|
3826
|
+
* (cross-year carry is V3 work).
|
|
3827
|
+
*
|
|
3828
|
+
* Note: the `ordinaryOffset` produced by {@link crossOffset} (the up-to-$3,000
|
|
3829
|
+
* §1211(b) capital-loss deduction against ordinary income) is intentionally not
|
|
3830
|
+
* surfaced here. This function models only the tax on capital income; that
|
|
3831
|
+
* deduction applies against wage/business income outside this module's scope.
|
|
3832
|
+
*
|
|
3833
|
+
* @param income - Year-level taxable income, as produced by {@link aggregateByYear}.
|
|
3834
|
+
* @param rates - `{ shortTerm, longTerm }` tax rates as decimals (e.g. `0.37`).
|
|
3835
|
+
* @returns `{ total, breakdown: { ordinaryPortion, ltPortion, carryForward } }`.
|
|
3836
|
+
*/
|
|
3837
|
+
declare function computeTaxBill(income: TaxableIncome, rates: TaxRates): {
|
|
3838
|
+
total: number;
|
|
3839
|
+
breakdown: {
|
|
3840
|
+
ordinaryPortion: number;
|
|
3841
|
+
ltPortion: number;
|
|
3842
|
+
carryForward: number;
|
|
3843
|
+
};
|
|
3844
|
+
};
|
|
3845
|
+
|
|
3846
|
+
type index_LotSlice = LotSlice;
|
|
3847
|
+
declare const index_ORDINARY_OFFSET_CAP: typeof ORDINARY_OFFSET_CAP;
|
|
3848
|
+
type index_RealizeResult = RealizeResult;
|
|
3849
|
+
type index_TaxRates = TaxRates;
|
|
3850
|
+
type index_TaxableIncome = TaxableIncome;
|
|
3851
|
+
declare const index_aggregateByYear: typeof aggregateByYear;
|
|
3852
|
+
declare const index_bucketByTerm: typeof bucketByTerm;
|
|
3853
|
+
declare const index_computeTaxBill: typeof computeTaxBill;
|
|
3854
|
+
declare const index_crossOffset: typeof crossOffset;
|
|
3855
|
+
declare const index_holdingPeriodDays: typeof holdingPeriodDays;
|
|
3856
|
+
declare const index_isLongTerm: typeof isLongTerm;
|
|
3857
|
+
declare const index_netWithinBucket: typeof netWithinBucket;
|
|
3858
|
+
declare const index_realize: typeof realize;
|
|
3859
|
+
declare const index_selectFIFO: typeof selectFIFO;
|
|
3860
|
+
declare const index_selectHIFO: typeof selectHIFO;
|
|
3861
|
+
declare const index_selectLIFO: typeof selectLIFO;
|
|
3862
|
+
declare const index_selectMinTax: typeof selectMinTax;
|
|
3598
3863
|
declare namespace index {
|
|
3599
|
-
export { type
|
|
3864
|
+
export { type index_LotSlice as LotSlice, index_ORDINARY_OFFSET_CAP as ORDINARY_OFFSET_CAP, type index_RealizeResult as RealizeResult, type index_TaxRates as TaxRates, type index_TaxableIncome as TaxableIncome, index_aggregateByYear as aggregateByYear, index_bucketByTerm as bucketByTerm, index_computeTaxBill as computeTaxBill, index_crossOffset as crossOffset, index_holdingPeriodDays as holdingPeriodDays, index_isLongTerm as isLongTerm, index_netWithinBucket as netWithinBucket, index_realize as realize, index_selectFIFO as selectFIFO, index_selectHIFO as selectHIFO, index_selectLIFO as selectLIFO, index_selectMinTax as selectMinTax };
|
|
3600
3865
|
}
|
|
3601
3866
|
|
|
3602
3867
|
/**
|
|
@@ -3712,4 +3977,4 @@ declare function applyOrders(portfolio: Portfolio, orders: ReadonlyArray<Order>)
|
|
|
3712
3977
|
*/
|
|
3713
3978
|
declare function positionsByAsset(portfolio: Portfolio): Position[];
|
|
3714
3979
|
|
|
3715
|
-
export { type AdhocTimeOverrides, type AdjustOrder, type AllocateNode, type Asset, type AssetId, type AssetRef, BacktestExecutor, type BacktestExecutorOptions, type BacktestResult, type BacktestSnapshot, type Bar, type BarField, type Calendar, type CloseOrder, type Comparison, type ComparisonOp, type ComputeFn, Crypto24x7Calendar, type DataEvent, type DataFeed, type DateRange, type EquityAsset, type EventKind, ExchangeCalendar, type ExchangeName, type Executor, type FeatureCache, type FeatureKey, type FeatureKind, type FeatureRef, FeatureRuntime, type FeatureRuntimeOptions, type FeatureScope, type FeatureSpec, type Features, type Fill, type Frequency, type FromSpecOptions, type Fundamentals, type HolidayRule, type IfNode, type IncomeKind, LSEExchangeCalendar, type LiveEvent, type Lot, type MacroAsset, MemoryFeatureCache, NYSEExchangeCalendar, type NextOpenFn, type OpenOrder, type Order, type PollingSchedule, type PollingStreamOptions, type Portfolio, type Position, type PositionId, type PriceMap, type Quote, type QuoteFeed, type RealizedEvent, type RebalanceConfig, type RebalanceFrequency, type RebalanceOrder, type ReturnMode, RoutingDataFeed, RoutingDataFeedError, type RoutingDataFeedRouteFn, type RoutingDataFeedRouteMap, RoutingQuoteFeed, RoutingQuoteFeedError, type RoutingQuoteFeedRouteFn, type RoutingQuoteFeedRouteMap, RoutingStreamingDataFeed, RoutingStreamingDataFeedError, type RoutingStreamingDataFeedRouteFn, type RoutingStreamingDataFeedRouteMap, type RuleNode, type RuleTreeState, type RunBacktestOptions, type RunLiveOptions, type Series, type Session, type SpecialClose, type SpecialOpen, type Strategy, type StreamingBar, type StreamingDataFeed, type SyntheticAsset, type TacticalFeatureKind, type TacticalFeatureSpec, type TacticalFeatures, type TacticalSpec, type TargetWeights, type TimeOfDay, type Tolerance, type WithStreamingSyntheticsOptions, applyFills, applyOrders, barsToSeries, collectBars, defineFeature, drawdown, ema, evaluateFeatureSpecs, evaluateRuleTree, index as features, fromSpec, getCalendar, getFeatureCompute, isRebalanceDay, paramsHash, periodKey, pollingStreamFromHistorical, positionsByAsset, reconcile, returnSeries, rsi, runBacktest, runLive, seriesAt, sma, index$
|
|
3980
|
+
export { type AdhocTimeOverrides, type AdjustOrder, type AllocateNode, type Asset, type AssetId, type AssetRef, BacktestExecutor, type BacktestExecutorOptions, type BacktestResult, type BacktestSnapshot, type Bar, type BarField, type Calendar, type CloseOrder, type Comparison, type ComparisonOp, type ComputeFn, Crypto24x7Calendar, type DataEvent, type DataFeed, type DateRange, type EquityAsset, type EventKind, ExchangeCalendar, type ExchangeName, type Executor, type FeatureCache, type FeatureKey, type FeatureKind, type FeatureRef, FeatureRuntime, type FeatureRuntimeOptions, type FeatureScope, type FeatureSpec, type Features, type Fill, type Frequency, type FromSpecOptions, type Fundamentals, type HolidayRule, type IfNode, type IncomeKind, LSEExchangeCalendar, type LiveEvent, type Lot, type LotSlice, type MacroAsset, MemoryFeatureCache, NYSEExchangeCalendar, type NextOpenFn, ORDINARY_OFFSET_CAP, type OpenOrder, type Order, type PollingSchedule, type PollingStreamOptions, type Portfolio, type Position, type PositionId, type PriceMap, type Quote, type QuoteFeed, type RealizeResult, type RealizedEvent, type RebalanceConfig, type RebalanceFrequency, type RebalanceOrder, type ReturnMode, RoutingDataFeed, RoutingDataFeedError, type RoutingDataFeedRouteFn, type RoutingDataFeedRouteMap, RoutingQuoteFeed, RoutingQuoteFeedError, type RoutingQuoteFeedRouteFn, type RoutingQuoteFeedRouteMap, RoutingStreamingDataFeed, RoutingStreamingDataFeedError, type RoutingStreamingDataFeedRouteFn, type RoutingStreamingDataFeedRouteMap, type RuleNode, type RuleTreeState, type RunBacktestOptions, type RunLiveOptions, type Series, type Session, type SpecialClose, type SpecialOpen, type Strategy, type StreamingBar, type StreamingDataFeed, type SyntheticAsset, type TacticalFeatureKind, type TacticalFeatureSpec, type TacticalFeatures, type TacticalSpec, type TargetWeights, type TaxRates, type TaxableIncome, type TimeOfDay, type Tolerance, type WithStreamingSyntheticsOptions, aggregateByYear, applyFills, applyOrders, barsToSeries, bucketByTerm, collectBars, computeTaxBill, crossOffset, defineFeature, drawdown, ema, evaluateFeatureSpecs, evaluateRuleTree, index$1 as features, fromSpec, getCalendar, getFeatureCompute, holdingPeriodDays, isLongTerm, isRebalanceDay, netWithinBucket, paramsHash, periodKey, pollingStreamFromHistorical, positionsByAsset, realize, reconcile, returnSeries, rsi, runBacktest, runLive, selectFIFO, selectHIFO, selectLIFO, selectMinTax, seriesAt, sma, index$2 as tactical, index as tax, volatility, withStreamingSynthetics, withSynthetics };
|