本文整理汇总了Python中position.Position类的典型用法代码示例。如果您正苦于以下问题:Python Position类的具体用法?Python Position怎么用?Python Position使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Position类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: expand_frontier
def expand_frontier(self, state):
for row in (-1, 0, 1):
for col in (-1, 0, 1):
# Only allow adjacent non-diagonal moves
#if row != 0 and col != 0:
# continue
# Get the new position
position = Position(state.row() + row, state.column() + col)
# Rule out invalid positions
if position.row() < 0 or position.column() < 0 or \
position.row() >= self.environment.height or position.column() >= self.environment.width:
return
p = position.as_tuple()
# If not an obstacle and not explored, then add to frontier
if p not in self.environment.obstacles and p not in self.explored:
self.f += 1
# Create the new state
new_state = State(position, state.target, state.cost + 1, state)
# Update state path cost
new_state.path_cost = new_state.cost + self.heuristic(new_state)
# Add to frontier
self.frontier.add(new_state)
示例2: __init__
def __init__(self):
Position.__init__(self)
self.rect = None
self.image = None
self.name = None
self.type = None
self.has_dialog = False
示例3: openPosition
def openPosition(self, order, bar, market = False):
position = 0
if order.instrument != "" and order.instrument != bar[11]:
print "bar of other instrument!" #exception here
raise NotImplementedError
if market:
if order.orderType == -1:
order.price = bar[4]
else:
order.price = bar[9]
position = Position(order, bar[0], self.slippage, self.randomizeSlippage, self.point, stat = [])
if self.getStat:
position.stat = []
position.stat.append(self.strategy.onGetStatOnPositionOpen(position, bar))
else:
position = Position(order, bar[0], stat = [])
if self.getStat:
position.stat = []
position.stat.append(self.strategy.onGetStatOnPositionOpen(position, bar))
self.positions.append(position)
self.orders.remove(position.order)
self.strategy.onOrderExecution(position.order)
示例4: TestLongGBPUSDPosition
class TestLongGBPUSDPosition(unittest.TestCase):
def setUp(self):
getcontext.prec = 2
side = "LONG"
market = "GBP/USD"
units = Decimal(str(2000))
exposure = Decimal("2000.00")
avg_price = Decimal("1.51819")
cur_price = Decimal("1.51770")
self.position = Position(
side, market, units, exposure,
avg_price, cur_price
)
def test_calculate_pips(self):
pos_pips = self.position.calculate_pips()
self.assertEqual(pos_pips, Decimal("-0.00049"))
def test_calculate_profit_base(self):
profit_base = self.position.calculate_profit_base(self.position.exposure)
self.assertEqual(profit_base, Decimal("-0.64571"))
def test_calculate_profit_perc(self):
profit_perc = self.position.calculate_profit_perc(self.position.exposure)
self.assertEqual(profit_perc, Decimal("-0.03229"))
示例5: funcVisit
def funcVisit(self, x, y):
pos = Position(x, y)
if pos.x < 0:
pos.x = 0
if pos.y < 0:
pos.y = 0
self.map[pos.x][pos.y].visible = True
self.map[pos.x][pos.y].discovered = True
示例6: test_move_info
def test_move_info(self):
"""Tests move info generation."""
pos = Position()
e4 = pos.get_move_info(Move.from_uci('e2e4'))
self.assertEqual(e4.san, 'e4')
self.assertFalse(e4.is_check)
self.assertFalse(e4.is_checkmate)
self.assertFalse(e4.is_castle)
示例7: generate_long_algebraic_moves
def generate_long_algebraic_moves(self):
position = Position()
for move in self.moves:
try:
long_move = "%s%s%s" % position.move(move)
if len(long_move) > 0:
yield long_move
except Exception, err:
raise BaseException("Could not process move %s (%s)" % (move, err))
示例8: TestRoundTripXOPosition
class TestRoundTripXOPosition(unittest.TestCase):
"""
Trade a round-trip trade in Exxon-MObil where the initial
trade is a buy/long of 100 shares of XOM, at a price of
$74.78, with $1.00 commission.
"""
def setUp(self):
"""
Set up the Position object that wil store the PnL.
"""
self.position = Position('BOT', 'XOM', Decimal('100'),
Decimal('74.78'), Decimal('1.00'),
Decimal('74.78'), Decimal('74.78'))
def test_calculate_round_trip(self):
"""
After the subsequent purchase, carry outtwo more buys/longs
and then close the position out with two additional sells/shorts.
The following prices have been tested against those calculated
via Interactive Brokers' Trader Workstation (TWS).
"""
# set the data in the object
self.position.transact_shares('BOT', Decimal('100'), Decimal('74.63'), Decimal('1.00'))
self.position.transact_shares('BOT', Decimal('250'), Decimal('74.620'), Decimal('1.25'))
self.position.transact_shares('SLD', Decimal('200'), Decimal('74.58'), Decimal('1.00'))
self.position.transact_shares('SLD', Decimal('250'), Decimal('75.26'), Decimal('1.25'))
self.position.update_market_value(Decimal('77.75'), Decimal('77.77'))
# start testing the values inside the object
# the assertEqual method is derived by the unittest.TestCase from which the class derive from
self.assertEqual(self.position.action, 'BOT')
self.assertEqual(self.position.ticker, 'XOM')
self.assertEqual(self.position.quantity, Decimal('0'))
self.assertEqual(self.position.buys, Decimal('450'))
self.assertEqual(self.position.sells, Decimal('450'))
self.assertEqual(self.position.net, Decimal('0'))
self.assertEqual(self.position.avg_bot, Decimal('74.65778'))
self.assertEqual(self.position.avg_sld, Decimal('74.95778'))
self.assertEqual(self.position.total_bot, Decimal('33596.00'))
self.assertEqual(self.position.total_sld, Decimal('33731.00'))
self.assertEqual(self.position.net_total, Decimal('135.00'))
self.assertEqual(self.position.total_commission, Decimal('5.50'))
self.assertEqual(self.position.net_incl_comm, Decimal('129.50'))
self.assertEqual(self.position.avg_price, Decimal('74.665'))
self.assertEqual(self.position.cost_basis, Decimal('0.00'))
self.assertEqual(self.position.market_value, Decimal('0.00'))
self.assertEqual(self.position.unrealised_pnl, Decimal('0.00'))
self.assertEqual(self.position.realised_pnl, Decimal('129.50'))
示例9: move
def move(self, steps: int) -> 'MegaCar':
"""
Move car "step" amount of places.
"""
if self.horizontal:
return Car.new(self.start + Position.new(steps, 0), self.horizontal,
self.length)
else:
return Car.new(self.start + Position.new(0, steps), self.horizontal,
self.length)
示例10: __repr__
def __repr__(self):
result = "Account %s\n" % (self.name)
result += " %s\n" % (Position.format(Account.CASH, None, None, self.cash),)
for position in self.positions.values():
result += " %s\n" % position
result += "================"
result += " %s\n" % (Position.format(None, None, None, account.get_value()),)
return result
示例11: setUp
def setUp(self):
p = Position()
self.moves = p.get_legal_moves()
m1 = Move.from_uci('e2e4')
m2 = Move.from_uci('b1c3')
self.san = SanNotation(p, m1)
self.san_dup = SanNotation(p, m1)
self.san_other = SanNotation(p, m2)
self.position = p
self.m1 = m1
self.m2 = m2
示例12: TestPosition
class TestPosition(unittest.TestCase):
def setUp(self):
self.pos = Position()
self.pos_dup = Position()
self.pos_other = Position()
self.pos_other.make_move(Move.from_uci('e2e4'))
def test___delitem__(self):
del self.pos['a1']
self.assertIs(None, self.pos['a1'])
def test___eq__(self):
self.assertEqual(True, self.pos == self.pos_dup)
self.assertEqual(False, self.pos == self.pos_other)
def test___getitem__(self):
self.assertEqual(True, self.pos['e1'] == 'K')
def test___hash__(self):
self.assertEqual(True, hash(self.pos) == hash(self.pos_dup))
self.assertEqual(False, hash(self.pos) != hash(self.pos_other))
def test___ne__(self):
self.assertEqual(False, self.pos != self.pos_dup)
self.assertEqual(True, self.pos != self.pos_other)
def test___repr__(self):
self.assertEqual("Position('%s')" % Fen(), repr(self.pos))
def test___setitem__(self):
self.pos['a1'] = 'K'
self.assertEqual('K', self.pos['a1'])
def test___str__(self):
self.assertEqual(str(Fen()), str(self.pos))
self.assertEqual(False, str(self.pos) == str(self.pos_other))
def test_copy(self):
copy = self.pos.copy()
self.assertEqual(copy, self.pos)
def test_is_check(self):
self.assertEqual(False, self.pos.is_check())
def test_is_checkmate(self):
self.assertEqual(False, self.pos.is_checkmate())
def test_is_game_over(self):
self.assertEqual(False, self.pos.is_game_over())
def test_is_insufficient_material(self):
self.assertEqual(False, self.pos.is_insufficient_material())
def test_is_king_attacked(self):
self.assertEqual(False, self.pos.is_king_attacked(WHITE))
def test_is_stalemate(self):
self.assertEqual(False, self.pos.is_stalemate())
示例13: cmdBreak
def cmdBreak(invoker):
preprocess = not invoker.hasOption("*")
invoker.checkUnsupportedOptions()
arguments = invoker.getArguments().strip()
runtime = invoker.getRuntime()
position = runtime.getPosition(runtime.getCurrentFrame())
if not arguments:
if not position:
raise CommandError, "%s: no current position" % invoker.getName()
id = invoker.getSession().addBreakpointAtPosition(position)
at = position.getShortDescription()
else:
words = arguments.split()
linenr_required = False
if words[0][0] == '#':
linenr_required = True
linenr_string = words[1]
try:
scriptindex = int(words[0][1:])
script = invoker.getSession().getScriptByIndex(scriptindex)
if not script:
raise ValueError
except ValueError:
raise CommandError, "%s: invalid script index: %s" % (invoker.getName(), words[0][1:])
else:
linenr_string = words[0]
script = False
try:
linenr = int(linenr_string)
if not script:
if not position:
raise CommandError, "%s: no current script" % invoker.getName()
script = position.getScript()
position = Position(script, linenr)
id = invoker.getSession().addBreakpointAtPosition(position)
at = position.getShortDescription()
except ValueError:
if linenr_required:
raise CommandError, "%s: line number required" % invoker.getName()
try:
result = runtime.eval(words[0], True, preprocess)
except KeyboardInterrupt:
return []
if not result.isObject() or not result.getValue().isFunction():
raise CommandError, "%s: not a function: %s" % (invoker.getName(), result)
id = invoker.getSession().addBreakpointAtFunction(result.getValue())
at = str(result)
return ["Breakpoint %d at %s." % (id, at)]
示例14: simulation
def simulation(self):
"""This function will perform the simulation process with several trials."""
for pos in self.positions:
p = Position(pos)
cumu_ret = np.zeros(self.num_trials)
daily_ret = np.zeros(self.num_trials)
for trial in range(self.num_trials):
#Get a daily return value
cumu_ret[trial] = p.invest()
#convert return value to return ratio
daily_ret[trial] = (cumu_ret[trial] / 1000.0) - 1
self.trials.append(daily_ret)
示例15: __init__
def __init__(self, name):
Position.__init__(self)
self.name = name
load_creature(self.name)
self.hp = CREATURES_LOADED[self.name]['hp']
self.mp = CREATURES_LOADED[self.name]['mp']
self.level = CREATURES_LOADED[self.name]['level']
self.attack = CREATURES_LOADED[self.name]['attack']
self.attack_m = CREATURES_LOADED[self.name]['attack_m']
self._class = CREATURES_LOADED[self.name]['_class']
self._def = CREATURES_LOADED[self.name]['_def']
self.def_m = CREATURES_LOADED[self.name]['def_m']
self.selfie = None