Exemple #1
0
 def do_backtest(self, arg):
     paramFlag = input('Use current parameters? ([y]/n): ')
     if paramFlag is 'n':
     #   Change parameters here
         bbFunctions.choose_parameters()
     numLinesLog = bbFunctions.file_len(bbCfg.logFileName) 
     bbCfg.logFileNameBT = bbFunctions.getLogFileNameBT()
     try:
         numLinesLogBT = bbFunctions.file_len(bbCfg.logFileNameBT)
     except:
         numLinesLogBT = 0
     if numLinesLogBT != numLinesLog:
         bitbot.main('-b')
     d,r=bbPerformance.getReturns(bbCfg.logFileNameBT, None, '2014-01-08', None)
     bbPerformance.printSummary(r)
Exemple #2
0
 def do_calibrate(self, arg):
     reload(bbCfg)
     old_walkUp = bbCfg.walkUp
     old_tradeFactor = bbCfg.tradeFactor
     old_allinLimit = bbCfg.allinLimit
     old_backupFund = bbCfg.backupFund
     m = [0.9, 1.1]
     result = []
     numLinesLog = bbFunctions.file_len(bbCfg.logFileName)
     for i in range(len(m)**4):
         sys.stdout.write('|')
     sys.stdout.write('\n')
     for bbCfg.walkUp in [x * old_walkUp for x in m]:
         for bbCfg.tradeFactor in [x * old_tradeFactor for x in m]:
             for bbCfg.allinLimit in [x * old_allinLimit for x in m]:
                 for bbCfg.backupFund in [x * old_backupFund for x in m]:
                     bbCfg.logFileNameBT = bbFunctions.getLogFileNameBT()
                     try:
                         n = bbFunctions.file_len(bbCfg.logFileNameBT)
                     except:
                         n = 0
                     #bbFunctions.display_config()
                     sys.stdout.write('|')
                     sys.stdout.flush()
                     if n != numLinesLog:
                         bitbot.main('-b -q')
                     d,r=bbPerformance.getReturns(bbCfg.logFileNameBT, 
                                                  None, '2014-01-08', None)
                     result.append([
                             bbCfg.walkUp,
                             bbCfg.tradeFactor,
                             bbCfg.allinLimit,
                             bbCfg.backupFund,
                             100*bbPerformance.totalReturn(r[:,3])])
     print('')
     result = np.array(result)
     result = result[np.argsort(result[:, len(result[0])-1])]
     print(' '.join('{0:>10}'.format(x) for x in ['walkUp', 'tradeFactor', 'allinLimit', 'backupFund', 'Return']))
     for row in result[-10:]:
         print(' '.join('{0:10.4}'.format(x) for x in row))
Exemple #3
0
from bbKeys import *

t = bbClasses.trader(bbCfg.logFileName)
p = bbClasses.portfolio(100,0)
m = bbClasses.marketData('Null', 500, 500)
apiK = apiKraken.API(keyKraken, secKraken)
apiB = apiBacktest.API()

print('\nTesting normal trading')
bitbot.mainLoop(m, p, t, apiK, 0, 0)

print('\nTesting test mode')
bitbot.mainLoop(m, p, t, apiK, 1, 0)

print('\nTesting backtesting')
bitbot.main('-b')

print('\nTesting backtest + test mode')
bitbot.mainLoop(m, p, t, apiB, 1, 1)

print('\nTesting trader error')
t.error='Test error'
bitbot.mainLoop(m, p, t, apiK, 0, 0)

print('\nTesting stop loss')
m.high = 99999
t.stopLoss(m,p)
with open(bbCfg.overrideFileName, 'wt') as of:
    of.write('override = ' + str(0) + '\n')
    of.write('target   = ' + str(0) + '\n')
    of.write('suspend  = ' + str(0) + '\n')