mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-11 06:46:56 +08:00
update some little code
This commit is contained in:
@@ -55,8 +55,8 @@ class HighFreqHandler(DataHandlerLP):
|
|||||||
names = []
|
names = []
|
||||||
|
|
||||||
template_if = "If(IsNull({1}), {0}, {1})"
|
template_if = "If(IsNull({1}), {0}, {1})"
|
||||||
#template_paused = "Select(Eq($paused, 0.0), {0})"
|
template_paused = "Select(Eq($paused, 0.0), {0})"
|
||||||
template_paused="{0}"
|
# template_paused="{0}"
|
||||||
template_fillnan = "FFillNan({0})"
|
template_fillnan = "FFillNan({0})"
|
||||||
simpson_vwap = "($open + 2*$high + 2*$low + $close)/6"
|
simpson_vwap = "($open + 2*$high + 2*$low + $close)/6"
|
||||||
fields += [
|
fields += [
|
||||||
@@ -196,17 +196,19 @@ class HighFreqBacktestHandler(DataHandler):
|
|||||||
names = []
|
names = []
|
||||||
|
|
||||||
template_if = "If(Eq({1}, np.nan), {0}, {1})"
|
template_if = "If(Eq({1}, np.nan), {0}, {1})"
|
||||||
#template_paused = "Select(Eq($paused, 0.0), {0})"
|
template_paused = "Select(Eq($paused, 0.0), {0})"
|
||||||
template_paused="{0}"
|
# template_paused="{0}"
|
||||||
template_fillnan = "FFillNan({0})"
|
template_fillnan = "FFillNan({0})"
|
||||||
simpson_vwap = "($open + 2*$high + 2*$low + $close)/6"
|
simpson_vwap = "($open + 2*$high + 2*$low + $close)/6"
|
||||||
#fields += [
|
# fields += [
|
||||||
# template_fillnan.format(template_paused.format("$close")),
|
# template_fillnan.format(template_paused.format("$close")),
|
||||||
#]
|
# ]
|
||||||
fields += [template_if.format(
|
fields += [
|
||||||
template_fillnan.format(template_paused.format("$close")),
|
template_if.format(
|
||||||
template_paused.format(simpson_vwap),
|
template_fillnan.format(template_paused.format("$close")),
|
||||||
)]
|
template_paused.format(simpson_vwap),
|
||||||
|
)
|
||||||
|
]
|
||||||
names += ["$vwap_0"]
|
names += ["$vwap_0"]
|
||||||
fields += [
|
fields += [
|
||||||
"If(IsNull({0}), 0, If(Or(Gt({1}, Mul(1.001, {3})), Lt({1}, Mul(0.999, {2}))), 0, {0}))".format(
|
"If(IsNull({0}), 0, If(Or(Gt({1}, Mul(1.001, {3})), Lt({1}, Mul(0.999, {2}))), 0, {0}))".format(
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ class HighFreqNorm(Processor):
|
|||||||
# print("start_call_feature_reshape")
|
# print("start_call_feature_reshape")
|
||||||
idx = df_features.index.droplevel("datetime").drop_duplicates()
|
idx = df_features.index.droplevel("datetime").drop_duplicates()
|
||||||
idx.set_names(["instrument", "datetime"], inplace=True)
|
idx.set_names(["instrument", "datetime"], inplace=True)
|
||||||
print(df_values.shape)
|
|
||||||
feat = df_values[:, [0, 1, 2, 3, 4, 10]].reshape(-1, 6 * 240)
|
feat = df_values[:, [0, 1, 2, 3, 4, 10]].reshape(-1, 6 * 240)
|
||||||
feat_1 = df_values[:, [5, 6, 7, 8, 9, 11]].reshape(-1, 6 * 240)
|
feat_1 = df_values[:, [5, 6, 7, 8, 9, 11]].reshape(-1, 6 * 240)
|
||||||
df_new_features = pd.DataFrame(
|
df_new_features = pd.DataFrame(
|
||||||
|
|||||||
@@ -38,12 +38,12 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
MARKET = "all"
|
MARKET = "all"
|
||||||
BENCHMARK = "SH000300"
|
BENCHMARK = "SH000300"
|
||||||
DROP_LOAD_DATASET = False # flag wether to test [drop and load dataset]
|
DROP_LOAD_DATASET = False # flag wether to test [drop and load dataset]
|
||||||
|
|
||||||
#start_time = "2019-01-01 00:00:00"
|
# start_time = "2019-01-01 00:00:00"
|
||||||
#end_time = "2019-12-31 15:00:00"
|
# end_time = "2019-12-31 15:00:00"
|
||||||
#train_end_time = "2019-05-31 15:00:00"
|
# train_end_time = "2019-05-31 15:00:00"
|
||||||
#test_start_time = "2019-06-01 00:00:00"
|
# test_start_time = "2019-06-01 00:00:00"
|
||||||
start_time = "2020-09-14 00:00:00"
|
start_time = "2020-09-14 00:00:00"
|
||||||
end_time = "2021-01-18 16:00:00"
|
end_time = "2021-01-18 16:00:00"
|
||||||
train_end_time = "2020-11-30 16:00:00"
|
train_end_time = "2020-11-30 16:00:00"
|
||||||
@@ -108,8 +108,9 @@ if __name__ == "__main__":
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
##=============load the calendar for cache=============
|
##=============load the calendar for cache=============
|
||||||
Cal.calendar(freq="1min")
|
# unnecessary, but may accelerate
|
||||||
Cal.get_calendar_day(freq="1min")
|
Cal.calendar(freq="1min") # load the calendar for cache
|
||||||
|
Cal.get_calendar_day(freq="1min") # load the calendar for cache
|
||||||
|
|
||||||
##=============get data=============
|
##=============get data=============
|
||||||
|
|
||||||
@@ -124,7 +125,7 @@ if __name__ == "__main__":
|
|||||||
del xtrain, xtest
|
del xtrain, xtest
|
||||||
del backtest_train, backtest_test
|
del backtest_train, backtest_test
|
||||||
|
|
||||||
|
## example to show how to save the dataset and reload it, and how to use different data
|
||||||
if DROP_LOAD_DATASET:
|
if DROP_LOAD_DATASET:
|
||||||
|
|
||||||
##=============dump dataset=============
|
##=============dump dataset=============
|
||||||
@@ -147,6 +148,7 @@ if __name__ == "__main__":
|
|||||||
dataset_backtest.init(init_type=DataHandlerLP.IT_LS)
|
dataset_backtest.init(init_type=DataHandlerLP.IT_LS)
|
||||||
|
|
||||||
##=============reinit qlib=============
|
##=============reinit qlib=============
|
||||||
|
## Unless you want to modify the provider_uri and other configurations, reinit is unnecessary
|
||||||
qlib.init(
|
qlib.init(
|
||||||
provider_uri=provider_uri,
|
provider_uri=provider_uri,
|
||||||
custom_ops=[DayFirst, DayLast, FFillNan, Date, Select, IsNull],
|
custom_ops=[DayFirst, DayLast, FFillNan, Date, Select, IsNull],
|
||||||
@@ -158,7 +160,7 @@ if __name__ == "__main__":
|
|||||||
Cal.calendar(freq="1min") # load the calendar for cache
|
Cal.calendar(freq="1min") # load the calendar for cache
|
||||||
Cal.get_calendar_day(freq="1min") # load the calendar for cache
|
Cal.get_calendar_day(freq="1min") # load the calendar for cache
|
||||||
|
|
||||||
##=============test dataset
|
##=============test dataset=============
|
||||||
xtrain, xtest = dataset.prepare(["train", "test"])
|
xtrain, xtest = dataset.prepare(["train", "test"])
|
||||||
backtest_train, backtest_test = dataset_backtest.prepare(["train", "test"])
|
backtest_train, backtest_test = dataset_backtest.prepare(["train", "test"])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user