@gabriel3615/ta_analysis
Version:
stock ta analysis
123 lines (122 loc) • 3.49 kB
JavaScript
/**
* 集成分析配置
* 统一管理所有集成相关的配置参数
*/
// 默认配置
export const DEFAULT_INTEGRATION_CONFIG = {
weights: {
chip: 0.1,
pattern: 0.5,
volume: 0.2,
bbsr: 0.1,
// 附加权重
structure: 0.3,
supplyDemand: 0.1,
range: 0.2,
trendline: 0.1,
plugins: {},
},
thresholds: {
scoreLong: 15,
scoreShort: -15,
volatilityAdjustedScoreStrong: 60,
volatilityAdjustedScoreModerate: 40,
volatilityAdjustedScoreWeak: 20,
chipDirectionThreshold: 20,
},
timeframes: {
weekly: {
lookbackDays: 365,
},
daily: {
lookbackDays: 365,
},
hourly: {
lookbackDays: 60,
},
},
consistency: {
timeframeWeights: { weekly: 0.4, daily: 0.4, '1hour': 0.2 },
structureWeight: 0.2,
trendlineWeight: 0.2,
},
options: {
enableFallbackStrategy: true,
logLevel: 'normal',
outputFormat: 'both',
usePluginsOnly: false,
},
};
// 配置更新函数
export function updateIntegrationConfig(updates) {
return {
...DEFAULT_INTEGRATION_CONFIG,
...updates,
weights: {
...DEFAULT_INTEGRATION_CONFIG.weights,
...updates.weights,
},
thresholds: {
...DEFAULT_INTEGRATION_CONFIG.thresholds,
...updates.thresholds,
},
timeframes: {
...DEFAULT_INTEGRATION_CONFIG.timeframes,
...updates.timeframes,
},
consistency: {
...DEFAULT_INTEGRATION_CONFIG.consistency,
...updates.consistency,
timeframeWeights: {
...DEFAULT_INTEGRATION_CONFIG.consistency.timeframeWeights,
...updates.consistency?.timeframeWeights,
},
},
options: {
...DEFAULT_INTEGRATION_CONFIG.options,
...updates.options,
},
};
}
// 权重归一化函数
export function normalizeWeights(weights) {
const totalWeight = weights.chip + weights.pattern + weights.volume + weights.bbsr;
if (totalWeight === 0) {
throw new Error('权重总和不能为0');
}
return {
chip: weights.chip / totalWeight,
pattern: weights.pattern / totalWeight,
volume: weights.volume / totalWeight,
bbsr: weights.bbsr / totalWeight,
// 附加权重保持不变
structure: weights.structure,
supplyDemand: weights.supplyDemand,
range: weights.range,
trendline: weights.trendline,
};
}
// 验证配置函数
export function validateConfig(config) {
const errors = [];
// 检查权重
const totalMainWeight = config.weights.chip +
config.weights.pattern +
config.weights.volume +
config.weights.bbsr;
if (totalMainWeight <= 0) {
errors.push('主要权重(chip+pattern+volume+bbsr)总和必须大于0');
}
// 检查阈值
if (config.thresholds.scoreLong <= config.thresholds.scoreShort) {
errors.push('做多阈值必须大于做空阈值');
}
// 检查时间范围
if (config.timeframes.weekly.lookbackDays < config.timeframes.daily.lookbackDays) {
errors.push('周线回看天数应该大于等于日线回看天数');
}
return {
valid: errors.length === 0,
errors,
};
}