Exemplo n.º 1
0
def str_perc_avg(data):
    # Average of success buy prices
    d = get_perc_from_history(data, 4)
    if len(d) > 0:
        return mean([l['y0'] for l in d])
    else:
        return None
Exemplo n.º 2
0
def str_perc_low(data):
    # Low of success buy prices
    d = get_perc_from_history(data, 4)
    if len(d) > 0:
        return min([l['y0'] for l in d])
    else:
        return None
Exemplo n.º 3
0
def str_perc_first(data):
    # Sort by timestamp
    # Low of success buy prices
    data = get_perc_from_history(data, 4)
    if len(data) > 0:
        return sorted(data, key=lambda k: k['t0'])[0]['y0']
    else:
        return None
Exemplo n.º 4
0
 def run(self, perc):
     # Get day cheap symbols
     i = 0
     ret = {}
     for f in glob.glob(dir_day + '/*.json'):
         if debug is True and i == 2:
             continue
         symbol = os.path.splitext(os.path.basename(f))[0]
         with open(f) as f:
             # [ { o, c, h, l, v, t }, { o, c, h, l, v, t } ]
             # Get perc
             data = json.load(f)
             if len(data) == 0:
                 continue
             ret[symbol] = get_perc_from_history(data, perc)
         i += 1
     # Print
     print('Found %i symbols' % len(ret))
     # Format as JSON
     out = {}
     for symbol in ret:
         out[symbol] = {}
         out[symbol].update({
             'len': len(ret[symbol]),
             'data': [],
         })
         print('%s: %i' % (symbol, len(ret[symbol])))
         for p in ret[symbol]:
             out[symbol]['data'].append({
                 'time': {
                     't0': to_hour(p['t0']),
                     't1': to_hour(p['t1']),
                 },
                 'price': {
                     'y0': p['y0'],
                     'y1': p['y1'],
                 },
                 'perc': round(p['perc'], 2),
                 'volume': {
                     'v0': p['v0'],
                     'v1': p['v1'],
                 },
             })
     print(json.dumps(out, indent=2))
Exemplo n.º 5
0
    'low',
    'perc_avg',
    'perc_first',
    'perc_low',
]
ret = {
    'summary': {
        'success_days': 0,
        'success_total': 0,
        'strategies': {},
    }
}

# Get count of successful buy/sell pairs (benchmark)
for date, points in sorted(data_by_date.items()):
    success_count = len(get_perc_from_history(points, 4))
    if success_count > 0:
        ret['summary']['success_days'] += 1
    ret['summary']['success_total'] += success_count

for strategy in strategies:
    strategy_info = {
        'success_total': 0,
        'success_days': 0,
        'success_dates': [],
        'success_days_perc': 0,
    }
    print('====', strategy)
    prev = None
    for date, points in sorted(data_by_date.items()):
        if prev is not None: