Skip to content

Commit

Permalink
fixing time.clock for python>=3.8 (mementum#394)
Browse files Browse the repository at this point in the history
* fixing time.clock for python>=3.8

* switching order of  time_clock imports
  • Loading branch information
simongarisch authored May 28, 2020
1 parent 9154552 commit 3380801
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
9 changes: 7 additions & 2 deletions tests/test_analyzer-sqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
unicode_literals)

import time
try:
time_clock = time.process_time
except:
time_clock = time.clock


import testcommon

Expand Down Expand Up @@ -92,7 +97,7 @@ def start(self):
self.log('Starting portfolio value: %.2f' % self.broker.getvalue(),
nodate=True)

self.tstart = time.clock()
self.tstart = time_clock()

self.buycreate = list()
self.sellcreate = list()
Expand All @@ -101,7 +106,7 @@ def start(self):
self.tradecount = 0

def stop(self):
tused = time.clock() - self.tstart
tused = time_clock() - self.tstart
if self.p.printdata:
self.log('Time used: %s' % str(tused))
self.log('Final portfolio value: %.2f' % self.broker.getvalue())
Expand Down
8 changes: 6 additions & 2 deletions tests/test_analyzer-timereturn.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
unicode_literals)

import time
try:
time_clock = time.process_time
except:
time_clock = time.clock

import testcommon

Expand Down Expand Up @@ -88,15 +92,15 @@ def start(self):
self.log('Starting portfolio value: %.2f' % self.broker.getvalue(),
nodate=True)

self.tstart = time.clock()
self.tstart = time_clock()

self.buycreate = list()
self.sellcreate = list()
self.buyexec = list()
self.sellexec = list()

def stop(self):
tused = time.clock() - self.tstart
tused = time_clock() - self.tstart
if self.p.printdata:
self.log('Time used: %s' % str(tused))
self.log('Final portfolio value: %.2f' % self.broker.getvalue())
Expand Down
9 changes: 6 additions & 3 deletions tests/test_strategy_optimized.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

import itertools
import time

try:
time_clock = time.process_time
except:
time_clock = time.clock

import testcommon

Expand Down Expand Up @@ -78,14 +81,14 @@ def __init__(self):

def start(self):
self.broker.setcommission(commission=2.0, mult=10.0, margin=1000.0)
self.tstart = time.clock()
self.tstart = time_clock()
self.buy_create_idx = itertools.count()

def stop(self):
global _chkvalues
global _chkcash

tused = time.clock() - self.tstart
tused = time_clock() - self.tstart
if self.p.printdata:
self.log(('Time used: %s - Period % d - '
'Start value: %.2f - End value: %.2f') %
Expand Down
8 changes: 6 additions & 2 deletions tests/test_strategy_unoptimized.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
unicode_literals)

import time
try:
time_clock = time.process_time
except:
time_clock = time.clock

import testcommon

Expand Down Expand Up @@ -107,15 +111,15 @@ def start(self):
self.log('Starting portfolio value: %.2f' % self.broker.getvalue(),
nodate=True)

self.tstart = time.clock()
self.tstart = time_clock()

self.buycreate = list()
self.sellcreate = list()
self.buyexec = list()
self.sellexec = list()

def stop(self):
tused = time.clock() - self.tstart
tused = time_clock() - self.tstart
if self.p.printdata:
self.log('Time used: %s' % str(tused))
self.log('Final portfolio value: %.2f' % self.broker.getvalue())
Expand Down

0 comments on commit 3380801

Please sign in to comment.