MCPcopy Index your code
hub / github.com/kernc/backtesting.py / close

Method close

backtesting/backtesting.py:590–596  ·  view source on GitHub ↗

Place new `Order` to close `portion` of the trade at next market price.

(self, portion: float = 1.)

Source from the content-addressed store, hash-verified

588 return copy(self)._replace(**kwargs)
589
590 def close(self, portion: float = 1.):
591 """Place new `Order` to close `portion` of the trade at next market price."""
592 assert 0 < portion <= 1, "portion must be a fraction between 0 and 1"
593 # Ensure size is an int to avoid rounding errors on 32-bit OS
594 size = copysign(max(1, int(round(abs(self.__size) * portion))), -self.__size)
595 order = Order(self.__broker, size, parent_trade=self, tag=self.__tag)
596 self.__broker.orders.insert(0, order)
597
598 # Fields getters
599

Callers 15

nextMethod · 0.45
nextMethod · 0.45
nextMethod · 0.45
__exit__Method · 0.45
closeMethod · 0.45
new_orderMethod · 0.45
runMethod · 0.45
_mp_taskMethod · 0.45
nextMethod · 0.45
_mp_task_runMethod · 0.45
_tempfileFunction · 0.45
nextMethod · 0.45

Calls 1

OrderClass · 0.85

Tested by

no test coverage detected