事件驱动
- 读取本地数据
- 添加金叉事件
- 计算binary事件
- 查看绩效
1_读取本地数据
import numpy as np
from jaqs.data import DataView
from jaqs.research import SignalDigger
import warnings
warnings.filterwarnings("ignore")
dataview_folder = 'JAQS_Data/hs300'
dv = DataView()
dv.load_dataview(dataview_folder)
D:\Anaconda3\lib\site-packages\statsmodels\compat\pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
from pandas.core import datetools
Dataview loaded successfully.
mask = dv.get_ts('mask_index_member')
can_enter = dv.get_ts('can_enter')
can_exit = dv.get_ts('can_exit')
2_添加金叉事件
dv.remove_field('above')
dv.remove_field('delay_above')
dv.remove_field('sig_cross')
Field name [above] does not exist.
Field name [delay_above] does not exist.
Field name [sig_cross] does not exist.
def add_event():
dv.add_formula('above', ' Ts_Mean(close_adj, 10) >= Ts_Mean(close_adj, 40)', is_quarterly=False)
dv.add_formula('delay_above', 'Delay(above, 1)', is_quarterly=False)
dv.add_formula('sig_cross', 'above&&(!delay_above)', is_quarterly=False)
add_event()
3_计算binary事件
import matplotlib.pyplot as plt
def cal_obj(signal, name, period):
price = dv.get_ts('close_adj').loc[20160105:]
# price_bench = dv.data_benchmark.loc[20160105:]
# Step.4 analyze!
obj = SignalDigger()
df_all, df_events, df_stats = obj.create_binary_event_report(signal.loc[20160105:], price, mask.loc[20160105:], can_enter.loc[20160105:], can_exit.loc[20160105:],periods=[period,period*2, period*3])
res = obj.create_full_report()
print(df_stats)
return obj
def plot_pfm(signal, name, period=5):
obj = cal_obj(signal, name, period)
obj.fig_objs
plt.show()
def signal_data(signal, name, period=5):
obj = cal_obj(signal, name, period)
return obj.signal_data
signal = dv.get_ts('sig_cross')
4_查看事件绩效
- 统计信息
- 回测绩效
- 事件表格
#统计信息
#回测绩效
plot_pfm(signal,'cross_sig', period=4)
Nan Data Count (should be zero) : 0; Percentage of effective data: 53%
Nan Data Count (should be zero) : 0; Percentage of effective data: 53%
Nan Data Count (should be zero) : 0; Percentage of effective data: 53%
Calendar Distribution (3696 occurance from 2016-01-05 to 2017-12-22):
Figure saved: C:\Users\small\OneDrive\notebook\Internet_Course\Selection\JAQS\event_report.pdf
Value of signals of Different Quantiles Statistics
min max mean std count count %
quantile
1 0.0 1.0 0.015204 0.122365 136475 100.0
Figure saved: C:\Users\small\OneDrive\notebook\Internet_Course\Selection\JAQS\returns_report.pdf
Information Analysis
ic
IC Mean -0.002
IC Std. 0.066
t-stat(IC) NaN
p-value(IC) NaN
IC Skew NaN
IC Kurtosis NaN
Ann. IR -0.037
Figure saved: C:\Users\small\OneDrive\notebook\Internet_Course\Selection\JAQS\information_report.pdf
Annu. Ret. Annu. Vol. t-stat p-value skewness \
trade_date Period
all_sample 4 0.195337 0.297228 3.848801 0.00012 0.660572
8 0.252103 0.279498 7.470432 0.00000 0.742530
12 0.234839 0.272293 8.748348 0.00000 0.567819
kurtosis occurance Annu. Ret. (all samp) \
trade_date Period
all_sample 4 4.367479 2075 0.050040
8 5.040717 2075 0.067030
12 2.933731 2075 0.073625
Annu. Vol. (all samp)
trade_date Period
all_sample 4 0.311621
8 0.297248
12 0.291717



signal_data = signal_data(signal,'cross_sig', period=4)
Nan Data Count (should be zero) : 0; Percentage of effective data: 53%
Nan Data Count (should be zero) : 0; Percentage of effective data: 53%
Nan Data Count (should be zero) : 0; Percentage of effective data: 53%
Calendar Distribution (3696 occurance from 2016-01-05 to 2017-12-22):
Figure saved: C:\Users\small\OneDrive\notebook\Internet_Course\Selection\JAQS\event_report.pdf
Value of signals of Different Quantiles Statistics
min max mean std count count %
quantile
1 0.0 1.0 0.015204 0.122365 136475 100.0
Figure saved: C:\Users\small\OneDrive\notebook\Internet_Course\Selection\JAQS\returns_report.pdf
Information Analysis
ic
IC Mean -0.002
IC Std. 0.066
t-stat(IC) NaN
p-value(IC) NaN
IC Skew NaN
IC Kurtosis NaN
Ann. IR -0.037
Figure saved: C:\Users\small\OneDrive\notebook\Internet_Course\Selection\JAQS\information_report.pdf
Annu. Ret. Annu. Vol. t-stat p-value skewness \
trade_date Period
all_sample 4 0.195337 0.297228 3.848801 0.00012 0.660572
8 0.252103 0.279498 7.470432 0.00000 0.742530
12 0.234839 0.272293 8.748348 0.00000 0.567819
kurtosis occurance Annu. Ret. (all samp) \
trade_date Period
all_sample 4 4.367479 2075 0.050040
8 5.040717 2075 0.067030
12 2.933731 2075 0.073625
Annu. Vol. (all samp)
trade_date Period
all_sample 4 0.311621
8 0.297248
12 0.291717
signal_df = signal_data.signal[signal_data.signal==1].unstack()
# 事件表格
print(signal_df.tail().stack())
trade_date symbol
20171218 002008.SZ 1.0
600519.SH 1.0
20171219 600009.SH 1.0
20171220 002608.SZ 1.0
601117.SH 1.0
601933.SH 1.0
20171221 000568.SZ 1.0
002304.SZ 1.0
002508.SZ 1.0
002555.SZ 1.0
600276.SH 1.0
600660.SH 1.0
20171222 601939.SH 1.0
603833.SH 1.0
dtype: float64
# 保存成excel
signal_df.to_excel('signal_df.xlsx')