掘金社区

【手写】东方财富/掘金量化 增强libPinned highlighted

niemand01 发表在策略研究 2021-10-25 23:38:12

策略研究
384
4
0

dflib_base

东方财富/掘金量化 增强lib

示例回测


0_1635176066878_sample_strategy.png
根据东财+掘金的量化API
定制个人希望的函数/策略

源码择时在GITHUB公开,先在论坛每日记录一下使用指南API

目前实现功能:

  1. demo:
    1.1fama-french 3因子全代码
    1.2行业轮动+m2货币+capm策略
    1.3carhart 4因子
    1.4PE选股+MA止损
  2. 指标类
    2.1 MACD,KDJ,RSI,MA,BOLLING判断+决策
    2.2 CAPM计算+决策
    2.3 股吧当日情绪面抓取+分析
  3. IO
    3.1 宏观函数抓取:ppi,m2...
    3.2 本地下载全A股股市K线数据+每日更新
    3.3 本地下载全A股财务数据+更新
  4. 选股
    4.1剔除股票:根据ST,上市,停牌,B股,新股
    4.2获取历史全A股停牌股票
  5. Util
    5.1全A股板块抓取
    5.2全A股行业抓取
    5.3获取当日涨幅榜
    5.4可视化阻力位和支撑位

27.10 每日更新一些代码

评论: 4
  • def calc_MACD(data=None,short=12,long=26,m=9):
        """
            MACD 计算,从IPO时间开始
            原理:https://baike.baidu.com/item/MACD%E6%8C%87%E6%A0%87/6271283
            注意:
                1.和东方财富数据不一样
                2.dfcf公式定义alpha参数,原文是定义了span=12/26
            
            #手动递归EMA12,26
            # all_history.loc[short,f'EMA_{short}'] = all_history.loc[:short-1,'close'].mean()
            # all_history.loc[long,f'EMA_{long}'] = all_history.loc[:long-1,'close'].mean()
            # #递归后面的数据
            # for i in range(short,all_history.shape[0]-1):
            #     all_history.loc[i+1,f'EMA_{short}'] = all_history.loc[i,f'EMA_{short}']*11/13 + all_history.loc[i+1,'close']*2/13
            #     if i >= long:
            #         all_history.loc[i+1,f'EMA_{long}'] = all_history.loc[i,f'EMA_{long}']*25/27 + all_history.loc[i+1,'close']*2/27
            
            
    
        """
        all_history = data.copy()
        all_history[f'EMA_{short}'] = all_history['close'].ewm(alpha=2/13,adjust=False).mean()
        all_history[f'EMA_{long}'] = all_history['close'].ewm(alpha=2/27,adjust=False).mean()
        #计算DIF
        all_history['DIF'] = all_history[f'EMA_{short}']- all_history[f'EMA_{long}']
        #计算DEM/DEA
        all_history['DEA'] = all_history['DIF'].ewm(alpha=2/10,adjust=False).mean()
        #计算MACD
        all_history['MACD'] = (all_history['DIF']-all_history['DEA'])*2
    
        return all_history
    
    2021-10-27 16:04:04
  • def calc_MA(data=None,short=10,long=50):
        """
            MA 计算,从IPO时间开始
            短线10天,长线50天
    
            example:
                dataset = calc_MA(data=all_history[-51:])  
                dataset
        """
        all_history = data.copy()
        all_history[f'MA_short'] = all_history['close'].rolling(short).mean()
        all_history[f'MA_long'] = all_history['close'].rolling(long).mean()
        return all_history
    
    2021-10-28 03:27:05
  • 666,得来全不费工夫,踏破铁鞋无觅处

    2021-10-29 18:08:59
  • def calc_Bolling(data=None,N=20):
        """
            参考:https://blog.csdn.net/stonesssssss/article/details/112323348?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link
        
            # calc_Bolling(data=all_history)
        """
        df = data.copy().reset_index(drop=True)
        df['BOLL'] = df['close'].rolling(N).mean()
        df['UB'] = df['BOLL'] + 2* data['close'].rolling(N).std()
        df['LB'] = df['BOLL'] - 2* data['close'].rolling(N).std()
        
        df['WIDTH_BOLL'] = (df['UB'] - df['LB'])/df['BOLL']
        df[['BOLL','UB','LB']] = df[['BOLL','UB','LB']].fillna(0)
        return df
    
    
    2021-10-29 20:12:02

Looks like your connection to 掘金量化社区 - 量化交易者的交流社区 was lost, please wait while we try to reconnect.