Exemplo n.º 1
0
    def run_hedgeit(self):
        manifest = 'data/future.csv'
        sectormap = json.load(open('examples/clenow-best40.json'))
    
        feedStart = datetime.datetime(1999,1,1)
        tradeStart = datetime.datetime(2000,1,1)
        tradeEnd = datetime.datetime(2013,12,31)
    
        InstrumentDb.Instance().load(manifest)
            
        plog = 'positions.csv'
        elog = 'equity.csv'
        rlog = 'returns.csv'
        slog = 'summary.csv'

        parms = { 'riskFactor' : 0.004 }
        
        ctrl = Controller(sectormap, 
                          modelType = 'breakout',
                          cash = 250000,
                          tradeStart = tradeStart,
                          compounding = False,
                          positionsFile = plog, 
                          equityFile = elog, 
                          returnsFile = rlog,
                          summaryFile = slog,
                          parms = parms
                          )
        
        ctrl.run(feedStart, tradeStart, tradeEnd)
    
        ctrl.writeAllTrades('trades.csv')        
        ctrl.writeTSSBTrades('tssb')
        ctrl.writePositionAlerts('alerts.csv')
        
        self._alerts = sorted(ctrl.get_position_alerts(), key=lambda x: x.datetime, reverse=True)

        Log.info('There are %d position updates' % (len(self._alerts)))                
Exemplo n.º 2
0
def main(argv=None):
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hc:p:t:g", ["tssb=","dump="])
    except getopt.GetoptError as err:
        # print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage()
        sys.exit(2)

    cash = 1000000
    type_ = 'breakout'
    compounding = True
    tssb = None
    parms = None
    dump = None
    for o, a in opts:
        if o == "-c":
            cash = float(a)
            Log.info('Setting initial cash position to: %0.2f' % cash)
        elif o == "-p":
            parms = parseParmString(a)
            Log.info('Using model parms: %s' % parms)
        elif o == "-t":
            type_ = a
            Log.info('Using model %s' % type_)
        elif o == "-g":
            compounding = False
            Log.info('Compounding disabled')
        elif o == "--tssb":
            tssb = a
            Log.info('Writing tssb files with base %s' % tssb)
        elif o == "--dump":
            dump = a
            Log.info('Will output data feed to %s.csv' % dump)
        else:
            usage()
            return
                         
    if len(args) != 5:
        Log.error('Not enough arguments to backtest!')
        usage()
        sys.exit(1)
        
    manifest = args[0]
    sectormap = json.load(open(args[1]))

    feedStart = datetime.strptime(args[2], '%Y-%m-%d')
    tradeStart = datetime.strptime(args[3], '%Y-%m-%d')
    tradeEnd = datetime.strptime(args[4], '%Y-%m-%d')

    InstrumentDb.Instance().load(manifest)
        
    plog = 'positions.csv'
    elog = 'equity.csv'
    rlog = 'returns.csv'
    slog = 'summary.csv'
    
    ctrl = Controller(sectormap, 
                      modelType = type_,
                      cash = cash,
                      tradeStart = tradeStart,
                      compounding = compounding,
                      positionsFile = plog, 
                      equityFile = elog, 
                      returnsFile = rlog,
                      summaryFile = slog,
                      parms = parms
                      )
    ctrl.run(feedStart, tradeStart, tradeEnd)
    if dump:
        ctrl.dumpFeed(dump)
        
    tlog = 'trades.csv'
    ctrl.writeAllTrades(tlog)
    if tssb:
        ctrl.writeTSSBTrades(tssb)
    
    alog = 'alerts.csv'
    ctrl.writePositionAlerts(alog)
    
    Log.info('Net return     :  %0.1f%%' % (ctrl.net_return() * 100.0))
    Log.info('Max drawdown   : -%0.1f%%' % (ctrl.drawdown().getMaxDrawDown() * 100.0))
Exemplo n.º 3
0
def main(argv=None):
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hc:p:t:g",
                                   ["tssb=", "dump="])
    except getopt.GetoptError as err:
        # print help information and exit:
        print str(err)  # will print something like "option -a not recognized"
        usage()
        sys.exit(2)

    cash = 1000000
    type_ = 'breakout'
    compounding = True
    tssb = None
    parms = None
    dump = None
    for o, a in opts:
        if o == "-c":
            cash = float(a)
            Log.info('Setting initial cash position to: %0.2f' % cash)
        elif o == "-p":
            parms = parseParmString(a)
            Log.info('Using model parms: %s' % parms)
        elif o == "-t":
            type_ = a
            Log.info('Using model %s' % type_)
        elif o == "-g":
            compounding = False
            Log.info('Compounding disabled')
        elif o == "--tssb":
            tssb = a
            Log.info('Writing tssb files with base %s' % tssb)
        elif o == "--dump":
            dump = a
            Log.info('Will output data feed to %s.csv' % dump)
        else:
            usage()
            return

    if len(args) != 5:
        Log.error('Not enough arguments to backtest!')
        usage()
        sys.exit(1)

    manifest = args[0]
    sectormap = json.load(open(args[1]))

    feedStart = datetime.strptime(args[2], '%Y-%m-%d')
    tradeStart = datetime.strptime(args[3], '%Y-%m-%d')
    tradeEnd = datetime.strptime(args[4], '%Y-%m-%d')

    InstrumentDb.Instance().load(manifest)

    plog = 'positions.csv'
    elog = 'equity.csv'
    rlog = 'returns.csv'
    slog = 'summary.csv'

    ctrl = Controller(sectormap,
                      modelType=type_,
                      cash=cash,
                      tradeStart=tradeStart,
                      compounding=compounding,
                      positionsFile=plog,
                      equityFile=elog,
                      returnsFile=rlog,
                      summaryFile=slog,
                      parms=parms)
    ctrl.run(feedStart, tradeStart, tradeEnd)
    if dump:
        ctrl.dumpFeed(dump)

    tlog = 'trades.csv'
    ctrl.writeAllTrades(tlog)
    if tssb:
        ctrl.writeTSSBTrades(tssb)

    alog = 'alerts.csv'
    ctrl.writePositionAlerts(alog)

    Log.info('Net return     :  %0.1f%%' % (ctrl.net_return() * 100.0))
    Log.info('Max drawdown   : -%0.1f%%' %
             (ctrl.drawdown().getMaxDrawDown() * 100.0))