Exemplo n.º 1
0
def main(ifcode, period_short, period_long):
    rs = []
    total = 0
    pos_num = 0
    nag_num = 0
    date_list = ifcode_day_map(ifcode)
    for day in date_list:
        df = get_data(ifcode, day)
        #df = point_prosess_v2(_df, 30)
        df['ema_short'] = Indicator.ewma_metric(period_short, df[['price']],
                                                'price')
        df['ema_long'] = Indicator.ewma_metric(period_long, df[['price']],
                                               'price')

        sig_infos = SellSignal.compare_ema(df, period_short, offset=5)
        profit_infos = SellSignal.profit_infos(sig_infos)
        profit_all = 0
        trans_num = (len(profit_infos) + 1) / 2
        for item in profit_infos:
            if item['gain'] != '-':
                profit_all += int(item['gain'])
        rs.append({day: profit_all, 'trans_num': trans_num})
        total += profit_all
        if profit_all >= 0:
            pos_num += 1
        elif profit_all < 0:
            nag_num += 1

    pprint(rs)
    print '%s total: %s' % (ifcode, total)
    print '%s profit rate: %.2f' % (ifcode, pos_num * 1.0 / nag_num)
Exemplo n.º 2
0
def get_all_trans(ifcode, period_short, period_long, ammout=1):
    rs = []
    total = 0
    pos_num = 0
    nag_num = 0
    trans_all = 0
    date_list = ifcode_day_map(ifcode)
    for day in date_list:
        _df = get_data(ifcode, day)
        df = macd_df(_df, period_short, period_long)
        sig_infos = SellSignal.compare_macd(df, 2, 25)
        profit_infos = SellSignal.profit_infos(sig_infos)
        profit_all = 0
        trans_num = (len(profit_infos) - 1) / 2
        trans_all += trans_num
        for item in profit_infos:
            if item['gain'] != '-':
                profit_all += int(item['gain']) * ammout
        rs.append({day: profit_all, 'trans_num': trans_num})
        total += profit_all
        if profit_all >= 0:
            pos_num += 1
        elif profit_all < 0:
            nag_num += 1

    pprint(rs)
    print '%s total: %s' % (ifcode, total)
    print '%s profit rate: %.2f' % (ifcode, pos_num * 1.0 / nag_num)
    print '%s trans all number: %s' % (ifcode, trans_all)
    print '%s fees : %s' % (ifcode, trans_all * 2300)
    print '%s real profit : %s' % (ifcode, total - trans_all * 2300)
Exemplo n.º 3
0
 def macd_analysis(cls, date, ifcode, period_short, period_long, \
                   period_dif, pre_point, pre_time, pre_offset):
     #date : 'yyyy-mm-dd'
     df = FittingDataCalculator.macd_df(date, ifcode, period_short, period_long, \
                                     period_dif, pre_point, pre_time)
     if df.empty:
         return []
     sig_infos = SellSignal.compare_macd(df, 3, pre_offset)
     profit_infos = SellSignal.profit_infos(sig_infos)
     return profit_infos
Exemplo n.º 4
0
 def macd(cls, date, ifcode, period_short=12, period_long=26, period_dif=9, \
          pre_point=init_point, pre_time=init_time, offset=init_offset):
     #date : 'yyyy-mm-dd'
     df = FittingDataCalculator.macd_df(date, ifcode, period_short, period_long, \
                                        period_dif, pre_point, pre_time)
     if df.empty:
         return []
     sig_infos = SellSignal.compare_macd(df, 3, offset)
     profit_infos = SellSignal.profit_infos(sig_infos)
     flags = SellSignal.out_flags(sig_infos)
     return profit_infos
Exemplo n.º 5
0
 def ema(cls, date, ifcode, period_short, period_long):
     _file = '%s/%s_%s_%s_%s' % (ema_file_dir, date, ifcode, period_short, period_long)
     if os.path.isfile(_file):
         df = read_df(_file)
     else:
         df = FittingDataCalculator.ema_df(date, ifcode, period_short, period_long)
         if df.empty:
             return []
     sig_infos = SellSignal.compare_ema(df, limit_period=60)
     profit_infos = SellSignal.profit_infos(sig_infos)
     return profit_infos
Exemplo n.º 6
0
    def macd_chart(cls, date, ifcode, period_short=12, period_long=26, period_dif=9, \
                   pre_point=init_point, pre_time=init_time, offset=init_offset):
        df = FittingDataCalculator.macd_df(date, ifcode, period_short, period_long, \
                                           period_dif, pre_point, pre_time)

        price = df[['time_index', 'price']].values.tolist()
        macd_dif = df[['time_index', 'macd_dif']].values.tolist()
        macd_dem = df[['time_index', 'macd_dem']].values.tolist()

        # flag
        sig_infos = SellSignal.compare_macd(df, 3, offset)
        flags = SellSignal.out_flags(sig_infos)
        return [price, macd_dif, macd_dem, flags]
Exemplo n.º 7
0
def get_first_trans(ifcode, period_short, period_long):
    rs = []
    total = 0
    pos_num = 0
    nag_num = 0
    date_list = ifcode_day_map(ifcode)
    for day in date_list:
        _df = get_data(ifcode, day)
        df = macd_df(_df, period_short, period_long)
        sig_infos = Signal.compare_macd(df, 2, 30)
        profit_infos = SellSignal.profit_infos(sig_infos)
        profit_first = 0
        for item in profit_infos:
            if item['gain'] != '-':
                profit_first = int(item['gain'])
                break
        rs.append({day: profit_first})
        if profit_first >= 0:
            pos_num += 1
        elif profit_first < 0:
            nag_num += 1

    print '每天第一笔交易'
    pprint(rs)
    print '%s profit rate: %.2f' % (ifcode, pos_num * 1.0 / nag_num)
Exemplo n.º 8
0
 def boll(cls, date, ifcode, period_short=50, period_long=80, pre_point=10):
     df = FittingDataCalculator.boll_df(date, ifcode, period_short, period_long, pre_point)
     sig_infos = SellSignal.compare_boll_b_percent(df)
     profit_infos = SellSignal.profit_infos(sig_infos)
     return profit_infos