1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-17 17:34:35 +08:00

add_pre-commit_and_flake8_to_CI

This commit is contained in:
Linlang Lv (iSoftStone)
2022-03-22 09:48:13 +08:00
committed by you-n-g
parent 243e516cf1
commit 30e457119c
45 changed files with 191 additions and 42 deletions

View File

@@ -164,14 +164,14 @@ import builtins
def _isinstance(instance, cls):
if isinstance_orig(instance, SepDataFrame): # pylint: disable=E0602
if isinstance_orig(instance, SepDataFrame): # pylint: disable=E0602 # noqa: F821
if isinstance(cls, Iterable):
for c in cls:
if c is pd.DataFrame:
return True
elif cls is pd.DataFrame:
return True
return isinstance_orig(instance, cls) # pylint: disable=E0602
return isinstance_orig(instance, cls) # pylint: disable=E0602 # noqa: F821
builtins.isinstance_orig = builtins.isinstance

View File

@@ -2,3 +2,6 @@
# Licensed under the MIT License.
from .data_selection import MetaTaskDS, MetaDatasetDS, MetaModelDS
__all__ = ["MetaTaskDS", "MetaDatasetDS", "MetaModelDS"]

View File

@@ -3,3 +3,6 @@
from .dataset import MetaDatasetDS, MetaTaskDS
from .model import MetaModelDS
__all__ = ["MetaDatasetDS", "MetaTaskDS", "MetaModelDS"]

View File

@@ -10,7 +10,6 @@ from tqdm.auto import tqdm
import copy
from typing import Union, List
from ....data.dataset.weight import Reweighter
from ....model.meta.dataset import MetaTaskDataset
from ....model.meta.model import MetaTaskModel
from ....workflow import R
@@ -18,8 +17,8 @@ from .utils import ICLoss
from .dataset import MetaDatasetDS
from qlib.log import get_module_logger
from qlib.data.dataset.weight import Reweighter
from qlib.model.meta.task import MetaTask
from qlib.data.dataset.weight import Reweighter
from qlib.contrib.meta.data_selection.net import PredNet
logger = get_module_logger("data selection")
@@ -98,7 +97,6 @@ class MetaModelDS(MetaTaskModel):
if phase == "train":
opt.zero_grad()
norm_loss = nn.MSELoss()
loss.backward()
opt.step()
elif phase == "test":

View File

@@ -249,7 +249,7 @@ class DEnsembleModel(Model, FeatureInt):
return pred
def predict_sub(self, submodel, df_data, features):
x_data, y_data = df_data["feature"].loc[:, features], df_data["label"]
x_data = df_data["feature"].loc[:, features]
pred_sub = pd.Series(submodel.predict(x_data.values), index=x_data.index)
return pred_sub

View File

@@ -84,7 +84,7 @@ class SFM_Model(nn.Module):
if len(self.states) == 0: # hasn't initialized yet
self.init_states(x)
self.get_constants(x)
p_tm1 = self.states[0]
p_tm1 = self.states[0] # noqa: F841
h_tm1 = self.states[1]
S_re_tm1 = self.states[2]
S_im_tm1 = self.states[3]

View File

@@ -477,10 +477,10 @@ class TabNet(nn.Module):
sparse_loss = []
out = torch.zeros(x.size(0), self.n_d).to(x.device)
for step in self.steps:
x_te, l = step(x, x_a, priors)
x_te, loss = step(x, x_a, priors)
out += F.relu(x_te[:, : self.n_d]) # split the feature from feat_transformer
x_a = x_te[:, self.n_d :]
sparse_loss.append(l)
sparse_loss.append(loss)
return self.fc(out), sum(sparse_loss)

View File

@@ -1,4 +1,5 @@
# pylint: skip-file
# flake8: noqa
'''
TODO:

View File

@@ -2,6 +2,7 @@
# Licensed under the MIT License.
# pylint: skip-file
# flake8: noqa
import yaml
import pathlib

View File

@@ -2,6 +2,7 @@
# Licensed under the MIT License.
# pylint: skip-file
# flake8: noqa
import random
import pandas as pd

View File

@@ -2,6 +2,7 @@
# Licensed under the MIT License.
# pylint: skip-file
# flake8: noqa
import fire
import pandas as pd

View File

@@ -2,6 +2,7 @@
# Licensed under the MIT License.
# pylint: skip-file
# flake8: noqa
import logging

View File

@@ -2,6 +2,7 @@
# Licensed under the MIT License.
# pylint: skip-file
# flake8: noqa
import pathlib
import pickle

View File

@@ -2,3 +2,6 @@
# Licensed under the MIT License.
from .analysis_model_performance import model_performance_graph
__all__ = ["model_performance_graph"]

View File

@@ -6,3 +6,6 @@ from .score_ic import score_ic_graph
from .report import report_graph
from .rank_label import rank_label_graph
from .risk_analysis import risk_analysis_graph
__all__ = ["cumulative_return_graph", "score_ic_graph", "report_graph", "rank_label_graph", "risk_analysis_graph"]

View File

@@ -15,3 +15,14 @@ from .rule_strategy import (
)
from .cost_control import SoftTopkStrategy
__all__ = [
"TopkDropoutStrategy",
"WeightStrategyBase",
"EnhancedIndexingStrategy",
"TWAPStrategy",
"SBBStrategyBase",
"SBBStrategyEMA",
"SoftTopkStrategy",
]

View File

@@ -4,3 +4,6 @@
from .base import BaseOptimizer
from .optimizer import PortfolioOptimizer
from .enhanced_indexing import EnhancedIndexingOptimizer
__all__ = ["BaseOptimizer", "PortfolioOptimizer", "EnhancedIndexingOptimizer"]

View File

@@ -131,10 +131,10 @@ class TopkDropoutStrategy(BaseSignalStrategy):
if self.only_tradable:
# If The strategy only consider tradable stock when make decision
# It needs following actions to filter stocks
def get_first_n(l, n, reverse=False):
def get_first_n(li, n, reverse=False):
cur_n = 0
res = []
for si in reversed(l) if reverse else l:
for si in reversed(li) if reverse else li:
if self.trade_exchange.is_stock_tradable(
stock_id=si, start_time=trade_start_time, end_time=trade_end_time
):
@@ -144,13 +144,13 @@ class TopkDropoutStrategy(BaseSignalStrategy):
break
return res[::-1] if reverse else res
def get_last_n(l, n):
return get_first_n(l, n, reverse=True)
def get_last_n(li, n):
return get_first_n(li, n, reverse=True)
def filter_stock(l):
def filter_stock(li):
return [
si
for si in l
for si in li
if self.trade_exchange.is_stock_tradable(
stock_id=si, start_time=trade_start_time, end_time=trade_end_time
)
@@ -158,14 +158,14 @@ class TopkDropoutStrategy(BaseSignalStrategy):
else:
# Otherwise, the stock will make decision with out the stock tradable info
def get_first_n(l, n):
return list(l)[:n]
def get_first_n(li, n):
return list(li)[:n]
def get_last_n(l, n):
return list(l)[-n:]
def get_last_n(li, n):
return list(li)[-n:]
def filter_stock(l):
return l
def filter_stock(li):
return li
current_temp = copy.deepcopy(self.trade_position)
# generate order list for this adjust date
@@ -203,7 +203,7 @@ class TopkDropoutStrategy(BaseSignalStrategy):
candi = filter_stock(last)
try:
sell = pd.Index(np.random.choice(candi, self.n_drop, replace=False) if len(last) else [])
except ValueError: # No enough candidates
except ValueError: # No enough candidates
sell = candi
else:
raise NotImplementedError(f"This type of input is not supported")

View File

@@ -1 +1,2 @@
# pylint: skip-file
# flake8: noqa

View File

@@ -2,6 +2,7 @@
# Licensed under the MIT License.
# pylint: skip-file
# flake8: noqa
import yaml
import copy

View File

@@ -2,6 +2,7 @@
# Licensed under the MIT License.
# pylint: skip-file
# flake8: noqa
# coding=utf-8

View File

@@ -2,6 +2,7 @@
# Licensed under the MIT License.
# pylint: skip-file
# flake8: noqa
import os
import json

View File

@@ -2,6 +2,7 @@
# Licensed under the MIT License.
# pylint: skip-file
# flake8: noqa
from hyperopt import hp

View File

@@ -2,6 +2,7 @@
# Licensed under the MIT License.
# pylint: skip-file
# flake8: noqa
import os
import yaml

View File

@@ -2,3 +2,6 @@
# Licensed under the MIT License.
from .record_temp import MultiSegRecord
from .record_temp import SignalMseRecord
__all__ = ["MultiSegRecord", "SignalMseRecord"]