Skip to content

Effect ProphetForecasting for TypeScript

Give it your history. Get back a forecast you can explain, with the trend, weekly and yearly patterns, and holidays each broken out.

A forecast in a few lines ​

ts
import { Effect } from "effect";
import { fit, makeFutureTimestamps, 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. Describe the work: fit a model to the history, list the next seven days, then predict.
const program = Effect.gen(function* () {
  const model = yield* fit(history);
  const nextWeek = yield* makeFutureTimestamps(history, { periods: 7, includeHistory: false });

  return yield* predict(model, nextWeek);
});

// 3. 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));
}
txt
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

Inspired by Prophet from Meta. Not affiliated with Meta.