Prophet's model, in TypeScript
Uses the same model as Prophet, the forecasting library from Meta, and is tested against Python Prophet 1.4.0 so the results match.
Give it your history. Get back a forecast you can explain, with the trend, weekly and yearly patterns, and holidays each broken out.
import { Effect } from "effect";
import { fit, predict, prophetFittingBackendLayer } from "effect-prophet";
// 1. Your history: one row per day, each with a timestamp and a value.
const history = Array.from({ length: 90 }, (_, day) => ({
timestamp: new Date(Date.UTC(2025, 0, 1 + day)).toISOString(),
value: 100 + day * 0.5 + 10 * Math.sin((2 * Math.PI * day) / 7),
}));
// 2. The dates you want a forecast for: the next seven days.
const nextWeek = Array.from({ length: 7 }, (_, offset) =>
new Date(Date.UTC(2025, 0, 91 + offset)).toISOString(),
);
// 3. Describe the work: fit a model to the history, then predict.
const program = Effect.gen(function* () {
const model = yield* fit(history);
return yield* predict(model, nextWeek);
});
// 4. Run it. The layer plugs in the forecasting engine.
const forecast = await Effect.runPromise(program.pipe(Effect.provide(prophetFittingBackendLayer)));
for (const row of forecast) {
console.log(new Date(row.timestamp).toISOString().slice(0, 10), row.value.toFixed(1));
}2025-04-01 137.2
2025-04-02 145.5
2025-04-03 153.8
2025-04-04 156.2
2025-04-05 151.3
2025-04-06 143.2
2025-04-07 138.3