goldenChat base source add

This commit is contained in:
aidev
2026-05-23 15:11:48 +09:00
commit a4ea7762b5
2081 changed files with 1155760 additions and 0 deletions
@@ -0,0 +1,104 @@
/*
* SPDX-License-Identifier: MIT
*/
package ta4jexamples.analysis.elliottwave.demo;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.ta4j.core.BarSeries;
import org.ta4j.core.indicators.elliott.ElliottAnalysisResult;
import org.ta4j.core.indicators.elliott.ElliottDegree;
import org.ta4j.core.indicators.elliott.ElliottScenario;
import org.ta4j.core.indicators.elliott.ElliottWaveAnalysisRunner;
import org.ta4j.core.indicators.elliott.ElliottWaveAnalysisResult;
import org.ta4j.core.indicators.elliott.confidence.ConfidenceFactorResult;
import org.ta4j.core.indicators.elliott.confidence.ElliottConfidenceBreakdown;
import org.ta4j.core.indicators.elliott.swing.AdaptiveZigZagConfig;
import org.ta4j.core.indicators.elliott.swing.CompositeSwingDetector;
import org.ta4j.core.indicators.elliott.swing.MinMagnitudeSwingFilter;
import org.ta4j.core.indicators.elliott.swing.SwingDetector;
import org.ta4j.core.indicators.elliott.swing.SwingDetectors;
import ta4jexamples.analysis.elliottwave.ElliottWaveIndicatorSuiteDemo;
import ta4jexamples.analysis.elliottwave.support.OssifiedElliottWaveSeriesLoader;
/**
* Demonstrates adaptive ZigZag and composite swing detection for Elliott Wave
* analysis.
*
* @since 0.22.2
*/
public class ElliottWaveAdaptiveSwingAnalysis {
private static final Logger LOG = LogManager.getLogger(ElliottWaveAdaptiveSwingAnalysis.class);
private static final String DEFAULT_OHLCV_RESOURCE = "Coinbase-BTC-USD-PT1D-20230616_20231011.json";
/**
* Runs the adaptive swing analysis demo.
*
* @param args command-line arguments (unused)
*/
public static void main(String[] args) {
BarSeries series = loadSeries();
if (series == null || series.isEmpty()) {
LOG.error("No data available for adaptive swing analysis");
return;
}
ElliottDegree baseDegree = ElliottWaveIndicatorSuiteDemo.autoSelectDegree(series);
AdaptiveZigZagConfig config = new AdaptiveZigZagConfig(14, 1.0, 0.0, 0.0, 3);
SwingDetector detector = SwingDetectors.composite(CompositeSwingDetector.Policy.OR, SwingDetectors.fractal(5),
SwingDetectors.adaptiveZigZag(config));
ElliottWaveAnalysisRunner analyzer = ElliottWaveAnalysisRunner.builder()
.degree(baseDegree)
.higherDegrees(1)
.lowerDegrees(1)
.swingDetector(detector)
.swingFilter(new MinMagnitudeSwingFilter(0.2))
.build();
ElliottWaveAnalysisResult analysisResult = analyzer.analyze(series);
ElliottAnalysisResult result = analysisResult.analysisFor(baseDegree).orElseThrow().analysis();
LOG.info("Adaptive swing analysis complete. Trend bias: {}", result.trendBias().direction());
result.scenarios().base().ifPresent(base -> logScenario("BASE", base, result));
List<ElliottScenario> alternatives = result.scenarios().alternatives();
for (int i = 0; i < Math.min(2, alternatives.size()); i++) {
logScenario("ALT " + (i + 1), alternatives.get(i), result);
}
}
/**
* Logs scenario-level confidence breakdown details.
*
* @param label scenario label
* @param scenario scenario to log
* @param result analysis result containing factor breakdowns
*/
private static void logScenario(String label, ElliottScenario scenario, ElliottAnalysisResult result) {
LOG.info("{} SCENARIO: {} ({}) - confidence={}%%", label, scenario.currentPhase(), scenario.type(),
String.format("%.1f", scenario.confidence().asPercentage()));
ElliottConfidenceBreakdown breakdown = result.breakdownFor(scenario).orElse(null);
if (breakdown == null) {
return;
}
for (ConfidenceFactorResult factor : breakdown.factors()) {
LOG.info(" Factor: {} score={} weight={} diagnostics={}", factor.name(),
String.format("%.2f", factor.score().doubleValue()), String.format("%.2f", factor.weight()),
factor.diagnostics());
}
}
/**
* Loads the ossified BTC-USD dataset from classpath resources.
*
* @return loaded bar series, or {@code null} if unavailable
*/
private static BarSeries loadSeries() {
return OssifiedElliottWaveSeriesLoader.loadSeries(ElliottWaveAdaptiveSwingAnalysis.class,
DEFAULT_OHLCV_RESOURCE, "BTC-USD_PT1D@Coinbase (ossified)", LOG);
}
}
@@ -0,0 +1,101 @@
/*
* SPDX-License-Identifier: MIT
*/
package ta4jexamples.analysis.elliottwave.demo;
import java.util.List;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.ta4j.core.BarSeries;
import org.ta4j.core.indicators.elliott.ElliottDegree;
import org.ta4j.core.indicators.elliott.ElliottScenario;
import org.ta4j.core.indicators.elliott.ElliottWaveAnalysisRunner;
import org.ta4j.core.indicators.elliott.ElliottWaveAnalysisResult;
import org.ta4j.core.indicators.elliott.swing.AdaptiveZigZagConfig;
import org.ta4j.core.indicators.elliott.swing.SwingDetectors;
import ta4jexamples.analysis.elliottwave.ElliottWaveIndicatorSuiteDemo;
import ta4jexamples.analysis.elliottwave.support.OssifiedElliottWaveSeriesLoader;
/**
* Demonstrates multi-degree Elliott Wave analysis, validating scenarios across
* neighboring degrees and re-ranking base-degree outcomes.
*
* <p>
* This demo uses an ossified BTC-USD dataset from classpath resources and runs
* an auto-selected base-degree analysis, plus one supporting degree higher and
* lower.
*
* @since 0.22.4
*/
public class ElliottWaveMultiDegreeAnalysisDemo {
private static final Logger LOG = LogManager.getLogger(ElliottWaveMultiDegreeAnalysisDemo.class);
private static final String DEFAULT_OHLCV_RESOURCE = "Coinbase-BTC-USD-PT1D-20230616_20231020.json";
public static void main(String[] args) {
BarSeries series = loadSeries(DEFAULT_OHLCV_RESOURCE);
if (series == null || series.isEmpty()) {
LOG.error("No series available for multi-degree Elliott Wave analysis");
return;
}
ElliottDegree baseDegree = ElliottWaveIndicatorSuiteDemo.autoSelectDegree(series);
ElliottWaveAnalysisRunner analyzer = ElliottWaveAnalysisRunner.builder()
.degree(baseDegree)
.higherDegrees(1)
.lowerDegrees(1)
.swingDetector(SwingDetectors.adaptiveZigZag(new AdaptiveZigZagConfig(14, 1.0, 0.0, 0.0, 1)))
.build();
ElliottWaveAnalysisResult result = analyzer.analyze(series);
LOG.info("Auto-selected base degree: {}", baseDegree);
for (ElliottWaveAnalysisResult.DegreeAnalysis analysis : result.analyses()) {
LOG.info("{} Degree {}: bars={} duration={} historyFit={} trendBias={}", series.getName(),
analysis.degree(), analysis.barCount(), analysis.barDuration(),
String.format("%.2f", analysis.historyFitScore()), analysis.analysis().trendBias().direction());
analysis.analysis().scenarios().base().ifPresent(base -> logScenario(" Base", base));
}
Optional<ElliottWaveAnalysisResult.BaseScenarioAssessment> recommended = result.recommendedScenario();
if (recommended.isEmpty()) {
LOG.warn("No base-degree scenarios were produced");
return;
}
ElliottWaveAnalysisResult.BaseScenarioAssessment assessment = recommended.orElseThrow();
ElliottScenario scenario = assessment.scenario();
LOG.info("Recommended base scenario: id={} phase={} type={} confidence={} crossDegree={} composite={}",
scenario.id(), scenario.currentPhase(), scenario.type(),
String.format("%.2f", assessment.confidenceScore()),
String.format("%.2f", assessment.crossDegreeScore()),
String.format("%.2f", assessment.compositeScore()));
List<ElliottWaveAnalysisResult.SupportingScenarioMatch> matches = assessment.supportingMatches();
for (ElliottWaveAnalysisResult.SupportingScenarioMatch match : matches) {
LOG.info(" Match {}: scenarioId={} compat={} weightedCompat={} historyFit={}", match.degree(),
match.scenarioId(), String.format("%.2f", match.compatibilityScore()),
String.format("%.2f", match.weightedCompatibility()),
String.format("%.2f", match.historyFitScore()));
}
for (String note : result.notes()) {
LOG.info("Note: {}", note);
}
}
private static void logScenario(final String label, final ElliottScenario scenario) {
LOG.info("{} scenarioId={} phase={} type={} confidence={} direction={}", label, scenario.id(),
scenario.currentPhase(), scenario.type(), String.format("%.1f", scenario.confidence().asPercentage()),
scenario.hasKnownDirection() ? (scenario.isBullish() ? "bullish" : "bearish") : "unknown");
}
private static BarSeries loadSeries(final String resource) {
return OssifiedElliottWaveSeriesLoader.loadSeries(ElliottWaveMultiDegreeAnalysisDemo.class, resource,
"BTC-USD_PT1D@Coinbase (ossified)", LOG);
}
}
@@ -0,0 +1,100 @@
/*
* SPDX-License-Identifier: MIT
*/
package ta4jexamples.analysis.elliottwave.demo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.ta4j.core.BarSeries;
import org.ta4j.core.indicators.elliott.ElliottAnalysisResult;
import org.ta4j.core.indicators.elliott.ElliottDegree;
import org.ta4j.core.indicators.elliott.ElliottScenario;
import org.ta4j.core.indicators.elliott.ElliottWaveAnalysisRunner;
import org.ta4j.core.indicators.elliott.ElliottWaveAnalysisResult;
import org.ta4j.core.indicators.elliott.confidence.ConfidenceProfiles;
import org.ta4j.core.indicators.elliott.swing.SwingDetectors;
import ta4jexamples.analysis.elliottwave.ElliottWaveIndicatorSuiteDemo;
import ta4jexamples.analysis.elliottwave.support.OssifiedElliottWaveSeriesLoader;
/**
* Demonstrates how pattern-specific confidence profiles influence scenario
* ranking.
*
* @since 0.22.2
*/
public class ElliottWavePatternProfileDemo {
private static final Logger LOG = LogManager.getLogger(ElliottWavePatternProfileDemo.class);
private static final String DEFAULT_OHLCV_RESOURCE = "Coinbase-BTC-USD-PT1D-20230616_20231011.json";
/**
* Runs the pattern profile comparison demo.
*
* @param args command-line arguments (unused)
*/
public static void main(String[] args) {
BarSeries series = loadSeries();
if (series == null || series.isEmpty()) {
LOG.error("No data available for pattern profile demo");
return;
}
ElliottDegree baseDegree = ElliottWaveIndicatorSuiteDemo.autoSelectDegree(series);
ElliottWaveAnalysisRunner defaultAnalyzer = ElliottWaveAnalysisRunner.builder()
.degree(baseDegree)
.higherDegrees(1)
.lowerDegrees(1)
.swingDetector(SwingDetectors.fractal(5))
.confidenceModelFactory(ConfidenceProfiles::defaultModel)
.build();
ElliottWaveAnalysisRunner patternAwareAnalyzer = ElliottWaveAnalysisRunner.builder()
.degree(baseDegree)
.higherDegrees(1)
.lowerDegrees(1)
.swingDetector(SwingDetectors.fractal(5))
.confidenceModelFactory(ConfidenceProfiles::patternAwareModel)
.build();
ElliottWaveAnalysisResult defaultSnapshot = defaultAnalyzer.analyze(series);
ElliottWaveAnalysisResult patternSnapshot = patternAwareAnalyzer.analyze(series);
ElliottAnalysisResult defaultResult = defaultSnapshot.analysisFor(baseDegree)
.orElseThrow(() -> new IllegalStateException("No base-degree analysis in default snapshot"))
.analysis();
ElliottAnalysisResult patternResult = patternSnapshot.analysisFor(baseDegree)
.orElseThrow(() -> new IllegalStateException("No base-degree analysis in pattern-aware snapshot"))
.analysis();
logBaseScenario("Default profile", defaultResult);
logBaseScenario("Pattern-aware profile", patternResult);
}
/**
* Logs the base scenario for the provided analysis result.
*
* @param label label for the output
* @param result analysis result to inspect
*/
private static void logBaseScenario(String label, ElliottAnalysisResult result) {
ElliottScenario base = result.scenarios().base().orElse(null);
if (base == null) {
LOG.info("{}: No scenarios available", label);
return;
}
LOG.info("{}: {} ({}) confidence={}%%", label, base.currentPhase(), base.type(),
String.format("%.1f", base.confidence().asPercentage()));
}
/**
* Loads the ossified BTC-USD dataset from classpath resources.
*
* @return loaded bar series, or {@code null} if unavailable
*/
private static BarSeries loadSeries() {
return OssifiedElliottWaveSeriesLoader.loadSeries(ElliottWavePatternProfileDemo.class, DEFAULT_OHLCV_RESOURCE,
"BTC-USD_PT1D@Coinbase (ossified)", LOG);
}
}