repo
stringlengths
7
90
file_url
stringlengths
81
315
file_path
stringlengths
4
228
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 14:38:15
2026-01-05 02:33:18
truncated
bool
2 classes
gradio-app/gradio
https://github.com/gradio-app/gradio/blob/3b56b13268ddcaf74d4e85e5dbf5a616d7843995/demo/blocks_flag/run.py
demo/blocks_flag/run.py
import numpy as np import gradio as gr def sepia(input_img, strength): sepia_filter = strength * np.array( [[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]] ) + (1-strength) * np.identity(3) sepia_img = input_img.dot(sepia_filter.T) sepia_img /= sepia_img.max() return se...
python
Apache-2.0
3b56b13268ddcaf74d4e85e5dbf5a616d7843995
2026-01-04T14:40:26.993006Z
false
gradio-app/gradio
https://github.com/gradio-app/gradio/blob/3b56b13268ddcaf74d4e85e5dbf5a616d7843995/demo/chatinterface_random_response/run.py
demo/chatinterface_random_response/run.py
import random import gradio as gr def random_response(message, history): return random.choice(["Yes", "No"]) demo = gr.ChatInterface(random_response, autofocus=False, api_name="chat") if __name__ == "__main__": demo.launch()
python
Apache-2.0
3b56b13268ddcaf74d4e85e5dbf5a616d7843995
2026-01-04T14:40:26.993006Z
false
gradio-app/gradio
https://github.com/gradio-app/gradio/blob/3b56b13268ddcaf74d4e85e5dbf5a616d7843995/demo/timer_simple/run.py
demo/timer_simple/run.py
import gradio as gr import random import time with gr.Blocks() as demo: timer = gr.Timer(1) timestamp = gr.Number(label="Time") timer.tick(lambda: round(time.time()), outputs=timestamp, api_name="timestamp") number = gr.Number(lambda: random.randint(1, 10), every=timer, label="Random Number") with gr.Row():...
python
Apache-2.0
3b56b13268ddcaf74d4e85e5dbf5a616d7843995
2026-01-04T14:40:26.993006Z
false
gradio-app/gradio
https://github.com/gradio-app/gradio/blob/3b56b13268ddcaf74d4e85e5dbf5a616d7843995/demo/generate_tone/run.py
demo/generate_tone/run.py
import numpy as np import gradio as gr notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"] def generate_tone(note, octave, duration): sr = 48000 a4_freq, tones_from_a4 = 440, 12 * (octave - 4) + (note - 9) frequency = a4_freq * 2 ** (tones_from_a4 / 12) duration = int(duration) ...
python
Apache-2.0
3b56b13268ddcaf74d4e85e5dbf5a616d7843995
2026-01-04T14:40:26.993006Z
false
gradio-app/gradio
https://github.com/gradio-app/gradio/blob/3b56b13268ddcaf74d4e85e5dbf5a616d7843995/demo/streaming_wav2vec/run.py
demo/streaming_wav2vec/run.py
from transformers import pipeline import gradio as gr import time p = pipeline("automatic-speech-recognition") def transcribe(audio, state=""): time.sleep(2) text = p(audio)["text"] # type: ignore state += text + " " # type: ignore return state, state demo = gr.Interface( fn=transcribe, inpu...
python
Apache-2.0
3b56b13268ddcaf74d4e85e5dbf5a616d7843995
2026-01-04T14:40:26.993006Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/setup.py
setup.py
import os import numpy from setuptools import Extension, setup NUMPY_INCLUDE = numpy.get_include() setup( ext_modules=[ Extension( "qlib.data._libs.rolling", ["qlib/data/_libs/rolling.pyx"], language="c++", include_dirs=[NUMPY_INCLUDE], ), ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/dump_bin.py
scripts/dump_bin.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import abc import shutil import traceback from pathlib import Path from typing import Iterable, List, Union from functools import partial from concurrent.futures import ThreadPoolExecutor, as_completed, ProcessPoolExecutor import fire import num...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/check_data_health.py
scripts/check_data_health.py
from loguru import logger import os from typing import Optional import fire import pandas as pd import qlib from tqdm import tqdm from qlib.data import D class DataHealthChecker: """Checks a dataset for data completeness and correctness. The data will be converted to a pd.DataFrame and checked for the following...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/check_dump_bin.py
scripts/check_dump_bin.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. from pathlib import Path from concurrent.futures import ProcessPoolExecutor import qlib from qlib.data import D import fire import datacompy import pandas as pd from tqdm import tqdm from loguru import logger class CheckBin: NOT_IN_FEATUR...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/collect_info.py
scripts/collect_info.py
import sys import platform import qlib import fire import pkg_resources from pathlib import Path QLIB_PATH = Path(__file__).absolute().resolve().parent.parent class InfoCollector: """ User could collect system info by following commands `cd scripts && python collect_info.py all` - NOTE: please avoid ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/get_data.py
scripts/get_data.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import fire from qlib.tests.data import GetData if __name__ == "__main__": fire.Fire(GetData)
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/dump_pit.py
scripts/dump_pit.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. """ TODO: - A more well-designed PIT database is required. - separated insert, delete, update, query operations are required. """ import shutil import struct from pathlib import Path from typing import Iterable from functools import partial f...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/future_calendar_collector.py
scripts/data_collector/future_calendar_collector.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import abc import importlib from pathlib import Path from typing import Union, Iterable, List import fire import numpy as np import pandas as pd # pip install baostock import baostock as bs from loguru import logger class CollectorFutureCalen...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/utils.py
scripts/data_collector/utils.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import re import copy import importlib import time import bisect import pickle import random import requests import functools from pathlib import Path from typing import Iterable, Tuple, List import numpy as np import pandas as pd from loguru ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/base.py
scripts/data_collector/base.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import abc import time import datetime import importlib from pathlib import Path from typing import Type, Iterable from concurrent.futures import ProcessPoolExecutor import pandas as pd from tqdm import tqdm from loguru import logger from jobli...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/index.py
scripts/data_collector/index.py
import sys import abc from pathlib import Path from typing import List import pandas as pd from tqdm import tqdm from loguru import logger CUR_DIR = Path(__file__).resolve().parent sys.path.append(str(CUR_DIR.parent)) from data_collector.utils import get_trading_date_by_shift class IndexBase: DEFAULT_END_DATE...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/us_index/collector.py
scripts/data_collector/us_index/collector.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import abc from functools import partial import sys from pathlib import Path from concurrent.futures import ThreadPoolExecutor from typing import List from io import StringIO import fire import requests import pandas as pd from tqdm import tqdm ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/fund/collector.py
scripts/data_collector/fund/collector.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import abc import sys import datetime import json from abc import ABC from pathlib import Path import fire import requests import pandas as pd from loguru import logger from dateutil.tz import tzlocal from qlib.constant import REG_CN as REGION_C...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/contrib/fill_cn_1min_data/fill_cn_1min_data.py
scripts/data_collector/contrib/fill_cn_1min_data/fill_cn_1min_data.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import sys from pathlib import Path from concurrent.futures import ThreadPoolExecutor import fire import qlib import pandas as pd from tqdm import tqdm from qlib.data import D from loguru import logger CUR_DIR = Path(__file__).resolve().parent ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/contrib/future_trading_date_collector/future_trading_date_collector.py
scripts/data_collector/contrib/future_trading_date_collector/future_trading_date_collector.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import sys from typing import List from pathlib import Path import fire import numpy as np import pandas as pd from loguru import logger # get data from baostock import baostock as bs CUR_DIR = Path(__file__).resolve().parent sys.path.append(s...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/baostock_5min/collector.py
scripts/data_collector/baostock_5min/collector.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import sys import copy import fire import numpy as np import pandas as pd import baostock as bs from tqdm import tqdm from pathlib import Path from loguru import logger from typing import Iterable, List import qlib from qlib.data import D CUR_...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/cn_index/collector.py
scripts/data_collector/cn_index/collector.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import re import abc import sys from io import BytesIO from typing import List, Iterable from pathlib import Path import fire import requests import pandas as pd import baostock as bs from tqdm import tqdm from loguru import logger CUR_DIR = Pa...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/br_index/collector.py
scripts/data_collector/br_index/collector.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. from functools import partial import sys from pathlib import Path import datetime import fire import pandas as pd from tqdm import tqdm from loguru import logger CUR_DIR = Path(__file__).resolve().parent sys.path.append(str(CUR_DIR.parent.parent...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/pit/collector.py
scripts/data_collector/pit/collector.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import re import sys from datetime import datetime from pathlib import Path from typing import List, Iterable, Optional, Union import fire import pandas as pd import baostock as bs from loguru import logger BASE_DIR = Path(__file__).resolve().p...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/yahoo/collector.py
scripts/data_collector/yahoo/collector.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import abc import sys import copy import time import datetime import importlib from abc import ABC import multiprocessing from pathlib import Path from typing import Iterable import fire import requests import numpy as np import pandas as pd fro...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
true
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/scripts/data_collector/crypto/collector.py
scripts/data_collector/crypto/collector.py
import abc import sys import datetime from abc import ABC from pathlib import Path import fire import pandas as pd from loguru import logger from dateutil.tz import tzlocal CUR_DIR = Path(__file__).resolve().parent sys.path.append(str(CUR_DIR.parent.parent)) from data_collector.base import BaseCollector, BaseNormaliz...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/test_all_pipeline.py
tests/test_all_pipeline.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import sys import shutil import unittest import pytest from pathlib import Path import qlib from qlib.config import C from qlib.utils import init_instance_by_config, flatten_dict from qlib.workflow import R from qlib.workflow.record_temp import ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/test_dump_data.py
tests/test_dump_data.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import sys import shutil import unittest from pathlib import Path import qlib import numpy as np import pandas as pd from qlib.data import D sys.path.append(str(Path(__file__).resolve().parent.parent.joinpath("scripts"))) from get_data impor...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/test_get_data.py
tests/test_get_data.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import shutil import unittest from pathlib import Path import qlib from qlib.data import D from qlib.tests.data import GetData DATA_DIR = Path(__file__).parent.joinpath("test_get_data") SOURCE_DIR = DATA_DIR.joinpath("source") SOURCE_DIR.mkdi...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/test_pit.py
tests/test_pit.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import sys import qlib import shutil import unittest import pytest import pandas as pd from pathlib import Path from qlib.data import D from qlib.tests.data import GetData sys.path.append(str(Path(__file__).resolve().parent.parent.joinpath("sc...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/conftest.py
tests/conftest.py
import os import sys """Ignore RL tests on non-linux platform.""" collect_ignore = [] if sys.platform != "linux": for root, dirs, files in os.walk("rl"): for file in files: collect_ignore.append(os.path.join(root, file))
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/test_structured_cov_estimator.py
tests/test_structured_cov_estimator.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest import numpy as np from scipy.linalg import sqrtm from qlib.model.riskmodel import StructuredCovEstimator class TestStructuredCovEstimator(unittest.TestCase): def test_random_covariance(self): # Try to estimate the ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/test_contrib_model.py
tests/test_contrib_model.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest from qlib.contrib.model import all_model_classes class TestAllFlow(unittest.TestCase): def test_0_initialize(self): num = 0 for model_class in all_model_classes: if model_class is not None: ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/test_contrib_workflow.py
tests/test_contrib_workflow.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. from qlib.workflow.record_temp import SignalRecord import shutil import unittest import pytest from pathlib import Path from qlib.contrib.workflow import MultiSegRecord, SignalMseRecord from qlib.utils import init_instance_by_config, flatten_dic...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/test_workflow.py
tests/test_workflow.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest from pathlib import Path import shutil from qlib.workflow import R from qlib.tests import TestAutoData class WorkflowTest(TestAutoData): # Creating the directory manually doesn't work with mlflow, # so we add a subfolder...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/test_register_ops.py
tests/test_register_ops.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest import numpy as np from qlib.data import D from qlib.data.ops import ElemOperator, PairOperator from qlib.tests import TestAutoData class Diff(ElemOperator): """Feature First Difference Parameters ---------- fea...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/dataset_tests/test_datalayer.py
tests/dataset_tests/test_datalayer.py
import unittest import numpy as np from qlib.data import D from qlib.tests import TestAutoData class TestDataset(TestAutoData): def testCSI300(self): close_p = D.features(D.instruments("csi300"), ["$close"]) size = close_p.groupby("datetime", group_keys=False).size() cnt = close_p.groupby(...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/rl/test_logger.py
tests/rl/test_logger.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. from random import randint, choice from pathlib import Path import logging import re from typing import Any, Tuple import gym import numpy as np import pandas as pd from gym import spaces from tianshou.data import Collector, Batch from tianshou....
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/rl/test_qlib_simulator.py
tests/rl/test_qlib_simulator.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import sys from pathlib import Path from typing import Tuple import pandas as pd import pytest from qlib.backtest.decision import Order, OrderDir from qlib.backtest.executor import SimulatorExecutor from qlib.rl.order_execution import Categoric...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/rl/test_trainer.py
tests/rl/test_trainer.py
import os import random import sys from pathlib import Path import pytest import torch import torch.nn as nn from gym import spaces from tianshou.policy import PPOPolicy from qlib.config import C from qlib.log import set_log_with_config from qlib.rl.interpreter import StateInterpreter, ActionInterpreter from qlib.rl...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/rl/test_data_queue.py
tests/rl/test_data_queue.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import multiprocessing import time import numpy as np import pandas as pd from torch.utils.data import Dataset, DataLoader from qlib.rl.utils.data_queue import DataQueue class DummyDataset(Dataset): def __init__(self, length): sel...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/rl/test_saoe_simple.py
tests/rl/test_saoe_simple.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import sys from functools import partial from pathlib import Path from typing import NamedTuple import numpy as np import pandas as pd import pytest import torch from tianshou.data import Batch from qlib.backtest import Order from qlib.config i...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/rl/test_finite_env.py
tests/rl/test_finite_env.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. from collections import Counter import gym import numpy as np from tianshou.data import Batch, Collector from tianshou.policy import BasePolicy from torch.utils.data import DataLoader, Dataset, DistributedSampler from qlib.rl.utils.finite_env im...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/misc/test_get_multi_proc.py
tests/misc/test_get_multi_proc.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest import qlib from qlib.data import D from qlib.tests import TestAutoData from multiprocessing import Pool def get_features(fields): qlib.init(provider_uri=TestAutoData.provider_uri, expression_cache=None, dataset_cache=Non...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/misc/test_utils.py
tests/misc/test_utils.py
from typing import List from unittest.case import TestCase import unittest import pandas as pd import numpy as np from datetime import datetime from qlib import init from qlib.config import C from qlib.log import TimeInspector from qlib.constant import REG_CN, REG_US, REG_TW from qlib.utils.time import cal_sam_minute a...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/misc/test_sepdf.py
tests/misc/test_sepdf.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest import numpy as np import pandas as pd from qlib.contrib.data.utils.sepdf import SepDataFrame class SepDF(unittest.TestCase): def to_str(self, obj): return "".join(str(obj).split()) def test_index_data(self): ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/misc/test_index_data.py
tests/misc/test_index_data.py
import numpy as np import pandas as pd import qlib.utils.index_data as idd import unittest class IndexDataTest(unittest.TestCase): def test_index_single_data(self): # Auto broadcast for scalar sd = idd.SingleData(0, index=["foo", "bar"]) print(sd) # Support empty value sd...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/rolling_tests/test_update_pred.py
tests/rolling_tests/test_update_pred.py
import copy import unittest import pytest import fire import pandas as pd import qlib from qlib.data import D from qlib.model.trainer import task_train from qlib.tests import TestAutoData from qlib.tests.config import CSI300_GBDT_TASK from qlib.workflow.online.utils import OnlineToolR from qlib.workflow.online.update...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/model/test_general_nn.py
tests/model/test_general_nn.py
import unittest from qlib.tests import TestAutoData class TestNN(TestAutoData): def test_both_dataset(self): try: from qlib.contrib.model.pytorch_general_nn import GeneralPTNN from qlib.data.dataset import DatasetH, TSDatasetH from qlib.data.dataset.handler import DataH...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/dependency_tests/test_mlflow.py
tests/dependency_tests/test_mlflow.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest import platform import mlflow import time from pathlib import Path import shutil class MLflowTest(unittest.TestCase): TMP_PATH = Path("./.mlruns_tmp/") def tearDown(self) -> None: if self.TMP_PATH.exists(): ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/backtest/test_file_strategy.py
tests/backtest/test_file_strategy.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest from qlib.backtest import backtest from qlib.tests import TestAutoData import pandas as pd from pathlib import Path from qlib.data import D import numpy as np DIRNAME = Path(__file__).absolute().resolve().parent class FileStrTe...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/backtest/test_high_freq_trading.py
tests/backtest/test_high_freq_trading.py
from typing import List, Tuple, Union from qlib.backtest.position import Position from qlib.backtest import collect_data, format_decisions from qlib.backtest.decision import BaseTradeDecision, TradeRangeByTime import qlib from qlib.tests import TestAutoData import unittest import pandas as pd @unittest.skip("This tes...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/data_mid_layer_tests/test_processor.py
tests/data_mid_layer_tests/test_processor.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest import numpy as np from qlib.data import D from qlib.tests import TestAutoData from qlib.data.dataset.processor import MinMaxNorm, ZScoreNorm, CSZScoreNorm, CSZFillna class TestProcessor(TestAutoData): TEST_INST = "SH600519"...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/data_mid_layer_tests/test_handler.py
tests/data_mid_layer_tests/test_handler.py
import os import unittest from qlib.data import D from qlib.data.dataset.handler import DataHandlerLP from qlib.tests import TestAutoData from qlib.utils.pickle_utils import restricted_pickle_load class HandlerTests(TestAutoData): def to_str(self, obj): return "".join(str(obj).split()) def test_hand...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/data_mid_layer_tests/test_dataloader.py
tests/data_mid_layer_tests/test_dataloader.py
# TODO: # dump alpha 360 to dataframe and merge it with Alpha158 import sys import unittest import qlib from pathlib import Path sys.path.append(str(Path(__file__).resolve().parent)) from qlib.data.dataset.loader import NestedDataLoader, QlibDataLoader from qlib.data.dataset.handler import DataHandlerLP from qlib.con...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/data_mid_layer_tests/test_handler_storage.py
tests/data_mid_layer_tests/test_handler_storage.py
import unittest import time import numpy as np from qlib.data import D from qlib.tests import TestAutoData from qlib.data.dataset.handler import DataHandlerLP from qlib.contrib.data.handler import check_transform_proc from qlib.log import TimeInspector class TestHandler(DataHandlerLP): def __init__( self...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/data_mid_layer_tests/test_dataset.py
tests/data_mid_layer_tests/test_dataset.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest import pytest import sys from qlib.tests import TestAutoData from qlib.data.dataset import TSDatasetH, TSDataSampler import numpy as np import pandas as pd import time from qlib.data.dataset.handler import DataHandlerLP class Te...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/storage_tests/test_storage.py
tests/storage_tests/test_storage.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. from pathlib import Path from collections.abc import Iterable import numpy as np from qlib.tests import TestAutoData from qlib.data.storage.file_storage import ( FileCalendarStorage as CalendarStorage, FileInstrumentStorage as Instrume...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/ops/test_elem_operator.py
tests/ops/test_elem_operator.py
import unittest import numpy as np import pytest from qlib.data import DatasetProvider from qlib.data.data import ExpressionD from qlib.tests import TestOperatorData, TestMockData, MOCK_DF from qlib.config import C class TestElementOperator(TestMockData): def setUp(self) -> None: self.instrument = "0050"...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/tests/ops/test_special_ops.py
tests/ops/test_special_ops.py
import unittest from qlib.data import D from qlib.data.dataset.loader import QlibDataLoader from qlib.data.ops import ChangeInstrument, Cov, Feature, Ref, Var from qlib.tests import TestOperatorData class TestOperatorDataSetting(TestOperatorData): def test_setting(self): # All the query below passes ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/docs/conf.py
docs/conf.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # QLib documentation build configuration file, created by # sphinx-quickstart on Wed Sep 27 15:16:05 2017. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values a...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/workflow_by_code.py
examples/workflow_by_code.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. """ Qlib provides two kinds of interfaces. (1) Users could define the Quant research workflow by a simple configuration. (2) Qlib is designed in a modularized way and supports creating research workflow by code just like building blocks. The in...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/run_all_model.py
examples/run_all_model.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import os import sys import fire import time import glob import shutil import signal import inspect import tempfile import functools import statistics import subprocess from datetime import datetime from ruamel.yaml import YAML from pathlib imp...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/orderbook_data/example.py
examples/orderbook_data/example.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. from arctic.arctic import Arctic import qlib from qlib.data import D import unittest class TestClass(unittest.TestCase): """ Useful commands - run all tests: pytest examples/orderbook_data/example.py - run a single test: pytest...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/orderbook_data/create_dataset.py
examples/orderbook_data/create_dataset.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. """ NOTE: - This scripts is a demo to import example data import Qlib - !!!!!!!!!!!!!!!TODO!!!!!!!!!!!!!!!!!!!: - Its structure is not well designed and very ugly, your contribution is welcome to make importing dataset easier """ from datetime...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TFT/tft.py
examples/benchmarks/TFT/tft.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. from pathlib import Path from typing import Union import numpy as np import pandas as pd import tensorflow.compat.v1 as tf import data_formatters.base import expt_settings.configs import libs.hyperparam_opt import libs.tft_model import libs.utils...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TFT/expt_settings/configs.py
examples/benchmarks/TFT/expt_settings/configs.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicab...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TFT/expt_settings/__init__.py
examples/benchmarks/TFT/expt_settings/__init__.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicab...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TFT/data_formatters/__init__.py
examples/benchmarks/TFT/data_formatters/__init__.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicab...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TFT/data_formatters/base.py
examples/benchmarks/TFT/data_formatters/base.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicab...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TFT/data_formatters/qlib_Alpha158.py
examples/benchmarks/TFT/data_formatters/qlib_Alpha158.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicab...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TFT/libs/tft_model.py
examples/benchmarks/TFT/libs/tft_model.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicab...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
true
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TFT/libs/utils.py
examples/benchmarks/TFT/libs/utils.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicab...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TFT/libs/__init__.py
examples/benchmarks/TFT/libs/__init__.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicab...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TFT/libs/hyperparam_opt.py
examples/benchmarks/TFT/libs/hyperparam_opt.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicab...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/LightGBM/features_resample_N.py
examples/benchmarks/LightGBM/features_resample_N.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import pandas as pd from qlib.data.inst_processor import InstProcessor from qlib.utils.resam import resam_calendar class ResampleNProcessor(InstProcessor): def __init__(self, target_frq: str, **kwargs): self.target_frq = target_f...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/LightGBM/features_sample.py
examples/benchmarks/LightGBM/features_sample.py
import datetime import pandas as pd from qlib.data.inst_processor import InstProcessor class Resample1minProcessor(InstProcessor): """This processor tries to resample the data. It will reasmple the data from 1min freq to day freq by selecting a specific miniute""" def __init__(self, hour: int, minute: int, ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/LightGBM/multi_freq_handler.py
examples/benchmarks/LightGBM/multi_freq_handler.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import pandas as pd from qlib.data.dataset.loader import QlibDataLoader from qlib.contrib.data.handler import DataHandlerLP, _DEFAULT_LEARN_PROCESSORS, check_transform_proc class Avg15minLoader(QlibDataLoader): def load(self, instruments...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TRA/example.py
examples/benchmarks/TRA/example.py
import argparse import qlib from ruamel.yaml import YAML from qlib.utils import init_instance_by_config def main(seed, config_file="configs/config_alstm.yaml"): # set random seed with open(config_file) as f: yaml = YAML(typ="safe", pure=True) config = yaml.load(f) # seed_suffix = "/seed1...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TRA/src/model.py
examples/benchmarks/TRA/src/model.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import os import copy import math import json import collections import numpy as np import pandas as pd import torch import torch.nn as nn import torch.optim as optim import torch.nn.functional as F from tqdm import tqdm from qlib.utils import...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks/TRA/src/dataset.py
examples/benchmarks/TRA/src/dataset.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import copy import torch import numpy as np import pandas as pd from qlib.data.dataset import DatasetH device = "cuda" if torch.cuda.is_available() else "cpu" def _to_tensor(x): if not isinstance(x, torch.Tensor): return torch.te...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/data_demo/data_mem_resuse_demo.py
examples/data_demo/data_mem_resuse_demo.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. """ The motivation of this demo - To show the data modules of Qlib is Serializable, users can dump processed data to disk to avoid duplicated data preprocessing """ from copy import deepcopy from pathlib import Path import pickle from pprint impo...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/data_demo/data_cache_demo.py
examples/data_demo/data_cache_demo.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. """ The motivation of this demo - To show the data modules of Qlib is Serializable, users can dump processed data to disk to avoid duplicated data preprocessing """ from copy import deepcopy from pathlib import Path import pickle from pprint impo...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/online_srv/rolling_online_management.py
examples/online_srv/rolling_online_management.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. """ This example shows how OnlineManager works with rolling tasks. There are four parts including first train, routine 1, add strategy and routine 2. Firstly, the OnlineManager will finish the first training and set trained models to `online` mod...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/online_srv/update_online_pred.py
examples/online_srv/update_online_pred.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. """ This example shows how OnlineTool works when we need update prediction. There are two parts including first_train and update_online_pred. Firstly, we will finish the training and set the trained models to the `online` models. Next, we will fi...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/online_srv/online_management_simulate.py
examples/online_srv/online_management_simulate.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. """ This example is about how can simulate the OnlineManager based on rolling tasks. """ from pprint import pprint import fire import qlib from qlib.model.trainer import DelayTrainerR, DelayTrainerRM, TrainerR, TrainerRM from qlib.workflow impor...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/rolling_process_data/rolling_handler.py
examples/rolling_process_data/rolling_handler.py
from qlib.data.dataset.handler import DataHandlerLP from qlib.data.dataset.loader import DataLoaderDH from qlib.contrib.data.handler import check_transform_proc class RollingDataHandler(DataHandlerLP): def __init__( self, start_time=None, end_time=None, infer_processors=[], ...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/rolling_process_data/workflow.py
examples/rolling_process_data/workflow.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import qlib import fire import pickle from datetime import datetime from qlib.constant import REG_CN from qlib.data.dataset.handler import DataHandlerLP from qlib.utils import init_instance_by_config from qlib.tests.data import GetData class...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks_dynamic/DDG-DA/vis_data.py
examples/benchmarks_dynamic/DDG-DA/vis_data.py
import pickle import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns sns.set(color_codes=True) plt.rcParams["font.sans-serif"] = "SimHei" plt.rcParams["axes.unicode_minus"] = False from tqdm.auto import tqdm # tqdm.pandas() # for progress_apply # %matplotlib inline # %load_ext a...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks_dynamic/DDG-DA/workflow.py
examples/benchmarks_dynamic/DDG-DA/workflow.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import os from pathlib import Path from typing import Union import fire from qlib import auto_init from qlib.contrib.rolling.ddgda import DDGDA from qlib.tests.data import GetData DIRNAME = Path(__file__).absolute().resolve().parent BENCH_DIR =...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/benchmarks_dynamic/baseline/rolling_benchmark.py
examples/benchmarks_dynamic/baseline/rolling_benchmark.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import os from pathlib import Path from typing import Union import fire from qlib import auto_init from qlib.contrib.rolling.base import Rolling from qlib.tests.data import GetData DIRNAME = Path(__file__).absolute().resolve().parent class Ro...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/hyperparameter/LightGBM/hyperparameter_158.py
examples/hyperparameter/LightGBM/hyperparameter_158.py
import qlib import optuna from qlib.constant import REG_CN from qlib.utils import init_instance_by_config from qlib.tests.config import CSI300_DATASET_CONFIG from qlib.tests.data import GetData def objective(trial): task = { "model": { "class": "LGBModel", "module_path": "qlib.cont...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/hyperparameter/LightGBM/hyperparameter_360.py
examples/hyperparameter/LightGBM/hyperparameter_360.py
import qlib import optuna from qlib.constant import REG_CN from qlib.utils import init_instance_by_config from qlib.tests.data import GetData from qlib.tests.config import get_dataset_config, CSI300_MARKET, DATASET_ALPHA360_CLASS DATASET_CONFIG = get_dataset_config(market=CSI300_MARKET, dataset_class=DATASET_ALPHA360_...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/model_interpreter/feature.py
examples/model_interpreter/feature.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import qlib from qlib.constant import REG_CN from qlib.utils import init_instance_by_config from qlib.tests.data import GetData from qlib.tests.config import CSI300_GBDT_TASK if __name__ == "__main__": # use default data provider_ur...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/highfreq/highfreq_processor.py
examples/highfreq/highfreq_processor.py
import numpy as np import pandas as pd from qlib.constant import EPS from qlib.data.dataset.processor import Processor from qlib.data.dataset.utils import fetch_df_by_index class HighFreqNorm(Processor): def __init__(self, fit_start_time, fit_end_time): self.fit_start_time = fit_start_time self.fi...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/highfreq/highfreq_ops.py
examples/highfreq/highfreq_ops.py
import numpy as np import pandas as pd import importlib from qlib.data.ops import ElemOperator, PairOperator from qlib.config import C from qlib.data.cache import H from qlib.data.data import Cal from qlib.contrib.ops.high_freq import get_calendar_day class DayLast(ElemOperator): """DayLast Operator Paramete...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/highfreq/workflow.py
examples/highfreq/workflow.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import fire import qlib import pickle from qlib.constant import REG_CN from qlib.config import HIGH_FREQ_CONFIG from qlib.utils import init_instance_by_config from qlib.data.dataset.handler import DataHandlerLP from qlib.data.ops import Opera...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/highfreq/highfreq_handler.py
examples/highfreq/highfreq_handler.py
from qlib.data.dataset.handler import DataHandler, DataHandlerLP from qlib.contrib.data.handler import check_transform_proc class HighFreqHandler(DataHandlerLP): def __init__( self, instruments="csi300", start_time=None, end_time=None, infer_processors=[], learn_pro...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/model_rolling/task_manager_rolling.py
examples/model_rolling/task_manager_rolling.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. """ This example shows how a TrainerRM works based on TaskManager with rolling tasks. After training, how to collect the rolling results will be shown in task_collecting. Based on the ability of TaskManager, `worker` method offer a simple way for...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false
microsoft/qlib
https://github.com/microsoft/qlib/blob/477160e4ac3b4273ae0d4007982ae794a91d9f47/examples/portfolio/prepare_riskdata.py
examples/portfolio/prepare_riskdata.py
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import os import numpy as np import pandas as pd from qlib.data import D from qlib.model.riskmodel import StructuredCovEstimator def prepare_data(riskdata_root="./riskdata", T=240, start_time="2016-01-01"): universe = D.features(D.instrumen...
python
MIT
477160e4ac3b4273ae0d4007982ae794a91d9f47
2026-01-04T14:42:12.012974Z
false