@ebowwa/quant-rust 0.1.0

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.
Files changed (60) hide show
  1. package/README.md +161 -0
  2. package/bun-ffi.d.ts +54 -0
  3. package/dist/index.js +576 -0
  4. package/dist/src/index.d.ts +324 -0
  5. package/dist/src/index.d.ts.map +1 -0
  6. package/dist/types/index.d.ts +403 -0
  7. package/dist/types/index.d.ts.map +1 -0
  8. package/native/README.md +62 -0
  9. package/native/darwin-arm64/libquant_rust.dylib +0 -0
  10. package/package.json +70 -0
  11. package/scripts/postinstall.cjs +85 -0
  12. package/src/ffi.rs +496 -0
  13. package/src/index.ts +1073 -0
  14. package/src/indicators/ma.rs +222 -0
  15. package/src/indicators/mod.rs +18 -0
  16. package/src/indicators/momentum.rs +353 -0
  17. package/src/indicators/sr.rs +195 -0
  18. package/src/indicators/trend.rs +351 -0
  19. package/src/indicators/volatility.rs +270 -0
  20. package/src/indicators/volume.rs +213 -0
  21. package/src/lib.rs +130 -0
  22. package/src/patterns/breakout.rs +431 -0
  23. package/src/patterns/chart.rs +772 -0
  24. package/src/patterns/mod.rs +394 -0
  25. package/src/patterns/sr.rs +423 -0
  26. package/src/prediction/amm.rs +338 -0
  27. package/src/prediction/arbitrage.rs +230 -0
  28. package/src/prediction/calibration.rs +317 -0
  29. package/src/prediction/kelly.rs +232 -0
  30. package/src/prediction/lmsr.rs +194 -0
  31. package/src/prediction/mod.rs +59 -0
  32. package/src/prediction/odds.rs +229 -0
  33. package/src/prediction/pnl.rs +254 -0
  34. package/src/prediction/risk.rs +228 -0
  35. package/src/risk/beta.rs +257 -0
  36. package/src/risk/drawdown.rs +256 -0
  37. package/src/risk/leverage.rs +201 -0
  38. package/src/risk/mod.rs +388 -0
  39. package/src/risk/portfolio.rs +287 -0
  40. package/src/risk/ratios.rs +290 -0
  41. package/src/risk/sizing.rs +194 -0
  42. package/src/risk/var.rs +222 -0
  43. package/src/stats/cdf.rs +257 -0
  44. package/src/stats/correlation.rs +225 -0
  45. package/src/stats/distribution.rs +194 -0
  46. package/src/stats/hypothesis.rs +177 -0
  47. package/src/stats/matrix.rs +346 -0
  48. package/src/stats/mod.rs +257 -0
  49. package/src/stats/regression.rs +239 -0
  50. package/src/stats/rolling.rs +193 -0
  51. package/src/stats/timeseries.rs +263 -0
  52. package/src/types.rs +224 -0
  53. package/src/utils/mod.rs +215 -0
  54. package/src/utils/normalize.rs +192 -0
  55. package/src/utils/price.rs +167 -0
  56. package/src/utils/quantiles.rs +177 -0
  57. package/src/utils/returns.rs +158 -0
  58. package/src/utils/rolling.rs +97 -0
  59. package/src/utils/stats.rs +154 -0
  60. package/types/index.ts +513 -0
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+ # @ebowwa/quant-rust
2
+
3
+ High-performance quantitative finance library with Rust FFI bindings for Bun.
4
+
5
+ This package provides blazing-fast quantitative finance computations powered by Rust, accessible through a clean TypeScript API using Bun's FFI capabilities.
6
+
7
+ ## Features
8
+
9
+ - **Prediction Markets**: Kelly criterion, AMM calculations, LMSR pricing, arbitrage detection
10
+ - **Technical Indicators**: SMA, EMA, RSI, MACD, Bollinger Bands, ATR, and more
11
+ - **Risk Management**: VaR, CVaR, Sharpe ratio, Sortino ratio, drawdown analysis
12
+ - **Statistical Functions**: Mean, variance, standard deviation, correlation
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ bun add @ebowwa/quant-rust
18
+ ```
19
+
20
+ ## Requirements
21
+
22
+ - Bun >= 1.0.0
23
+ - Prebuilt binaries are included for:
24
+ - macOS (Apple Silicon/arm64)
25
+ - macOS (Intel/x64)
26
+ - Linux (x64)
27
+ - Windows (x64)
28
+
29
+ If no prebuilt binary is available for your platform, the library will fall back to the development build in `target/release/`.
30
+
31
+ ## Usage
32
+
33
+ ```typescript
34
+ import {
35
+ kellyCriterion,
36
+ detectArbitrage,
37
+ convertOdds,
38
+ mean,
39
+ sma,
40
+ ema,
41
+ rsi,
42
+ macd,
43
+ calculateVar,
44
+ calculateSharpeRatio,
45
+ } from "@ebowwa/quant-rust";
46
+
47
+ // Kelly criterion for position sizing
48
+ const kelly = kellyCriterion(0.6, 0.5, 1000);
49
+ console.log(kelly.kelly_fraction); // 0.2
50
+ console.log(kelly.full_bet_size); // 200
51
+
52
+ // Detect arbitrage in prediction markets
53
+ const arb = detectArbitrage(0.45, 0.45);
54
+ console.log(arb.has_arbitrage); // true (0.45 + 0.45 = 0.9 < 1)
55
+ console.log(arb.profit_per_share); // 0.1 (10 cents per share)
56
+
57
+ // Convert between odds formats
58
+ const odds = convertOdds(0.5, "probability");
59
+ console.log(odds.decimal_odds); // 2.0
60
+ console.log(odds.american_odds); // 100
61
+
62
+ // Statistical functions
63
+ const avg = mean([1, 2, 3, 4, 5]);
64
+ console.log(avg); // 3
65
+
66
+ // Technical indicators
67
+ const smaResult = sma([1, 2, 3, 4, 5], 3);
68
+ console.log(smaResult); // [2, 3, 4]
69
+
70
+ const rsiResult = rsi([10, 11, 12, 11, 10, 9, 8, 9, 10, 11, 12, 13, 14, 15, 16], 14);
71
+ console.log(rsiResult); // [71.43...]
72
+
73
+ // Risk metrics
74
+ const returns = [0.01, 0.02, -0.01, 0.03, -0.02, 0.01, 0.02, 0.01, -0.01, 0.02];
75
+ const varResult = calculateVar(returns, 0.95);
76
+ console.log(varResult.var); // Value at Risk at 95% confidence
77
+
78
+ const sharpe = calculateSharpeRatio(returns, 0.04, 252);
79
+ console.log(sharpe.annualized_sharpe); // Annualized Sharpe ratio
80
+ ```
81
+
82
+ ## API Reference
83
+
84
+ ### Prediction Market Functions
85
+
86
+ #### `kellyCriterion(yourProbability, marketPrice, bankroll)`
87
+ Calculate optimal position sizing using the Kelly criterion.
88
+
89
+ #### `detectArbitrage(yesPrice, noPrice)`
90
+ Detect arbitrage opportunities in binary prediction markets.
91
+
92
+ #### `convertOdds(value, fromType)`
93
+ Convert between probability, decimal odds, and American odds.
94
+
95
+ #### `ammCalculateCost(poolYes, poolNo, buyYes, shares)`
96
+ Calculate cost to buy shares from a constant-product AMM.
97
+
98
+ #### `lmsrPrice(yesShares, noShares, b)`
99
+ Calculate LMSR prices for a prediction market.
100
+
101
+ ### Statistical Functions
102
+
103
+ #### `mean(data)`
104
+ Calculate the arithmetic mean.
105
+
106
+ #### `stdDev(data)`
107
+ Calculate the standard deviation.
108
+
109
+ #### `variance(data)`
110
+ Calculate the variance.
111
+
112
+ #### `correlation(x, y)`
113
+ Calculate Pearson correlation coefficient.
114
+
115
+ ### Technical Indicators
116
+
117
+ #### `sma(prices, period)`
118
+ Simple Moving Average.
119
+
120
+ #### `ema(prices, period)`
121
+ Exponential Moving Average.
122
+
123
+ #### `rsi(prices, period)`
124
+ Relative Strength Index.
125
+
126
+ #### `macd(prices, fastPeriod, slowPeriod, signalPeriod)`
127
+ MACD (Moving Average Convergence Divergence).
128
+
129
+ ### Risk Management
130
+
131
+ #### `calculateVar(returns, confidenceLevel)`
132
+ Value at Risk calculation.
133
+
134
+ #### `calculateDrawdown(equityCurve)`
135
+ Drawdown analysis.
136
+
137
+ #### `calculateSharpeRatio(returns, riskFreeRate, periodsPerYear)`
138
+ Sharpe ratio calculation.
139
+
140
+ #### `calculateSortinoRatio(returns, riskFreeRate, periodsPerYear)`
141
+ Sortino ratio (downside deviation only).
142
+
143
+ ## Building from Source
144
+
145
+ If you need to build the native library from source:
146
+
147
+ ```bash
148
+ # Navigate to the package directory
149
+ cd node_modules/@ebowwa/quant-rust
150
+
151
+ # Build the Rust library
152
+ cargo build --release
153
+ ```
154
+
155
+ ## License
156
+
157
+ MIT
158
+
159
+ ## Repository
160
+
161
+ https://github.com/ebowwa/codespaces/tree/main/packages/src/quant-rust
package/bun-ffi.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Type augmentation for bun:ffi
3
+ *
4
+ * This file provides additional type definitions for FFIType that may not be
5
+ * included in the official bun-types package.
6
+ */
7
+
8
+ declare module "bun:ffi" {
9
+ export const FFIType: {
10
+ bool: FFIEnum;
11
+ c_int: FFIEnum;
12
+ c_uint: FFIEnum;
13
+ char: FFIEnum;
14
+ "char*": FFIEnum;
15
+ double: FFIEnum;
16
+ f32: FFIEnum;
17
+ f64: FFIEnum;
18
+ float: FFIEnum;
19
+ i16: FFIEnum;
20
+ i32: FFIEnum;
21
+ i64: FFIEnum;
22
+ i8: FFIEnum;
23
+ int: FFIEnum;
24
+ int16_t: FFIEnum;
25
+ int32_t: FFIEnum;
26
+ int64_t: FFIEnum;
27
+ int8_t: FFIEnum;
28
+ isize: FFIEnum;
29
+ u16: FFIEnum;
30
+ u32: FFIEnum;
31
+ u64: FFIEnum;
32
+ u8: FFIEnum;
33
+ uint16_t: FFIEnum;
34
+ uint32_t: FFIEnum;
35
+ uint64_t: FFIEnum;
36
+ uint8_t: FFIEnum;
37
+ usize: FFIEnum;
38
+ "void*": FFIEnum;
39
+ ptr: FFIEnum;
40
+ pointer: FFIEnum;
41
+ void: FFIEnum;
42
+ cstring: FFIEnum;
43
+ i64_fast: FFIEnum;
44
+ u64_fast: FFIEnum;
45
+ function: FFIEnum;
46
+ callback: FFIEnum;
47
+ fn: FFIEnum;
48
+ napi_env: FFIEnum;
49
+ napi_value: FFIEnum;
50
+ buffer: FFIEnum;
51
+ };
52
+
53
+ type FFIEnum = string | number;
54
+ }