google-research / timesfm

TimesFM (Time Series Foundation Model) is a pretrained time-series foundation model developed by Google Research for time-series forecasting.
https://research.google/blog/a-decoder-only-foundation-model-for-time-series-forecasting/
Apache License 2.0
3.04k stars 228 forks source link

Is there any certified case that timesfm could predict the trend of a stock? #82

Open JackeyLee007 opened 3 days ago

JackeyLee007 commented 3 days ago

I tried it with China's A-share 000001 and found that it was not accurate. Is there anything that I used improperly?

The blue-grey line is real data, and the red line is predicted value. I used the value from 20210101 to 20210430 to predict the value of the next 32 days.

stock_trend

import timesfm
import os
import numpy as np
import akshare as ak
import pandas as pd

stHist = ak.stock_zh_a_hist('000001', 'daily', '20210101', '20210430')
incVals=range(1, len(stHist)+1)
stHist['unique_id'] = incVals
stHist = stHist.rename(columns={'日期':'ds','收盘':'value'})
stHist['ds'] = pd.to_datetime(stHist['ds'])
print(stHist)
tfm = timesfm.TimesFm(
    context_len=128,
    horizon_len=32,
    input_patch_len=32,
    output_patch_len=128,
    num_layers=20,
    model_dims=1280,
    backend='cpu',
)
tfm.load_from_checkpoint(repo_id="google/timesfm-1.0-200m")

forecast_df = tfm.forecast_on_df(
        inputs=stHist,
        freq='D',
        value_name='value',
        num_jobs=1)