예제 #1
0
def get_sharp_ratio_for_each_year(net_value_list):
    sharpRatioList = []
    startYear = DateUtil.datetime2_year_str(net_value_list.index[0])
    endYear = DateUtil.datetime2_year_str(net_value_list.index[-1])

    for year in range(int(startYear), int(endYear) + 1, 1):
        yearStr = str(year)
        # print("yearStr:" + str(yearStr))
        # 把总列表按年切分成子列表
        subNetValueList = net_value_list.ix[yearStr]
        ss = subNetValueList['changePCT']
        sharpRatio = get_sharp_ratio_common_day(ss)
        sharpRatioDict = {'year': yearStr, 'sharpRatio': sharpRatio}
        sharpRatioList.append(sharpRatioDict)

    # 非时间序列DF
    df = pd.DataFrame(sharpRatioList)
    return df
예제 #2
0
def main(net_value_list):
    #startYear = DateUtil.datetime2YearStr(netValueList.index[0])
    #endYear = DateUtil.datetime2YearStr(netValueList.index[-1]) #len(netValueList) - 1
    net_value_list['year'] = DateUtil.datetime2_year_str(net_value_list.index)
    #print(netValueList)
    #['netValue']
    stockYearList = net_value_list.groupby(net_value_list['year']).apply(
        get_year_profit, 'netValue')
    # 非时间序列DF
    df = pd.DataFrame(stockYearList, columns=['profit'])
    return df
예제 #3
0
def get_max_drop_for_each_year(net_value_list):
    #netValueList2 = pd.DataFrame(data=netValueList,columns=['netValue','hightestNetValue'])
    #netValueList2['hightestNetValue'] = 0;

    stock_trade_result_max_drop_list = []
    start_year = DateUtil.datetime2_year_str(net_value_list.index[0])
    end_year = DateUtil.datetime2_year_str(net_value_list.index[-1])

    for year in range(int(start_year), int(end_year) + 1, 1):
        year_str = str(year)
        #print("yearStr:" + str(yearStr))
        #把总列表按年切分成子列表
        sub_net_value_list = net_value_list.ix[year_str]
        max_drop_dict = get_max_drop(sub_net_value_list)
        max_drop_dict.setdefault("year", year_str)
        #print(maxDropDict)
        stock_trade_result_max_drop_list.append(max_drop_dict)

    #非时间序列DF
    df = pd.DataFrame(stock_trade_result_max_drop_list)
    return df