zipline-live / zipline

Zipline-Live, a Pythonic Algorithmic Trading Library
http://www.zipline-live.io/
Apache License 2.0
394 stars 65 forks source link

Trading guard testcases #49

Open tibkiss opened 6 years ago

tibkiss commented 6 years ago

Contrary to what zipline-live's feature page states order/trading guards are supported, but not tested: LiveTradingAlgorithm.order() calls TradingAlgorithm._calculate_order(), which calls to TradingAlgorithm.validate_order_params() which finally enforces that the order meets the guards set by the user.

This effort is to prove that Trading Guards are working: Create a testcase which tests that sets trading guards are called if they are set and used through LiveTradingAlgorithm.

peterfabakker commented 6 years ago

so these tests?

set_long_only() -> try to order a short: should fail set_do_not_order_list([asset1, asset 2]) -> try order asset1 or asset 2: should fail set_max_order_count(2): -> try order 1 time: success, 2 time success, 3 times fail set_max_order_count(0): -> any order should fail set_max_order_count(-1): -> any order should fail set_max_order_size( max_shares=10) -> any order with more then 10 shares should fail set_max_order_size( max_notional=1000.00) -> any order with more then 1000 $ should fail set_max_order_size(asset1, max_shares=1) -> 2 shares of asset1 will fail set_max_order_size(asset1, max_notional=1000.00) -> 1001.00 of value of asset1 will fail

first buy 10 shares for 1000 and then: set_max_position_size( max_shares=11) -> any order with more then 1 shares should fail, 1 share should succeed set_max_position_size( max_notional=1100.00) -> any order with more then 100 $ should fail, 99$ should succeed set_max_position_size(asset1, max_shares=11) -> 2 shares of asset1 will fail, 1 will succeed set_max_position_size(asset1, max_notional=1100.00) -> 101.00 of value of asset1 will fail, 100 will succeed

peterfabakker commented 6 years ago

Do set_max_order_size, set_max_position_size, set_max_order_size need a short version?

tibkiss commented 6 years ago

I think the proposed tests are all valid. Short version would also make sense.