MAINT: Separate volume and direction while calculating volume share.

In the volume share slippgae, the current amount had the direction,
i.e. buy/sell was baked into the value of `cur_amount` which then
needed to have the direction multiplied out when parts of the slippage
model needed to take in just the magnitude/amount into account.

So calculate the current volume, use that in calculations and then
apply at the order direction at order time.

Also, when applying the direction to the magnitude of the sell,
use copysign to make the code more explicit about taking the direction
of the order, instead of it possibly having some scalar impact.

As well as remove direction from volume_share calculation since that
calculation and subsequent calculations only care about the magnitude,
so make the disregard for direction more explicit by removing it.
This commit is contained in:
Eddie Hebert
2013-06-13 15:20:30 -04:00
parent 0ae41f4d01
commit 7f669c4391
+8 -6
View File
@@ -12,6 +12,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import division
import abc
import math
@@ -174,17 +176,17 @@ class VolumeShareSlippage(SlippageModel):
# the current order amount will be the min of the
# volume available in the bar or the open amount.
cur_amount = min(remaining_volume, abs(open_amount))
cur_amount = cur_amount * order.direction
cur_volume = min(remaining_volume, abs(open_amount))
# tally the current amount into our total amount ordered.
# total amount will be used to calculate price impact
total_volume = total_volume + order.direction * cur_amount
total_volume = total_volume + cur_volume
volume_share = min(order.direction * (total_volume) / event.volume,
volume_share = min(total_volume / event.volume,
self.volume_limit)
simulated_impact = (volume_share) ** 2 \
* self.price_impact * order.direction * event.price
* math.copysign(self.price_impact, order.direction) \
* event.price
txn = create_transaction(
event,
@@ -192,7 +194,7 @@ class VolumeShareSlippage(SlippageModel):
# In the future, we may want to change the next line
# for limit pricing
event.price + simulated_impact,
cur_amount
math.copysign(cur_volume, order.direction)
)
txns.append(txn)