fixed up types and working on utils lib

This commit is contained in:
Boki 2025-06-19 09:47:57 -04:00
parent 25d9f2dd85
commit da75979574
17 changed files with 1093 additions and 901 deletions

View file

@ -25,98 +25,40 @@ import {
* Organized into logical categories for easy use and maintenance.
*/
// Re-export standardized types
export type { OHLCV, OHLCVWithMetadata } from '@stock-bot/types';
// Legacy interface for backward compatibility - prefer OHLCV from @stock-bot/types
/** @deprecated Use OHLCV from @stock-bot/types instead */
export interface OHLCVData {
open: number;
high: number;
low: number;
close: number;
volume: number;
timestamp: Date;
}
export interface PriceData {
price: number;
timestamp: Date;
}
// Financial calculation result interfaces
export interface PortfolioMetrics {
totalValue: number;
totalReturn: number;
totalReturnPercent: number;
dailyReturn: number;
dailyReturnPercent: number;
maxDrawdown: number;
sharpeRatio: number;
beta: number;
alpha: number;
volatility: number;
}
export interface RiskMetrics {
var95: number; // Value at Risk 95%
var99: number; // Value at Risk 99%
cvar95: number; // Conditional VaR 95%
maxDrawdown: number;
volatility: number;
downside_deviation: number;
calmar_ratio: number;
sortino_ratio: number;
beta: number;
alpha: number;
sharpeRatio: number;
treynorRatio: number;
trackingError: number;
informationRatio: number;
}
export interface TechnicalIndicators {
sma: number[];
ema: number[];
rsi: number[];
macd: { macd: number[]; signal: number[]; histogram: number[] };
bollinger: { upper: number[]; middle: number[]; lower: number[] };
atr: number[];
stochastic: { k: number[]; d: number[] };
williams_r: number[];
cci: number[];
momentum: number[];
roc: number[];
}
// Additional interfaces for new functionality
export interface TradeExecution {
entry: number;
exit: number;
peak?: number;
trough?: number;
volume: number;
timestamp: Date;
}
export interface MarketData {
price: number;
volume: number;
timestamp: Date;
bid?: number;
ask?: number;
bidSize?: number;
askSize?: number;
}
export interface BacktestResults {
trades: TradeExecution[];
equityCurve: Array<{ value: number; date: Date }>;
performance: PortfolioMetrics;
riskMetrics: RiskMetrics;
drawdownAnalysis: any; // Import from performance-metrics
}
// Re-export all standardized types from @stock-bot/types
export type {
OHLCV,
OHLCVWithMetadata,
PortfolioPosition,
PortfolioAnalysis,
AssetAllocation,
TradeExecution,
TradePerformance,
RiskMetrics,
DrawdownAnalysis,
ReturnAnalysis,
OptionParameters,
OptionPricing,
GreeksCalculation,
MarketData,
LiquidityMetrics,
MarketRegime,
PositionSizeParams,
KellyParams,
BalanceSheet,
IncomeStatement,
CashFlowStatement,
TechnicalIndicators,
CorrelationResult,
CorrelationMatrix,
VolatilityEstimates,
GARCHParameters,
BacktestResults,
HasClose,
HasOHLC,
HasVolume,
HasTimestamp
} from '@stock-bot/types';
// Export all calculation functions
export * from './basic-calculations';
@ -132,7 +74,7 @@ export * from './correlation-analysis';
// Convenience function to calculate all technical indicators at once
export function calculateAllTechnicalIndicators(
ohlcv: OHLCVData[],
ohlcv: OHLCV[],
periods: { sma?: number; ema?: number; rsi?: number; atr?: number } = {}
): TechnicalIndicators {
const {
@ -166,7 +108,7 @@ export function analyzePortfolio(
benchmarkReturns?: number[],
riskFreeRate: number = 0.02
): {
performance: PortfolioMetrics;
performance: PortfolioAnalysis;
risk: RiskMetrics;
trades?: any;
drawdown?: any;