MCPcopy Create free account
hub / github.com/shiyu-coder/Kronos / predict_future

Function predict_future

examples/prediction_cn_markets_day.py:159–198  ·  view source on GitHub ↗
(symbol)

Source from the content-addressed store, hash-verified

157
158
159def predict_future(symbol):
160 print(f"🚀 Loading Kronos tokenizer:{TOKENIZER_PRETRAINED} model:{MODEL_PRETRAINED} ...")
161 tokenizer = KronosTokenizer.from_pretrained(TOKENIZER_PRETRAINED)
162 model = Kronos.from_pretrained(MODEL_PRETRAINED)
163 predictor = KronosPredictor(model, tokenizer, device=DEVICE, max_context=MAX_CONTEXT)
164
165 df = load_data(symbol)
166 x_df, x_timestamp, y_timestamp = prepare_inputs(df)
167
168 print("🔮 Generating predictions ...")
169
170 pred_df = predictor.predict(
171 df=x_df,
172 x_timestamp=x_timestamp,
173 y_timestamp=y_timestamp,
174 pred_len=PRED_LEN,
175 T=T,
176 top_p=TOP_P,
177 sample_count=SAMPLE_COUNT,
178 )
179
180 pred_df["date"] = y_timestamp.values
181
182 # Apply ±10% price limit
183 last_close = df["close"].iloc[-1]
184 pred_df = apply_price_limits(pred_df, last_close, limit_rate=0.1)
185
186 # Merge historical and predicted data
187 df_out = pd.concat([
188 df[["date", "open", "high", "low", "close", "volume", "amount"]],
189 pred_df[["date", "open", "high", "low", "close", "volume", "amount"]]
190 ]).reset_index(drop=True)
191
192 # Save CSV
193 out_file = os.path.join(save_dir, f"pred_{symbol.replace('.', '_')}_data.csv")
194 df_out.to_csv(out_file, index=False)
195 print(f"✅ Prediction completed and saved: {out_file}")
196
197 # Plot
198 plot_result(df, pred_df, symbol)
199
200
201if __name__ == "__main__":

Callers 1

Calls 6

predictMethod · 0.95
KronosPredictorClass · 0.90
prepare_inputsFunction · 0.85
apply_price_limitsFunction · 0.85
plot_resultFunction · 0.85
load_dataFunction · 0.70

Tested by

no test coverage detected