Skip to content

Commit

Permalink
Added suggested_quantity keyword argument to SignalEvent in order to …
Browse files Browse the repository at this point in the history
…transmit quantity information to PositionSizer. Added NaivePositionSizer to 'blindly' accept suggested quantities from SignalEvents.
  • Loading branch information
mhallsmoore committed Sep 14, 2016
1 parent eba6789 commit 9834aae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
7 changes: 6 additions & 1 deletion qstrader/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,22 @@ class SignalEvent(Event):
Handles the event of sending a Signal from a Strategy object.
This is received by a Portfolio object and acted upon.
"""
def __init__(self, ticker, action):
def __init__(self, ticker, action, suggested_quantity=None):
"""
Initialises the SignalEvent.
Parameters:
ticker - The ticker symbol, e.g. 'GOOG'.
action - 'BOT' (for long) or 'SLD' (for short).
suggested_quantity - Optional positively valued integer
representing a suggested absolute quantity of units
of an asset to transact in, which is used by the
PositionSizer and RiskManager.
"""
self.type = EventType.SIGNAL
self.ticker = ticker
self.action = action
self.suggested_quantity = suggested_quantity


class OrderEvent(Event):
Expand Down
4 changes: 3 additions & 1 deletion qstrader/portfolio_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def _create_order_from_signal(self, signal_event):
RiskManager will either verify, modify or eliminate.
"""
order = SuggestedOrder(
signal_event.ticker, signal_event.action
signal_event.ticker,
signal_event.action,
quantity=signal_event.suggested_quantity
)
return order

Expand Down
2 changes: 1 addition & 1 deletion qstrader/position_sizer/fixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self, default_quantity=100):

def size_order(self, portfolio, initial_order):
"""
This TestPositionSizer object simply modifies
This FixedPositionSizer object simply modifies
the quantity to be 100 of any share transacted.
"""
initial_order.quantity = self.default_quantity
Expand Down
16 changes: 16 additions & 0 deletions qstrader/position_sizer/naive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from .base import AbstractPositionSizer


class NaivePositionSizer(AbstractPositionSizer):
def __init__(self, default_quantity=100):
self.default_quantity = default_quantity

def size_order(self, portfolio, initial_order):
"""
This NaivePositionSizer object follows all
suggestions from the initial order without
modification. Useful for testing simpler
strategies that do not reside in a larger
risk-managed portfolio.
"""
return initial_order

0 comments on commit 9834aae

Please sign in to comment.