Exemple #1
0
def ema_save2db(date, ifcode, period_short, period_long):
    if not date or not ifcode or not period_short or not period_long:
        return {'error': u'params is fault'}
    period_short = int(period_short)
    period_long = int(period_long)
    return FittingDataCalculator.ema_df(date, ifcode, period_short,
                                        period_long)
Exemple #2
0
def main(ifcode, period_short, period_long):
    date_list = ifcode_day_map(ifcode)
    for day in date_list:
        print '*' * 20
        print day
        df = FittingDataCalculator.ema_df(day, ifcode, period_short,
                                          period_long)
        save_data(df.values.tolist(), day, ifcode, period_short, period_long)
Exemple #3
0
    def boll_chart(cls, date, ifcode, period_short=50, period_long=80, pre_point=10):
        df = FittingDataCalculator.boll_df(date, ifcode, period_short, period_long, pre_point)

        price = df[['time_index', 'price']].values.tolist()
        boll_up = df[['time_index', 'boll_up']].values.tolist()
        boll_dn = df[['time_index', 'boll_dn']].values.tolist()
        boll_mb = df[['time_index', 'boll_mb']].values.tolist()
        return price, boll_up, boll_dn, boll_mb
Exemple #4
0
def ema(date, ifcode, period_short, period_long):
    if not date or not ifcode or not period_short or not period_long:
        return {'error': u'params is fault'}
    date = str2day(date, DATE_DISPLAY_FORMAT).strftime(DATE_DISPLAY_FORMAT)
    period_short = int(period_short)
    period_long = int(period_long)
    return FittingDataCalculator.ema_chart(date, ifcode, period_short,
                                           period_long)
Exemple #5
0
def fitting_data():
    if not req.args.get('date') or not req.args.get(
            'ifcode') or not req.args.get('period'):
        return {'error': u'params is fault'}
    date = str2day(req.args.get('date')).strftime(DATE_DISPLAY_FORMAT)
    ifcode = req.args.get('ifcode')
    period = int(req.args.get('period'))
    return FittingDataCalculator.fitting_series(period, date, ifcode)
Exemple #6
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
Exemple #7
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
Exemple #8
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
Exemple #9
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]
Exemple #10
0
from simplejson import dumps
from datetime import date

from models.api.backtest.calculator import FittingDataCalculator

save_dir = '/root/ema_backtest_data'

def save_data(df, date, ifcode, period_short, period_long):
    f = open('%s/%s_%s_%s_%s' % (save_dir, date, ifcode, period_short, period_long), 'w')
    try:
        f.write(dumps(df))
        f.close()
    except BaseException, e:
        print e
        f.close()


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="save ema dataframe to files")
    parser.add_argument("ifcode", type=str, help="ifcode")
    parser.add_argument("period_short", type=int, help="short period")
    parser.add_argument("period_long", type=int, help="long period")
    args = parser.parse_args()
    ifcode = args.ifcode
    period_short = args.period_short
    period_long = args.period_long
    thedate = date.today().strftime('%Y-%m-%d')

    df = FittingDataCalculator.ema_df(thedate, ifcode, period_short, period_long)
    save_data(df.values.tolist(), thedate, ifcode, period_short, period_long)
Exemple #11
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
Exemple #12
0
def raw_data(date, ifcode):
    if not date or not ifcode:
        return {'error': u'params is fault'}
    date = str2day(date, DATE_DISPLAY_FORMAT).strftime(DATE_DISPLAY_FORMAT)
    return FittingDataCalculator.raw_series(date, ifcode)