Skip to content

Commit cc01812

Browse files
Fix typos and grammar errors in docstrings and comments (microsoft#1366)
* fix gramma error in doc strings * fix typos in exchange.py * fix typos and gramma errors * fix typo and rename function param to avoid shading python keyword * remove redundant parathesis; pass kwargs to parent class * fix pyblack * further correction * assign -> be assigned to
1 parent 0c4db8b commit cc01812

24 files changed

+77
-72
lines changed

qlib/backtest/exchange.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727

2828
class Exchange:
2929
# `quote_df` is a pd.DataFrame class that contains basic information for backtesting
30-
# After some processing, the data will later be maintained by `quote_cls` object for faster data retriving.
30+
# After some processing, the data will later be maintained by `quote_cls` object for faster data retrieving.
3131
# Some conventions for `quote_df`
3232
# - $close is for calculating the total value at end of each day.
33-
# - if $close is None, the stock on that day is reguarded as suspended.
33+
# - if $close is None, the stock on that day is regarded as suspended.
3434
# - $factor is for rounding to the trading unit;
3535
# - if any $factor is missing when $close exists, trading unit rounding will be disabled
3636
quote_df: pd.DataFrame
@@ -141,7 +141,7 @@ def __init__(
141141
if deal_price is None:
142142
deal_price = C.deal_price
143143

144-
# we have some verbose information here. So logging is enable
144+
# we have some verbose information here. So logging is enabled
145145
self.logger = get_module_logger("online operator")
146146

147147
# TODO: the quote, trade_dates, codes are not necessary.
@@ -168,7 +168,7 @@ def __init__(
168168
self.codes = codes
169169
# Necessary fields
170170
# $close is for calculating the total value at end of each day.
171-
# - if $close is None, the stock on that day is reguarded as suspended.
171+
# - if $close is None, the stock on that day is regarded as suspended.
172172
# $factor is for rounding to the trading unit
173173
# $change is for calculating the limit of the stock
174174

@@ -271,7 +271,7 @@ def _get_limit_type(self, limit_threshold: Union[tuple, float, None]) -> str:
271271
raise NotImplementedError(f"This type of `limit_threshold` is not supported")
272272

273273
def _update_limit(self, limit_threshold: Union[Tuple, float, None]) -> None:
274-
# $close is may contains NaN, the nan indicates that the stock is not tradable at that timestamp
274+
# $close may contain NaN, the nan indicates that the stock is not tradable at that timestamp
275275
suspended = self.quote_df["$close"].isna()
276276
# check limit_threshold
277277
limit_type = self._get_limit_type(limit_threshold)
@@ -356,12 +356,12 @@ def check_stock_limit(
356356
357357
Returns
358358
-------
359-
True: the trading of the stock is limted (maybe hit the highest/lowest price), hence the stock is not tradable
359+
True: the trading of the stock is limited (maybe hit the highest/lowest price), hence the stock is not tradable
360360
False: the trading of the stock is not limited, hence the stock may be tradable
361361
"""
362362
# NOTE:
363363
# **all** is used when checking limitation.
364-
# For example, the stock trading is limited in a day if every miniute is limited in a day if every miniute is limited.
364+
# For example, the stock trading is limited in a day if every minute is limited in a day if every minute is limited.
365365
if direction is None:
366366
# The trading limitation is related to the trading direction
367367
# if the direction is not provided, then any limitation from buy or sell will result in trading limitation
@@ -385,17 +385,17 @@ def check_stock_suspended(
385385
# is suspended
386386
if stock_id in self.quote.get_all_stock():
387387
# suspended stocks are represented by None $close stock
388-
# The $close may contains NaN,
388+
# The $close may contain NaN,
389389
close = self.quote.get_data(stock_id, start_time, end_time, "$close")
390390
if close is None:
391391
# if no close record exists
392392
return True
393393
elif isinstance(close, IndexData):
394-
# **any** non-NaN $close represents trading opportunity may exists
394+
# **any** non-NaN $close represents trading opportunity may exist
395395
# if all returned is nan, then the stock is suspended
396396
return cast(bool, cast(IndexData, close).isna().all())
397397
else:
398-
# it is single value, make sure is is not None
398+
# it is single value, make sure is not None
399399
return np.isnan(close)
400400
else:
401401
# if the stock is not in the stock list, then it is not tradable and regarded as suspended
@@ -540,8 +540,8 @@ def generate_amount_position_from_weight_position(
540540
direction: OrderDir = OrderDir.BUY,
541541
) -> dict:
542542
"""
543-
The generate the target position according to the weight and the cash.
544-
NOTE: All the cash will assigned to the tradable stock.
543+
Generates the target position according to the weight and the cash.
544+
NOTE: All the cash will be assigned to the tradable stock.
545545
Parameter:
546546
weight_position : dict {stock_id : weight}; allocate cash by weight_position
547547
among then, weight must be in this range: 0 < weight < 1
@@ -639,7 +639,7 @@ def generate_order_for_target_amount_position(
639639
random.shuffle(sorted_ids)
640640
for stock_id in sorted_ids:
641641

642-
# Do not generate order for the nontradable stocks
642+
# Do not generate order for the non-tradable stocks
643643
if not self.is_stock_tradable(stock_id=stock_id, start_time=start_time, end_time=end_time):
644644
continue
645645

qlib/contrib/data/handler.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(
5757
fit_end_time=None,
5858
filter_pipe=None,
5959
inst_processor=None,
60-
**kwargs,
60+
**kwargs
6161
):
6262
infer_processors = check_transform_proc(infer_processors, fit_start_time, fit_end_time)
6363
learn_processors = check_transform_proc(learn_processors, fit_start_time, fit_end_time)
@@ -67,7 +67,7 @@ def __init__(
6767
"kwargs": {
6868
"config": {
6969
"feature": self.get_feature_config(),
70-
"label": kwargs.get("label", self.get_label_config()),
70+
"label": kwargs.pop("label", self.get_label_config()),
7171
},
7272
"filter_pipe": filter_pipe,
7373
"freq": freq,
@@ -82,12 +82,14 @@ def __init__(
8282
data_loader=data_loader,
8383
learn_processors=learn_processors,
8484
infer_processors=infer_processors,
85+
**kwargs
8586
)
8687

8788
def get_label_config(self):
88-
return (["Ref($close, -2)/Ref($close, -1) - 1"], ["LABEL0"])
89+
return ["Ref($close, -2)/Ref($close, -1) - 1"], ["LABEL0"]
8990

90-
def get_feature_config(self):
91+
@staticmethod
92+
def get_feature_config():
9193
# NOTE:
9294
# Alpha360 tries to provide a dataset with original price data
9395
# the original price data includes the prices and volume in the last 60 days.
@@ -99,33 +101,33 @@ def get_feature_config(self):
99101
names = []
100102

101103
for i in range(59, 0, -1):
102-
fields += ["Ref($close, %d)/$close" % (i)]
103-
names += ["CLOSE%d" % (i)]
104+
fields += ["Ref($close, %d)/$close" % i]
105+
names += ["CLOSE%d" % i]
104106
fields += ["$close/$close"]
105107
names += ["CLOSE0"]
106108
for i in range(59, 0, -1):
107-
fields += ["Ref($open, %d)/$close" % (i)]
108-
names += ["OPEN%d" % (i)]
109+
fields += ["Ref($open, %d)/$close" % i]
110+
names += ["OPEN%d" % i]
109111
fields += ["$open/$close"]
110112
names += ["OPEN0"]
111113
for i in range(59, 0, -1):
112-
fields += ["Ref($high, %d)/$close" % (i)]
113-
names += ["HIGH%d" % (i)]
114+
fields += ["Ref($high, %d)/$close" % i]
115+
names += ["HIGH%d" % i]
114116
fields += ["$high/$close"]
115117
names += ["HIGH0"]
116118
for i in range(59, 0, -1):
117-
fields += ["Ref($low, %d)/$close" % (i)]
118-
names += ["LOW%d" % (i)]
119+
fields += ["Ref($low, %d)/$close" % i]
120+
names += ["LOW%d" % i]
119121
fields += ["$low/$close"]
120122
names += ["LOW0"]
121123
for i in range(59, 0, -1):
122-
fields += ["Ref($vwap, %d)/$close" % (i)]
123-
names += ["VWAP%d" % (i)]
124+
fields += ["Ref($vwap, %d)/$close" % i]
125+
names += ["VWAP%d" % i]
124126
fields += ["$vwap/$close"]
125127
names += ["VWAP0"]
126128
for i in range(59, 0, -1):
127-
fields += ["Ref($volume, %d)/($volume+1e-12)" % (i)]
128-
names += ["VOLUME%d" % (i)]
129+
fields += ["Ref($volume, %d)/($volume+1e-12)" % i]
130+
names += ["VOLUME%d" % i]
129131
fields += ["$volume/($volume+1e-12)"]
130132
names += ["VOLUME0"]
131133

@@ -134,7 +136,7 @@ def get_feature_config(self):
134136

135137
class Alpha360vwap(Alpha360):
136138
def get_label_config(self):
137-
return (["Ref($vwap, -2)/Ref($vwap, -1) - 1"], ["LABEL0"])
139+
return ["Ref($vwap, -2)/Ref($vwap, -1) - 1"], ["LABEL0"]
138140

139141

140142
class Alpha158(DataHandlerLP):
@@ -151,7 +153,7 @@ def __init__(
151153
process_type=DataHandlerLP.PTYPE_A,
152154
filter_pipe=None,
153155
inst_processor=None,
154-
**kwargs,
156+
**kwargs
155157
):
156158
infer_processors = check_transform_proc(infer_processors, fit_start_time, fit_end_time)
157159
learn_processors = check_transform_proc(learn_processors, fit_start_time, fit_end_time)
@@ -161,7 +163,7 @@ def __init__(
161163
"kwargs": {
162164
"config": {
163165
"feature": self.get_feature_config(),
164-
"label": kwargs.get("label", self.get_label_config()),
166+
"label": kwargs.pop("label", self.get_label_config()),
165167
},
166168
"filter_pipe": filter_pipe,
167169
"freq": freq,
@@ -176,6 +178,7 @@ def __init__(
176178
infer_processors=infer_processors,
177179
learn_processors=learn_processors,
178180
process_type=process_type,
181+
**kwargs
179182
)
180183

181184
def get_feature_config(self):
@@ -190,7 +193,7 @@ def get_feature_config(self):
190193
return self.parse_config_to_fields(conf)
191194

192195
def get_label_config(self):
193-
return (["Ref($close, -2)/Ref($close, -1) - 1"], ["LABEL0"])
196+
return ["Ref($close, -2)/Ref($close, -1) - 1"], ["LABEL0"]
194197

195198
@staticmethod
196199
def parse_config_to_fields(config):
@@ -426,4 +429,4 @@ def use(x):
426429

427430
class Alpha158vwap(Alpha158):
428431
def get_label_config(self):
429-
return (["Ref($vwap, -2)/Ref($vwap, -1) - 1"], ["LABEL0"])
432+
return ["Ref($vwap, -2)/Ref($vwap, -1) - 1"], ["LABEL0"]

qlib/contrib/model/pytorch_adarnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ADARNN(Model):
2828
d_feat : int
2929
input dimension for each time step
3030
metric: str
31-
the evaluate metric used in early stop
31+
the evaluation metric used in early stop
3232
optimizer : str
3333
optimizer name
3434
GPU : str

qlib/contrib/model/pytorch_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ADD(Model):
3636
d_feat : int
3737
input dimensions for each time step
3838
metric : str
39-
the evaluate metric used in early stop
39+
the evaluation metric used in early stop
4040
optimizer : str
4141
optimizer name
4242
GPU : int

qlib/contrib/model/pytorch_alstm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ALSTM(Model):
3030
d_feat : int
3131
input dimension for each time step
3232
metric: str
33-
the evaluate metric used in early stop
33+
the evaluation metric used in early stop
3434
optimizer : str
3535
optimizer name
3636
GPU : int

qlib/contrib/model/pytorch_alstm_ts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ALSTM(Model):
3333
d_feat : int
3434
input dimension for each time step
3535
metric: str
36-
the evaluate metric used in early stop
36+
the evaluation metric used in early stop
3737
optimizer : str
3838
optimizer name
3939
GPU : int

qlib/contrib/model/pytorch_gats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GATs(Model):
3333
d_feat : int
3434
input dimensions for each time step
3535
metric : str
36-
the evaluate metric used in early stop
36+
the evaluation metric used in early stop
3737
optimizer : str
3838
optimizer name
3939
GPU : int

qlib/contrib/model/pytorch_gats_ts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class GATs(Model):
5050
d_feat : int
5151
input dimensions for each time step
5252
metric : str
53-
the evaluate metric used in early stop
53+
the evaluation metric used in early stop
5454
optimizer : str
5555
optimizer name
5656
GPU : int

qlib/contrib/model/pytorch_gru.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class GRU(Model):
3030
d_feat : int
3131
input dimension for each time step
3232
metric: str
33-
the evaluate metric used in early stop
33+
the evaluation metric used in early stop
3434
optimizer : str
3535
optimizer name
3636
GPU : str

qlib/contrib/model/pytorch_gru_ts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class GRU(Model):
3131
d_feat : int
3232
input dimension for each time step
3333
metric: str
34-
the evaluate metric used in early stop
34+
the evaluation metric used in early stop
3535
optimizer : str
3636
optimizer name
3737
GPU : str

0 commit comments

Comments
 (0)