Skip to content

Commit

Permalink
peer review
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisSzeto committed Dec 6, 2024
1 parent 00de10f commit b28c98b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
1 change: 0 additions & 1 deletion Algorithm.CSharp/VolumeShareSlippageModelAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
Expand Down
3 changes: 2 additions & 1 deletion Algorithm.Python/VolumeShareSlippageModelAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# limitations under the License.

from AlgorithmImports import *
from Orders.Slippage.VolumeShareSlippageModel import VolumeShareSlippageModel

### <summary>
### Example algorithm implementing VolumeShareSlippageModel.
Expand All @@ -33,7 +34,7 @@ def initialize(self) -> None:
self.universe_settings.schedule.on(self.date_rules.week_start())
# Add universe to trade on the most and least liquid stocks among QQQ constituents.
self.add_universe(
self.universe.etf(qqq.value, Market.USA, self.universe_settings, lambda constituents: [c.symbol for c in constituents]),
self.universe.etf(qqq, Market.USA, self.universe_settings, lambda constituents: [c.symbol for c in constituents]),
self.fundamental_selection
)

Expand Down
6 changes: 3 additions & 3 deletions Common/Orders/Slippage/VolumeShareSlippageModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ def get_slippage_approximation(self, asset: Security, order: Order) -> float:
elif last_data.data_type == MarketDataType.QUOTE_BAR:
bar_volume = last_data.last_bid_size if order.direction == OrderDirection.BUY else last_data.last_ask_size
else:
raise InvalidOperationException(Messages.VolumeShareSlippageModel.InvalidMarketDataType(last_data))
raise InvalidOperationException(Messages.VolumeShareSlippageModel.invalid_market_data_type(last_data))

# If volume is zero or negative, we use the maximum slippage percentage since the impact of any quantity is infinite
# In FX/CFD case, we issue a warning and return zero slippage
if bar_volume <= 0:
security_type = asset.symbol.id.security_type
if security_type == SecurityType.CFD or security_type == SecurityType.FOREX or security_type == SecurityType.CRYPTO:
Log.error(Messages.VolumeShareSlippageModel.VolumeNotReportedForMarketDataType(security_type))
Log.error(Messages.VolumeShareSlippageModel.volume_not_reported_for_market_data_type(security_type))
return 0

Log.error(Messages.VolumeShareSlippageModel.NegativeOrZeroBarVolume(bar_volume, slippage_percent))
Log.error(Messages.VolumeShareSlippageModel.negative_or_zero_bar_volume(bar_volume, slippage_percent))
else:
# Ratio of the order to the total volume
volume_share = min(order.absolute_quantity / bar_volume, self.volume_limit)
Expand Down

0 comments on commit b28c98b

Please sign in to comment.