@fullstackcraftllc/floe 0.0.13 → 0.0.15
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/README.md +8 -8
- package/dist/client/FloeClient.d.ts +5 -1
- package/dist/client/FloeClient.js +54 -0
- package/dist/client/brokers/IBKRClient.d.ts +324 -0
- package/dist/client/brokers/IBKRClient.js +797 -0
- package/dist/client/brokers/TradierClient.js +7 -6
- package/dist/hedgeflow/charm.d.ts +23 -0
- package/dist/hedgeflow/charm.js +113 -0
- package/dist/hedgeflow/curve.d.ts +27 -0
- package/dist/hedgeflow/curve.js +315 -0
- package/dist/hedgeflow/index.d.ts +33 -0
- package/dist/hedgeflow/index.js +52 -0
- package/dist/hedgeflow/regime.d.ts +7 -0
- package/dist/hedgeflow/regime.js +99 -0
- package/dist/hedgeflow/types.d.ts +185 -0
- package/dist/hedgeflow/types.js +2 -0
- package/dist/impliedpdf/adjusted.d.ts +173 -0
- package/dist/impliedpdf/adjusted.js +500 -0
- package/dist/impliedpdf/index.d.ts +1 -0
- package/dist/impliedpdf/index.js +10 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +27 -1
- package/dist/iv/index.d.ts +52 -0
- package/dist/iv/index.js +287 -0
- package/dist/iv/types.d.ts +40 -0
- package/dist/iv/types.js +2 -0
- package/dist/pressure/grid.d.ts +14 -0
- package/dist/pressure/grid.js +220 -0
- package/dist/pressure/index.d.ts +5 -0
- package/dist/pressure/index.js +22 -0
- package/dist/pressure/ivpath.d.ts +31 -0
- package/dist/pressure/ivpath.js +304 -0
- package/dist/pressure/normalize.d.ts +6 -0
- package/dist/pressure/normalize.js +76 -0
- package/dist/pressure/regime.d.ts +7 -0
- package/dist/pressure/regime.js +99 -0
- package/dist/pressure/types.d.ts +182 -0
- package/dist/pressure/types.js +2 -0
- package/dist/rv/index.d.ts +26 -0
- package/dist/rv/index.js +81 -0
- package/dist/rv/types.d.ts +32 -0
- package/dist/rv/types.js +2 -0
- package/dist/utils/indexOptions.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PriceObservation, RealizedVolatilityResult } from './types';
|
|
2
|
+
export type { PriceObservation, RealizedVolatilityResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Compute annualized realized volatility from price observations.
|
|
5
|
+
*
|
|
6
|
+
* Uses the standard quadratic variation estimator:
|
|
7
|
+
*
|
|
8
|
+
* QV = Σᵢ (ln(Pᵢ / Pᵢ₋₁))²
|
|
9
|
+
*
|
|
10
|
+
* Annualized as:
|
|
11
|
+
*
|
|
12
|
+
* σ_realized = √(QV × (N_year / elapsed_time))
|
|
13
|
+
*
|
|
14
|
+
* This function is stateless and tick-based: pass all observed prices
|
|
15
|
+
* and it computes from the full set. No windowing, no sampling — the
|
|
16
|
+
* consumer decides what observations to include. As the session
|
|
17
|
+
* progresses and more ticks arrive, the estimate naturally converges.
|
|
18
|
+
*
|
|
19
|
+
* Observations are sorted by timestamp internally, so order does not
|
|
20
|
+
* matter. Duplicate timestamps are preserved (both contribute).
|
|
21
|
+
* Zero or negative prices are filtered out.
|
|
22
|
+
*
|
|
23
|
+
* @param observations - Array of { price, timestamp } observations
|
|
24
|
+
* @returns Realized volatility result with annualized RV
|
|
25
|
+
*/
|
|
26
|
+
export declare function computeRealizedVolatility(observations: PriceObservation[]): RealizedVolatilityResult;
|
package/dist/rv/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeRealizedVolatility = computeRealizedVolatility;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
/**
|
|
6
|
+
* Compute annualized realized volatility from price observations.
|
|
7
|
+
*
|
|
8
|
+
* Uses the standard quadratic variation estimator:
|
|
9
|
+
*
|
|
10
|
+
* QV = Σᵢ (ln(Pᵢ / Pᵢ₋₁))²
|
|
11
|
+
*
|
|
12
|
+
* Annualized as:
|
|
13
|
+
*
|
|
14
|
+
* σ_realized = √(QV × (N_year / elapsed_time))
|
|
15
|
+
*
|
|
16
|
+
* This function is stateless and tick-based: pass all observed prices
|
|
17
|
+
* and it computes from the full set. No windowing, no sampling — the
|
|
18
|
+
* consumer decides what observations to include. As the session
|
|
19
|
+
* progresses and more ticks arrive, the estimate naturally converges.
|
|
20
|
+
*
|
|
21
|
+
* Observations are sorted by timestamp internally, so order does not
|
|
22
|
+
* matter. Duplicate timestamps are preserved (both contribute).
|
|
23
|
+
* Zero or negative prices are filtered out.
|
|
24
|
+
*
|
|
25
|
+
* @param observations - Array of { price, timestamp } observations
|
|
26
|
+
* @returns Realized volatility result with annualized RV
|
|
27
|
+
*/
|
|
28
|
+
function computeRealizedVolatility(observations) {
|
|
29
|
+
// Filter invalid observations and sort by timestamp
|
|
30
|
+
const valid = observations
|
|
31
|
+
.filter(o => o.price > 0 && isFinite(o.price) && isFinite(o.timestamp))
|
|
32
|
+
.sort((a, b) => a.timestamp - b.timestamp);
|
|
33
|
+
if (valid.length < 2) {
|
|
34
|
+
return emptyResult(valid);
|
|
35
|
+
}
|
|
36
|
+
// Compute sum of squared log returns
|
|
37
|
+
let quadraticVariation = 0;
|
|
38
|
+
let numReturns = 0;
|
|
39
|
+
for (let i = 1; i < valid.length; i++) {
|
|
40
|
+
const logReturn = Math.log(valid[i].price / valid[i - 1].price);
|
|
41
|
+
quadraticVariation += logReturn * logReturn;
|
|
42
|
+
numReturns++;
|
|
43
|
+
}
|
|
44
|
+
// Elapsed time
|
|
45
|
+
const firstTs = valid[0].timestamp;
|
|
46
|
+
const lastTs = valid[valid.length - 1].timestamp;
|
|
47
|
+
const elapsedMs = lastTs - firstTs;
|
|
48
|
+
const elapsedMinutes = elapsedMs / 60000;
|
|
49
|
+
const elapsedYears = elapsedMs / types_1.MILLISECONDS_PER_YEAR;
|
|
50
|
+
// Guard against zero elapsed time
|
|
51
|
+
if (elapsedYears <= 0) {
|
|
52
|
+
return emptyResult(valid);
|
|
53
|
+
}
|
|
54
|
+
// Annualize: σ² = QV × (year / elapsed)
|
|
55
|
+
const annualizedVariance = quadraticVariation / elapsedYears;
|
|
56
|
+
const realizedVolatility = Math.sqrt(annualizedVariance);
|
|
57
|
+
return {
|
|
58
|
+
realizedVolatility,
|
|
59
|
+
annualizedVariance,
|
|
60
|
+
quadraticVariation,
|
|
61
|
+
numObservations: valid.length,
|
|
62
|
+
numReturns,
|
|
63
|
+
elapsedMinutes,
|
|
64
|
+
elapsedYears,
|
|
65
|
+
firstObservation: firstTs,
|
|
66
|
+
lastObservation: lastTs,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function emptyResult(valid) {
|
|
70
|
+
return {
|
|
71
|
+
realizedVolatility: 0,
|
|
72
|
+
annualizedVariance: 0,
|
|
73
|
+
quadraticVariation: 0,
|
|
74
|
+
numObservations: valid.length,
|
|
75
|
+
numReturns: 0,
|
|
76
|
+
elapsedMinutes: 0,
|
|
77
|
+
elapsedYears: 0,
|
|
78
|
+
firstObservation: valid.length > 0 ? valid[0].timestamp : 0,
|
|
79
|
+
lastObservation: valid.length > 0 ? valid[valid.length - 1].timestamp : 0,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single price observation for realized volatility computation.
|
|
3
|
+
*/
|
|
4
|
+
export interface PriceObservation {
|
|
5
|
+
/** Price of the underlying (mid, last, or whatever the consumer provides) */
|
|
6
|
+
price: number;
|
|
7
|
+
/** Timestamp in milliseconds */
|
|
8
|
+
timestamp: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Result of computing realized volatility from price observations.
|
|
12
|
+
*/
|
|
13
|
+
export interface RealizedVolatilityResult {
|
|
14
|
+
/** Annualized realized volatility as decimal (e.g. 0.18 = 18%) */
|
|
15
|
+
realizedVolatility: number;
|
|
16
|
+
/** Annualized realized variance */
|
|
17
|
+
annualizedVariance: number;
|
|
18
|
+
/** Raw quadratic variation: Σ (ln(Pᵢ/Pᵢ₋₁))² */
|
|
19
|
+
quadraticVariation: number;
|
|
20
|
+
/** Number of price observations used */
|
|
21
|
+
numObservations: number;
|
|
22
|
+
/** Number of returns computed (observations - 1) */
|
|
23
|
+
numReturns: number;
|
|
24
|
+
/** Elapsed time in minutes from first to last observation */
|
|
25
|
+
elapsedMinutes: number;
|
|
26
|
+
/** Elapsed time in years (for annualization reference) */
|
|
27
|
+
elapsedYears: number;
|
|
28
|
+
/** Timestamp of first observation */
|
|
29
|
+
firstObservation: number;
|
|
30
|
+
/** Timestamp of last observation */
|
|
31
|
+
lastObservation: number;
|
|
32
|
+
}
|
package/dist/rv/types.js
ADDED
|
@@ -9,8 +9,9 @@ exports.getUnderlyingFromOptionRoot = exports.OPTION_ROOT_TO_UNDERLYING = void 0
|
|
|
9
9
|
exports.OPTION_ROOT_TO_UNDERLYING = {
|
|
10
10
|
'SPXW': 'SPX', // SPX Weekly options
|
|
11
11
|
'SPXPM': 'SPX', // SPX PM-settled options
|
|
12
|
-
'NDXP': 'NDX', // NDX
|
|
12
|
+
'NDXP': 'NDX', // NDXP is Tradier's NDX options root
|
|
13
13
|
'RUTW': 'RUT', // RUT Weekly options
|
|
14
|
+
'DJXW': 'DJX', // DJX Weekly options
|
|
14
15
|
// Add more as needed
|
|
15
16
|
};
|
|
16
17
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fullstackcraftllc/floe",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "Production-ready options analytics toolkit. Normalize broker data structures and calculate Black-Scholes, Greeks, and exposures with a clean, type-safe API. Built for trading platforms and fintech applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|