mirror of
https://github.com/db9979/wibosim.git
synced 2026-12-06 13:34:09 +01:00
Erdgas (GAS) als neuer Rohstoff mit Saison und Gasspeicher
- Instrument GAS (Erdgas, 1 MWh): Heizsaison, Speicherfüllstand als Makrogröße, Gasmarkt-Ereignisse, schwache Ölkopplung - Nachrichtenthema gas (Regeln und LLM-Schema), Gaspreis nicht mehr beim Öl - Wirkung auf Inflation, BIP, Branchen und Bevölkerung (Heizkosten) - Gesetze Gaspreisbremse und Gasspeicherpflicht, Szenario Energiekrise mit Gas - Client: Kurs- und Makroansicht, Hilfe, Glossar, Handbuchkapitel Energie, Admin-Ereignis - Alte Spielstände laden ohne GAS sauber, Tests in gas.test.js - Balancing-Bericht mit GAS und Saisonkurve, Doku in BALANCING.md, API.md, README Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
This commit is contained in:
22 files changed
+749
-99
No files matched your search
@@ -101,6 +101,8 @@ function classify(n) {
|
||||
if (id.startsWith('earn-')) return 'Quartalszahlen';
|
||||
if (id.startsWith('warn-')) return 'Gewinnwarnung';
|
||||
if (id.startsWith('oil-')) return t.includes('Petrolia') ? 'Ölkartell' : 'Szenario-Ereignis';
|
||||
if (id.startsWith('gasrep-')) return null;
|
||||
if (id.startsWith('gas-')) return 'Gasmarkt-Ereignis';
|
||||
if (id.startsWith('chain-')) return 'Lieferketten-Kaskade';
|
||||
if (id.startsWith('wahl-')) return 'Wahl';
|
||||
if (id.startsWith('mv-end-')) return t.includes('erfolgreich') ? 'Misstrauensvotum erfolgreich' : 'Misstrauensvotum gescheitert';
|
||||
@@ -316,7 +318,7 @@ function makeStrategies(g, players, ctx) {
|
||||
// --- Zufallshändler: ~10 Orders je Handelstag, 5–15 % des Depots, auch short
|
||||
for (const p of P('random')) {
|
||||
if (Math.random() > ctx.randomPerTick) continue;
|
||||
const sym = Math.random() < 0.8 ? stocks[Math.floor(Math.random() * stocks.length)] : ['WIB2', 'WIB10', 'OEL', 'GOLD', 'USD'][Math.floor(Math.random() * 5)];
|
||||
const sym = Math.random() < 0.8 ? stocks[Math.floor(Math.random() * stocks.length)] : ['WIB2', 'WIB10', 'OEL', 'GAS', 'GOLD', 'USD'][Math.floor(Math.random() * 6)];
|
||||
const s = S(sym);
|
||||
if (g.ex.status(s) !== 'continuous') continue;
|
||||
const qty = (eq(p) * (0.05 + Math.random() * 0.1)) / s.last;
|
||||
@@ -393,6 +395,8 @@ async function seasonJob(job, g, clock, { simulatedNews, settings }) {
|
||||
const yields = { WIB2: [], WIB10: [] };
|
||||
const macroPath = [];
|
||||
const budgetPath = [];
|
||||
// Erdgas: Saisonkurve je Spielmonat (Kurs, innerer Wert, Speicherfüllstand)
|
||||
const gasByMonth = Array.from({ length: 12 }, () => ({ n: 0, lnPx: 0, lnFv: 0, fill: 0, norm: 0 }));
|
||||
const tickMs = { open: [], closed: [] };
|
||||
const closes = ctx.closes;
|
||||
let lastDay = g.day;
|
||||
@@ -416,6 +420,11 @@ async function seasonJob(job, g, clock, { simulatedNews, settings }) {
|
||||
const m = g.macro, b = g.gov.budget;
|
||||
macroPath.push({ day: g.day, rate: m.rate, infl: m.inflation, gdp: m.gdp, u: m.unemployment, regime: m.regime, sent: m.sentiment, oilFv: g.stocks.get('OEL').fv });
|
||||
budgetPath.push({ day: g.day, debt: b.debt, deficit: b.deficit, rating: b.rating, crisis: b.crisis, rp: g.gov.riskPremium() });
|
||||
const gs = g.stocks.get('GAS');
|
||||
if (gs) {
|
||||
const gi = g.assets.gasInfo(0), mi = MONTH_IDX[gi.month], x = gasByMonth[mi];
|
||||
x.n++; x.lnPx += Math.log(gs.last); x.lnFv += Math.log(gs.fv); x.fill += gi.storage; x.norm += gi.norm;
|
||||
}
|
||||
};
|
||||
|
||||
while (clock.t < endAt) {
|
||||
@@ -486,7 +495,7 @@ async function seasonJob(job, g, clock, { simulatedNews, settings }) {
|
||||
events, lawStats, halts, marketHalts, strategies, errors: strat?.errors ?? {}, insiderLog: ctx.insiderLog,
|
||||
macro: { first: macroPath[0], last: macroPath.at(-1), rateMin: Math.min(...macroPath.map((x) => x.rate)), rateMax: Math.max(...macroPath.map((x) => x.rate)), inflMax: Math.max(...macroPath.map((x) => x.infl)), inflMin: Math.min(...macroPath.map((x) => x.infl)), gdpMin: Math.min(...macroPath.map((x) => x.gdp)), gdpMax: Math.max(...macroPath.map((x) => x.gdp)), recessionDays: macroPath.filter((x) => x.regime === 'recession').length },
|
||||
budget: { first: budgetPath[0], last: budgetPath.at(-1), debtMax: Math.max(...budgetPath.map((x) => x.debt)), crisisDays: budgetPath.filter((x) => x.crisis).length, ratings: [...new Set(budgetPath.map((x) => x.rating))], worst: worstRating(budgetPath.map((x) => x.rating)), days: budgetPath.length },
|
||||
seasons: seasonsSeen.length + 1,
|
||||
seasons: seasonsSeen.length + 1, gasByMonth,
|
||||
tick: { open: tickStats(sortT(tickMs.open)), closed: tickStats(sortT(tickMs.closed)) },
|
||||
players: g.players.size,
|
||||
};
|
||||
@@ -498,7 +507,7 @@ async function effectsJob(job, g, clock, { analyze }) {
|
||||
for (let i = 0; i < 400 && g.market.phase !== 'continuous'; i++) step(1);
|
||||
step(5);
|
||||
const out = [];
|
||||
const watch = ['OEL', 'GOLD', 'USD', 'WIB10', 'WIB2', 'AEGS', 'HLIO', 'VOLT', 'RHBK', 'NVLT', 'STHL', 'KRMA'];
|
||||
const watch = ['OEL', 'GAS', 'GOLD', 'USD', 'WIB10', 'WIB2', 'AEGS', 'HLIO', 'VOLT', 'RHBK', 'NVLT', 'STHL', 'KRMA'];
|
||||
for (const h of job.headlines) {
|
||||
const a = analyze(h.title);
|
||||
const mk = (real, k) => ({ id: `eff-${k}-${Math.random()}`, title: h.title, source: 'Test', real, sentiment: a.sentiment, sectors: a.sectors, ts: clock.t, analysis: { by: 'regeln', topics: a.topics, sectorImpact: a.sectorImpact, strength: a.strength, reasons: a.reasons } });
|
||||
@@ -547,10 +556,14 @@ function runPool(jobs, n, onDone) {
|
||||
});
|
||||
}
|
||||
|
||||
const MONTH_NAMES = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
|
||||
const MONTH_IDX = Object.fromEntries(MONTH_NAMES.map((m, i) => [m, i]));
|
||||
const HEADLINES = [
|
||||
{ title: 'Ölpreis springt nach OPEC-Förderkürzung auf Jahreshoch', note: 'starke Öl-Meldung' },
|
||||
{ title: 'Krieg im Nahen Osten eskaliert – Ölpreis steigt drastisch', note: 'Krieg + Öl' },
|
||||
{ title: 'OPEC weitet Fördermenge deutlich aus – Ölpreis fällt', note: 'Öl billiger' },
|
||||
{ title: 'Gasspeicher leeren sich schneller als erwartet – Gaspreis steigt kräftig', note: 'Gas teurer' },
|
||||
{ title: 'LNG-Lieferungen steigen deutlich – Erdgas wird billiger', note: 'Gas billiger' },
|
||||
{ title: 'Friedensabkommen unterzeichnet: Waffenstillstand in Osteuropa', note: 'Frieden' },
|
||||
{ title: 'EZB erhöht Leitzins überraschend um 0,5 Prozentpunkte', note: 'Zinsschock' },
|
||||
{ title: 'Inflation steigt auf höchsten Stand seit 30 Jahren', note: 'Inflation' },
|
||||
@@ -658,7 +671,7 @@ function report(res, A) {
|
||||
// ---------------- 4. Wirkung
|
||||
if (eff.length) {
|
||||
H(`4a. WIRKUNG EINZELNER SCHLAGZEILEN auf den fairen Wert (Sofortsprung, Mittel aus ${eff.length} Läufen; Folgemeldung = dieselbe Meldung 1 min später aus anderer Quelle)`);
|
||||
const cols = ['OEL', 'GOLD', 'USD', 'WIB10', 'AEGS', 'HLIO', 'VOLT', 'RHBK', 'NVLT', 'KRMA'];
|
||||
const cols = ['OEL', 'GAS', 'GOLD', 'USD', 'WIB10', 'AEGS', 'HLIO', 'STHL', 'VOLT', 'RHBK', 'NVLT', 'KRMA'];
|
||||
console.log(`${pad('Schlagzeile', 58)}${cols.map((c) => lpad(c, 7)).join('')}${lpad('Folge OEL', 10)}${lpad('iW OEL', 8)}`);
|
||||
for (let i = 0; i < eff[0].out.length; i++) {
|
||||
const xs = eff.map((e) => e.out[i]);
|
||||
@@ -670,12 +683,12 @@ function report(res, A) {
|
||||
}
|
||||
if (scen.length) {
|
||||
H(`4b. SZENARIEN (hybride Wirtschaft im Zeitraffer, je ${A.fastSeeds} Saisons à 20 Handelstage)`);
|
||||
console.log(`${pad('Szenario', 14)}${lpad('Index', 9)}${lpad('max. DD', 9)}${lpad('Tech', 9)}${lpad('Banken', 9)}${lpad('Energie', 9)}${lpad('Rüstung', 9)}${lpad('OEL', 9)}${lpad('GOLD', 9)}${lpad('WIB10', 9)}${lpad('Zins Ende', 10)}${lpad('Infl. max', 10)}${lpad('Rend.10J', 10)}${lpad('Rating', 8)}${lpad('Krise', 7)}`);
|
||||
console.log(`${pad('Szenario', 14)}${lpad('Index', 9)}${lpad('max. DD', 9)}${lpad('Tech', 9)}${lpad('Banken', 9)}${lpad('Energie', 9)}${lpad('Rüstung', 9)}${lpad('OEL', 9)}${lpad('GAS', 9)}${lpad('GOLD', 9)}${lpad('WIB10', 9)}${lpad('Zins Ende', 10)}${lpad('Infl. max', 10)}${lpad('Rend.10J', 10)}${lpad('Rating', 8)}${lpad('Krise', 7)}`);
|
||||
for (const sc of [...new Set(scen.map((r) => r.scenario))]) {
|
||||
const rs = scen.filter((r) => r.scenario === sc);
|
||||
const sec = (syms) => mean(rs.map((r) => mean(syms.map((s) => r.inst[s].ret))));
|
||||
const worst = worstRating(rs.map((r) => r.budget.worst));
|
||||
console.log(`${pad(sc, 14)}${lpad(pct(mean(rs.map((r) => r.index.ret))), 9)}${lpad(pct(mean(rs.map((r) => r.index.mdd))).replace('+', ''), 9)}${lpad(pct(sec(['NVLT', 'QBIT'])), 9)}${lpad(pct(sec(['RHBK'])), 9)}${lpad(pct(sec(['HLIO', 'GRNH'])), 9)}${lpad(pct(sec(['AEGS'])), 9)}${lpad(pct(sec(['OEL'])), 9)}${lpad(pct(sec(['GOLD'])), 9)}${lpad(pct(sec(['WIB10'])), 9)}${lpad(f(mean(rs.map((r) => r.macro.last.rate)), 2), 10)}${lpad(f(mean(rs.map((r) => r.macro.inflMax)), 1), 10)}${lpad(f(mean(rs.map((r) => r.yields.WIB10.end)), 2), 10)}${lpad(worst, 8)}${lpad(f(mean(rs.map((r) => r.budget.crisisDays / r.budget.days)) * 100, 0) + '%', 7)}`);
|
||||
console.log(`${pad(sc, 14)}${lpad(pct(mean(rs.map((r) => r.index.ret))), 9)}${lpad(pct(mean(rs.map((r) => r.index.mdd))).replace('+', ''), 9)}${lpad(pct(sec(['NVLT', 'QBIT'])), 9)}${lpad(pct(sec(['RHBK'])), 9)}${lpad(pct(sec(['HLIO', 'GRNH'])), 9)}${lpad(pct(sec(['AEGS'])), 9)}${lpad(pct(sec(['OEL'])), 9)}${lpad(pct(sec(['GAS'])), 9)}${lpad(pct(sec(['GOLD'])), 9)}${lpad(pct(sec(['WIB10'])), 9)}${lpad(f(mean(rs.map((r) => r.macro.last.rate)), 2), 10)}${lpad(f(mean(rs.map((r) => r.macro.inflMax)), 1), 10)}${lpad(f(mean(rs.map((r) => r.yields.WIB10.end)), 2), 10)}${lpad(worst, 8)}${lpad(f(mean(rs.map((r) => r.budget.crisisDays / r.budget.days)) * 100, 0) + '%', 7)}`);
|
||||
}
|
||||
console.log('Renditen = Saison Ø · Rating = schlechtestes Rating der Saison · Krise = Anteil der Tage mit Haushaltskrise');
|
||||
}
|
||||
@@ -683,10 +696,25 @@ function report(res, A) {
|
||||
H('4c. HAUSHALT & RATING ÜBER VIELE SPIELJAHRE (Saisons hintereinander, Gesetze und Wahlen laufen mit)');
|
||||
for (const r of long) {
|
||||
const b = r.budget;
|
||||
console.log(`${pad(`Seed ${r.seed} (${r.scenario === 'schuldenkrise' ? 'Start Schuldenkrise' : 'Start normal'})`, 30)} ${lpad(r.seasons, 3)} Saisons ≈ ${f(r.tradingDays / 84, 1)} Spieljahre: Schulden ${f(b.first.debt, 1)} → ${f(b.last.debt, 1)} % BIP (max ${f(b.debtMax, 1)}), Defizit Ende ${f(b.last.deficit, 1)} %, Rating ${b.first.rating} → ${b.last.rating} (schlechtestes ${b.worst}), Krisentage ${f(b.crisisDays / b.days * 100, 0)} %, Zins Ende ${f(r.macro.last.rate, 2)} %, Index ${pct(r.index.ret)}, OEL ${pct(r.inst.OEL.ret)}, GOLD ${pct(r.inst.GOLD.ret)}, USD ${pct(r.inst.USD.ret)}`);
|
||||
console.log(`${pad(`Seed ${r.seed} (${r.scenario === 'schuldenkrise' ? 'Start Schuldenkrise' : 'Start normal'})`, 30)} ${lpad(r.seasons, 3)} Saisons ≈ ${f(r.tradingDays / 84, 1)} Spieljahre: Schulden ${f(b.first.debt, 1)} → ${f(b.last.debt, 1)} % BIP (max ${f(b.debtMax, 1)}), Defizit Ende ${f(b.last.deficit, 1)} %, Rating ${b.first.rating} → ${b.last.rating} (schlechtestes ${b.worst}), Krisentage ${f(b.crisisDays / b.days * 100, 0)} %, Zins Ende ${f(r.macro.last.rate, 2)} %, Index ${pct(r.index.ret)}, OEL ${pct(r.inst.OEL.ret)}, GAS ${pct(r.inst.GAS?.ret)}, GOLD ${pct(r.inst.GOLD.ret)}, USD ${pct(r.inst.USD.ret)}`);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- 4d. Erdgas: Saisonkurve
|
||||
const gasRuns = [...long, ...fastN].filter((r) => r.gasByMonth);
|
||||
if (gasRuns.length) {
|
||||
H(`4d. ERDGAS – SAISONKURVE je Spielmonat (${long.length ? 'Langläufe über viele Spieljahre' : 'Zeitraffer-Saisons'}, ${gasRuns.length} Läufe)`);
|
||||
const tot = Array.from({ length: 12 }, (_, i) => gasRuns.reduce((a, r) => { const x = r.gasByMonth[i]; return { n: a.n + x.n, lnPx: a.lnPx + x.lnPx, lnFv: a.lnFv + x.lnFv, fill: a.fill + x.fill, norm: a.norm + x.norm }; }, { n: 0, lnPx: 0, lnFv: 0, fill: 0, norm: 0 }));
|
||||
const all = tot.reduce((a, x) => a + x.lnPx, 0) / Math.max(1, tot.reduce((a, x) => a + x.n, 0));
|
||||
console.log(`${pad('Monat', 12)}${lpad('Tage', 7)}${lpad('Kurs Ø', 9)}${lpad('ggü. Jahr', 11)}${lpad('innerer W.', 12)}${lpad('Speicher', 10)}${lpad('üblich', 9)}`);
|
||||
tot.forEach((x, i) => {
|
||||
if (!x.n) return;
|
||||
console.log(`${pad(MONTH_NAMES[i], 12)}${lpad(x.n, 7)}${lpad(f(Math.exp(x.lnPx / x.n), 2), 9)}${lpad(pct(Math.exp(x.lnPx / x.n - all) - 1), 11)}${lpad(f(Math.exp(x.lnFv / x.n), 2), 12)}${lpad(pct(x.fill / x.n, 0).replace('+', ''), 10)}${lpad(pct(x.norm / x.n, 0).replace('+', ''), 9)}`);
|
||||
});
|
||||
const gv = gasRuns.map((r) => r.inst.GAS?.realVol).filter(Number.isFinite);
|
||||
console.log(`Ist-Volatilität GAS Ø ${pct(mean(gv), 0).replace('+', '')} (Ziel 60 %) · Kurs ggü. Jahresmittel: Saisonaufschlag + Speicher + Ereignisse + Zufall`);
|
||||
}
|
||||
|
||||
// ---------------- 5. Leistung
|
||||
if (hy.length) {
|
||||
H('5. LEISTUNG (Echtzeit-Hybrid, alle Funktionen, Spieler handeln, SQLite schreibt jeden Takt)');
|
||||
|
||||
Reference in new issue
Block a user