克隆策略
In [450]:
df=DataSource('bar1m_CN_FUTURE').read(instruments=['RM2201.CZC'],start_date='2021-09-02',end_date='2021-09-02')
df
Out[450]:
instrument date trading_day open close low high volume amount open_intl product_code
0 RM2201.CZC 2021-09-02 09:01:00 20210902 2845.0 2842.0 2841.0 2845.0 7104 198093380.0 401058.0 RM
1 RM2201.CZC 2021-09-02 09:02:00 20210902 2842.0 2841.0 2839.0 2842.0 6596 187920040.0 401445.0 RM
2 RM2201.CZC 2021-09-02 09:03:00 20210902 2841.0 2841.0 2839.0 2841.0 3385 96438650.0 401766.0 RM
3 RM2201.CZC 2021-09-02 09:04:00 20210902 2840.0 2838.0 2837.0 2841.0 3575 101851750.0 402092.0 RM
4 RM2201.CZC 2021-09-02 09:05:00 20210902 2838.0 2839.0 2837.0 2839.0 2720 77492800.0 403118.0 RM
... ... ... ... ... ... ... ... ... ... ... ...
340 RM2201.CZC 2021-09-02 22:56:00 20210903 2868.0 2867.0 2867.0 2870.0 3044 87362800.0 385244.0 RM
341 RM2201.CZC 2021-09-02 22:57:00 20210903 2868.0 2868.0 2867.0 2869.0 1704 48904800.0 385224.0 RM
342 RM2201.CZC 2021-09-02 22:58:00 20210903 2868.0 2867.0 2867.0 2869.0 1729 49622300.0 384738.0 RM
343 RM2201.CZC 2021-09-02 22:59:00 20210903 2868.0 2867.0 2866.0 2868.0 1772 50856400.0 384247.0 RM
344 RM2201.CZC 2021-09-02 23:00:00 20210903 2867.0 2868.0 2865.0 2869.0 4419 126825300.0 382467.0 RM

345 rows × 11 columns

In [451]:
print(type(df)) 
<class 'pandas.core.frame.DataFrame'>
In [452]:
df.to_csv('cb20210902.csv')
In [453]:
import pandas as pd
df=DataSource('bar1m_CN_FUTURE').read(instruments=['RM2201.CZC'],start_date='2021-09-02',end_date='2021-09-02')
df
Out[453]:
instrument date trading_day open close low high volume amount open_intl product_code
0 RM2201.CZC 2021-09-02 09:01:00 20210902 2845.0 2842.0 2841.0 2845.0 7104 198093380.0 401058.0 RM
1 RM2201.CZC 2021-09-02 09:02:00 20210902 2842.0 2841.0 2839.0 2842.0 6596 187920040.0 401445.0 RM
2 RM2201.CZC 2021-09-02 09:03:00 20210902 2841.0 2841.0 2839.0 2841.0 3385 96438650.0 401766.0 RM
3 RM2201.CZC 2021-09-02 09:04:00 20210902 2840.0 2838.0 2837.0 2841.0 3575 101851750.0 402092.0 RM
4 RM2201.CZC 2021-09-02 09:05:00 20210902 2838.0 2839.0 2837.0 2839.0 2720 77492800.0 403118.0 RM
... ... ... ... ... ... ... ... ... ... ... ...
340 RM2201.CZC 2021-09-02 22:56:00 20210903 2868.0 2867.0 2867.0 2870.0 3044 87362800.0 385244.0 RM
341 RM2201.CZC 2021-09-02 22:57:00 20210903 2868.0 2868.0 2867.0 2869.0 1704 48904800.0 385224.0 RM
342 RM2201.CZC 2021-09-02 22:58:00 20210903 2868.0 2867.0 2867.0 2869.0 1729 49622300.0 384738.0 RM
343 RM2201.CZC 2021-09-02 22:59:00 20210903 2868.0 2867.0 2866.0 2868.0 1772 50856400.0 384247.0 RM
344 RM2201.CZC 2021-09-02 23:00:00 20210903 2867.0 2868.0 2865.0 2869.0 4419 126825300.0 382467.0 RM

345 rows × 11 columns

In [ ]:
 
In [454]:
#df.dtyp()
df.set_index('date')
Out[454]:
instrument trading_day open close low high volume amount open_intl product_code
date
2021-09-02 09:01:00 RM2201.CZC 20210902 2845.0 2842.0 2841.0 2845.0 7104 198093380.0 401058.0 RM
2021-09-02 09:02:00 RM2201.CZC 20210902 2842.0 2841.0 2839.0 2842.0 6596 187920040.0 401445.0 RM
2021-09-02 09:03:00 RM2201.CZC 20210902 2841.0 2841.0 2839.0 2841.0 3385 96438650.0 401766.0 RM
2021-09-02 09:04:00 RM2201.CZC 20210902 2840.0 2838.0 2837.0 2841.0 3575 101851750.0 402092.0 RM
2021-09-02 09:05:00 RM2201.CZC 20210902 2838.0 2839.0 2837.0 2839.0 2720 77492800.0 403118.0 RM
... ... ... ... ... ... ... ... ... ... ...
2021-09-02 22:56:00 RM2201.CZC 20210903 2868.0 2867.0 2867.0 2870.0 3044 87362800.0 385244.0 RM
2021-09-02 22:57:00 RM2201.CZC 20210903 2868.0 2868.0 2867.0 2869.0 1704 48904800.0 385224.0 RM
2021-09-02 22:58:00 RM2201.CZC 20210903 2868.0 2867.0 2867.0 2869.0 1729 49622300.0 384738.0 RM
2021-09-02 22:59:00 RM2201.CZC 20210903 2868.0 2867.0 2866.0 2868.0 1772 50856400.0 384247.0 RM
2021-09-02 23:00:00 RM2201.CZC 20210903 2867.0 2868.0 2865.0 2869.0 4419 126825300.0 382467.0 RM

345 rows × 10 columns

In [455]:
groups=df.groupby('trading_day')
print(type(groups))
<class 'pandas.core.groupby.generic.DataFrameGroupBy'>
In [456]:
for k,v in groups:
    print(k)
    print(v)
20210902
     instrument                date  trading_day    open   close     low  \
0    RM2201.CZC 2021-09-02 09:01:00     20210902  2845.0  2842.0  2841.0   
1    RM2201.CZC 2021-09-02 09:02:00     20210902  2842.0  2841.0  2839.0   
2    RM2201.CZC 2021-09-02 09:03:00     20210902  2841.0  2841.0  2839.0   
3    RM2201.CZC 2021-09-02 09:04:00     20210902  2840.0  2838.0  2837.0   
4    RM2201.CZC 2021-09-02 09:05:00     20210902  2838.0  2839.0  2837.0   
..          ...                 ...          ...     ...     ...     ...   
220  RM2201.CZC 2021-09-02 14:56:00     20210902  2873.0  2871.0  2870.0   
221  RM2201.CZC 2021-09-02 14:57:00     20210902  2871.0  2872.0  2871.0   
222  RM2201.CZC 2021-09-02 14:58:00     20210902  2872.0  2870.0  2870.0   
223  RM2201.CZC 2021-09-02 14:59:00     20210902  2871.0  2870.0  2869.0   
224  RM2201.CZC 2021-09-02 15:00:00     20210902  2870.0  2871.0  2869.0   

       high  volume       amount  open_intl product_code  
0    2845.0    7104  198093380.0   401058.0           RM  
1    2842.0    6596  187920040.0   401445.0           RM  
2    2841.0    3385   96438650.0   401766.0           RM  
3    2841.0    3575  101851750.0   402092.0           RM  
4    2839.0    2720   77492800.0   403118.0           RM  
..      ...     ...          ...        ...          ...  
220  2874.0    4691  143709300.0   390478.0           RM  
221  2872.0    1056   30127680.0   390229.0           RM  
222  2874.0    4578  130610340.0   390106.0           RM  
223  2872.0    3375   96288750.0   389496.0           RM  
224  2872.0    4141  118142730.0   388818.0           RM  

[225 rows x 11 columns]
20210903
     instrument                date  trading_day    open   close     low  \
225  RM2201.CZC 2021-09-02 21:01:00     20210903  2871.0  2872.0  2871.0   
226  RM2201.CZC 2021-09-02 21:02:00     20210903  2873.0  2872.0  2870.0   
227  RM2201.CZC 2021-09-02 21:03:00     20210903  2872.0  2870.0  2870.0   
228  RM2201.CZC 2021-09-02 21:04:00     20210903  2870.0  2868.0  2868.0   
229  RM2201.CZC 2021-09-02 21:05:00     20210903  2868.0  2870.0  2868.0   
..          ...                 ...          ...     ...     ...     ...   
340  RM2201.CZC 2021-09-02 22:56:00     20210903  2868.0  2867.0  2867.0   
341  RM2201.CZC 2021-09-02 22:57:00     20210903  2868.0  2868.0  2867.0   
342  RM2201.CZC 2021-09-02 22:58:00     20210903  2868.0  2867.0  2867.0   
343  RM2201.CZC 2021-09-02 22:59:00     20210903  2868.0  2867.0  2866.0   
344  RM2201.CZC 2021-09-02 23:00:00     20210903  2867.0  2868.0  2865.0   

       high  volume       amount  open_intl product_code  
225  2876.0   11955  343586700.0   388044.0           RM  
226  2874.0    7169  205845820.0   388137.0           RM  
227  2873.0    4736  135826680.0   388540.0           RM  
228  2871.0    4599  132083280.0   389036.0           RM  
229  2870.0    2987   85786640.0   389403.0           RM  
..      ...     ...          ...        ...          ...  
340  2870.0    3044   87362800.0   385244.0           RM  
341  2869.0    1704   48904800.0   385224.0           RM  
342  2869.0    1729   49622300.0   384738.0           RM  
343  2868.0    1772   50856400.0   384247.0           RM  
344  2869.0    4419  126825300.0   382467.0           RM  

[120 rows x 11 columns]
In [457]:
df.to_csv('groups.csv')
In [458]:
for k,v in groups:
    print(k)
    print(v.hist())
20210902
[[<AxesSubplot:title={'center':'date'}>
  <AxesSubplot:title={'center':'trading_day'}>
  <AxesSubplot:title={'center':'open'}>]
 [<AxesSubplot:title={'center':'close'}>
  <AxesSubplot:title={'center':'low'}>
  <AxesSubplot:title={'center':'high'}>]
 [<AxesSubplot:title={'center':'volume'}>
  <AxesSubplot:title={'center':'amount'}>
  <AxesSubplot:title={'center':'open_intl'}>]]
20210903
[[<AxesSubplot:title={'center':'date'}>
  <AxesSubplot:title={'center':'trading_day'}>
  <AxesSubplot:title={'center':'open'}>]
 [<AxesSubplot:title={'center':'close'}>
  <AxesSubplot:title={'center':'low'}>
  <AxesSubplot:title={'center':'high'}>]
 [<AxesSubplot:title={'center':'volume'}>
  <AxesSubplot:title={'center':'amount'}>
  <AxesSubplot:title={'center':'open_intl'}>]]
In [459]:
df['low'].min()
Out[459]:
2834.0
In [460]:
df2= DataSource('bar1m_HC2101.SHF').read(start_date='2021-01-01',end_date='2021-01-02')
In [461]:
df.reset_index()
Out[461]:
index instrument date trading_day open close low high volume amount open_intl product_code
0 0 RM2201.CZC 2021-09-02 09:01:00 20210902 2845.0 2842.0 2841.0 2845.0 7104 198093380.0 401058.0 RM
1 1 RM2201.CZC 2021-09-02 09:02:00 20210902 2842.0 2841.0 2839.0 2842.0 6596 187920040.0 401445.0 RM
2 2 RM2201.CZC 2021-09-02 09:03:00 20210902 2841.0 2841.0 2839.0 2841.0 3385 96438650.0 401766.0 RM
3 3 RM2201.CZC 2021-09-02 09:04:00 20210902 2840.0 2838.0 2837.0 2841.0 3575 101851750.0 402092.0 RM
4 4 RM2201.CZC 2021-09-02 09:05:00 20210902 2838.0 2839.0 2837.0 2839.0 2720 77492800.0 403118.0 RM
... ... ... ... ... ... ... ... ... ... ... ... ...
340 340 RM2201.CZC 2021-09-02 22:56:00 20210903 2868.0 2867.0 2867.0 2870.0 3044 87362800.0 385244.0 RM
341 341 RM2201.CZC 2021-09-02 22:57:00 20210903 2868.0 2868.0 2867.0 2869.0 1704 48904800.0 385224.0 RM
342 342 RM2201.CZC 2021-09-02 22:58:00 20210903 2868.0 2867.0 2867.0 2869.0 1729 49622300.0 384738.0 RM
343 343 RM2201.CZC 2021-09-02 22:59:00 20210903 2868.0 2867.0 2866.0 2868.0 1772 50856400.0 384247.0 RM
344 344 RM2201.CZC 2021-09-02 23:00:00 20210903 2867.0 2868.0 2865.0 2869.0 4419 126825300.0 382467.0 RM

345 rows × 12 columns

In [462]:
df.index
Out[462]:
RangeIndex(start=0, stop=345, step=1)
In [463]:
df.index[0]
Out[463]:
0
In [464]:
df.iloc[3,0]
Out[464]:
'RM2201.CZC'
In [ ]:
 
In [465]:
df.iloc[3,0]
Out[465]:
'RM2201.CZC'

    {"description":"实验创建于2021/9/4","graph":{"edges":[{"to_node_id":"-2916:instruments","from_node_id":"-1118:data"},{"to_node_id":"-2916:features","from_node_id":"-2574:data"},{"to_node_id":"-168:features","from_node_id":"-2574:data"},{"to_node_id":"-168:input_data","from_node_id":"-2916:data"},{"to_node_id":"-35:input_data","from_node_id":"-168:data"}],"nodes":[{"node_id":"-1118","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2021-08-02","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-09-02","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_FUTURE","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"RM2201.CZC","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-1118"}],"output_ports":[{"name":"data","node_id":"-1118"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-2574","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nopen=open_0/adjust_factor_0\nhigh=high_0/adjust_factor_0\nlow=low_0/adjust_factor_0\nclose=close_0/adjust_factor_0\namount=amount_0/adjust_factor_0\nma5=mean(close,5)\nvolume=volume_0/adjust_factor_0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-2574"}],"output_ports":[{"name":"data","node_id":"-2574"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-2916","module_id":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":"10","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-2916"},{"name":"features","node_id":"-2916"}],"output_ports":[{"name":"data","node_id":"-2916"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-168","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"drop_na","value":"False","type":"Literal","bound_global_parameter":null},{"name":"remove_extra_columns","value":"False","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"{}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-168"},{"name":"features","node_id":"-168"}],"output_ports":[{"name":"data","node_id":"-168"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-35","module_id":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","parameters":[{"name":"title","value":"时间序列图","type":"Literal","bound_global_parameter":null},{"name":"chart_type","value":"candlestick","type":"Literal","bound_global_parameter":null},{"name":"x","value":"date","type":"Literal","bound_global_parameter":null},{"name":"y","value":"open ,high ,low,close,amount,ma5","type":"Literal","bound_global_parameter":null},{"name":"options","value":"{\n \"chart\": {\"height\": 600},\n \"yAxis\": [\n {\"tilte\": {\"text\": \"价格\"}},\n {\"tilte\": {\"text\": \"成交额\"},\"top\": \"45%\", \"height\": \"50%\",\"offset\":0}\n ],\n 'series': [\n {'yAxis': 0},\n {'type': 'column','yAxis':1},\n {'data':[m5.data.read()[['date']],m5.data.read()[['ma5']]],'type':'spline','yAxis':0}]\n}","type":"Literal","bound_global_parameter":null},{"name":"candlestick","value":"True","type":"Literal","bound_global_parameter":null},{"name":"pane_1","value":"","type":"Literal","bound_global_parameter":null},{"name":"pane_2","value":"","type":"Literal","bound_global_parameter":null},{"name":"pane_3","value":"","type":"Literal","bound_global_parameter":null},{"name":"pane_4","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-35"}],"output_ports":[],"cacheable":false,"seq_num":6,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-1118' Position='251,-2,200,200'/><node_position Node='-2574' Position='545,-6,200,200'/><node_position Node='-2916' Position='443,164,200,200'/><node_position Node='-168' Position='651.1368408203125,279.4560241699219,200,200'/><node_position Node='-35' Position='625.0488891601562,401.114013671875,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [2]:
    # 本代码由可视化策略环境自动生成 2021年9月14日 15:39
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m1 = M.instruments.v2(
        start_date='2021-08-02',
        end_date='2021-09-02',
        market='CN_FUTURE',
        instrument_list='RM2201.CZC',
        max_count=0
    )
    
    m3 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    open=open_0/adjust_factor_0
    high=high_0/adjust_factor_0
    low=low_0/adjust_factor_0
    close=close_0/adjust_factor_0
    amount=amount_0/adjust_factor_0
    ma5=mean(close,5)
    volume=volume_0/adjust_factor_0"""
    )
    
    m4 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=10
    )
    
    m5 = M.derived_feature_extractor.v3(
        input_data=m4.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m6 = M.plot_dataframe.v1(
        input_data=m5.data,
        title='时间序列图',
        chart_type='candlestick',
        x='date',
        y='open ,high ,low,close,amount,ma5',
        options={
        "chart": {"height": 600},
        "yAxis": [
                  {"tilte": {"text": "价格"}},
                  {"tilte": {"text": "成交额"},"top": "45%", "height": "50%","offset":0}
                 ],
        'series': [
                   {'yAxis': 0},
                   {'type': 'column','yAxis':1},
                   {'data':[m5.data.read()[['date']],m5.data.read()[['ma5']]],'type':'spline','yAxis':0}]
    },
        candlestick=True,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    ---------------------------------------------------------------------------
    Exception                                 Traceback (most recent call last)
    <ipython-input-2-8e2e8480616d> in <module>
         24 )
         25 
    ---> 26 m4 = M.general_feature_extractor.v7(
         27     instruments=m1.data,
         28     features=m3.data,
    
    Exception: no features extracted.
    In [ ]: