最大回撤

def get_maxdown_ratio(df):
    se = df['cumprod_value']
    se = se.drop_duplicates(keep='last')
    df = se.to_frame('values')
    df['max2here'] = df['values'].expanding().max()
    df['dd2here'] = df['values'] / df['max2here']
    df['maxd2here'] = 1 - df['dd2here']
    
    return df#df['maxd2here'].max()

年化收益率

def get_annual_return(df):
    start = df.index[0]
    end = df.index[-1]
    start_date = datetime.strptime(start,'%Y-%m-%d')
    end_date = datetime.strptime(end,'%Y-%m-%d')
    days = (end_date - start_date) / timedelta(1)
    cumprod_value = df['cumprod_value'].iloc[-1] / df['cumprod_value'].iloc[0] 
    annual = cumprod_value ** (1/(days/365)) - 1
    return annual

索提诺比率

def get_sortino(df):
    se = df['cumprod_value']
    
    start = df.index[0]
    end = df.index[-1]
    start_date = datetime.strptime(start,'%Y-%m-%d')
    end_date = datetime.strptime(end,'%Y-%m-%d')
    
    # 年化收益
    day_list = se.index.tolist()
    days = (end_date - start_date).days
    
    ann_r = (se.iloc[-1]/se.iloc[0])**(365/days) -1
    
    pct_change = se.pct_change()
    pct_change = pct_change.dropna()
    
    # 策略波下行波动率
    num = len(pct_change)
    se = pct_change - pct_change.mean() 
    se = se[se<0]
    vol = np.sqrt(((se)**2).sum()*250/(num))
    
    # 索提诺比率
    Sortino = (ann_r - 0.04) / vol
    
    return (Sortino)

文章作者: 止一之路
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 止一之路 !
评论
  目录