1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-06-06 14:01:28 +08:00

update some little code

This commit is contained in:
bxdd
2021-01-26 17:02:30 +00:00
parent 1b569d371d
commit 3bdd54308b
3 changed files with 25 additions and 22 deletions

View File

@@ -55,8 +55,8 @@ class HighFreqHandler(DataHandlerLP):
names = []
template_if = "If(IsNull({1}), {0}, {1})"
#template_paused = "Select(Eq($paused, 0.0), {0})"
template_paused="{0}"
template_paused = "Select(Eq($paused, 0.0), {0})"
# template_paused="{0}"
template_fillnan = "FFillNan({0})"
simpson_vwap = "($open + 2*$high + 2*$low + $close)/6"
fields += [
@@ -128,7 +128,7 @@ class HighFreqHandler(DataHandlerLP):
fields += [
"Ref({0}, 240)/Ref(DayLast({0}), 240)".format(template_fillnan.format(template_paused.format("$close")))
]
fields += [
"Ref({0}, 240)/Ref(DayLast({1}), 240)".format(
template_if.format(
@@ -196,17 +196,19 @@ class HighFreqBacktestHandler(DataHandler):
names = []
template_if = "If(Eq({1}, np.nan), {0}, {1})"
#template_paused = "Select(Eq($paused, 0.0), {0})"
template_paused="{0}"
template_paused = "Select(Eq($paused, 0.0), {0})"
# template_paused="{0}"
template_fillnan = "FFillNan({0})"
simpson_vwap = "($open + 2*$high + 2*$low + $close)/6"
#fields += [
# fields += [
# template_fillnan.format(template_paused.format("$close")),
#]
fields += [template_if.format(
template_fillnan.format(template_paused.format("$close")),
template_paused.format(simpson_vwap),
)]
# ]
fields += [
template_if.format(
template_fillnan.format(template_paused.format("$close")),
template_paused.format(simpson_vwap),
)
]
names += ["$vwap_0"]
fields += [
"If(IsNull({0}), 0, If(Or(Gt({1}, Mul(1.001, {3})), Lt({1}, Mul(0.999, {2}))), 0, {0}))".format(

View File

@@ -58,7 +58,6 @@ class HighFreqNorm(Processor):
# print("start_call_feature_reshape")
idx = df_features.index.droplevel("datetime").drop_duplicates()
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_1 = df_values[:, [5, 6, 7, 8, 9, 11]].reshape(-1, 6 * 240)
df_new_features = pd.DataFrame(

View File

@@ -38,12 +38,12 @@ if __name__ == "__main__":
MARKET = "all"
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"
#end_time = "2019-12-31 15:00:00"
#train_end_time = "2019-05-31 15:00:00"
#test_start_time = "2019-06-01 00:00:00"
# start_time = "2019-01-01 00:00:00"
# end_time = "2019-12-31 15:00:00"
# train_end_time = "2019-05-31 15:00:00"
# test_start_time = "2019-06-01 00:00:00"
start_time = "2020-09-14 00:00:00"
end_time = "2021-01-18 16:00:00"
train_end_time = "2020-11-30 16:00:00"
@@ -108,11 +108,12 @@ if __name__ == "__main__":
},
}
##=============load the calendar for cache=============
Cal.calendar(freq="1min")
Cal.get_calendar_day(freq="1min")
# unnecessary, but may accelerate
Cal.calendar(freq="1min") # load the calendar for cache
Cal.get_calendar_day(freq="1min") # load the calendar for cache
##=============get data=============
dataset = init_instance_by_config(task["dataset"])
xtrain, xtest = dataset.prepare(["train", "test"])
print(xtrain, xtest)
@@ -124,7 +125,7 @@ if __name__ == "__main__":
del xtrain, xtest
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:
##=============dump dataset=============
@@ -147,6 +148,7 @@ if __name__ == "__main__":
dataset_backtest.init(init_type=DataHandlerLP.IT_LS)
##=============reinit qlib=============
## Unless you want to modify the provider_uri and other configurations, reinit is unnecessary
qlib.init(
provider_uri=provider_uri,
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.get_calendar_day(freq="1min") # load the calendar for cache
##=============test dataset
##=============test dataset=============
xtrain, xtest = dataset.prepare(["train", "test"])
backtest_train, backtest_test = dataset_backtest.prepare(["train", "test"])