def testCanSetPerPositionShortLimitAndUnsetLong(self):
     rm = FxPositionLimitRiskEvaluator()
     rm.set_limit('SHF_USD', posLimit=10000)
     self.assertEquals(rm.posLimits['SHF_USD'], 10000)
     rm.set_limit('SHF_USD', posLimitShort=-22)
     self.assertEquals(rm.posLimitsShort['SHF_USD'], -22)
     self.assertFalse('SHF_USD' in rm.posLimits)
 def testFilterOrderDefaultShortPositionLimitBreach(self):
     rm = FxPositionLimitRiskEvaluator()
     order = OrderEvent('CHF_USD', 10000, 'sell')
     print(order)
     filtered = rm.filter_order(order)
     self.assertNotEquals(filtered.units, 10000)
     self.assertEquals(filtered.units, 0)
 def testFilterOrderPositionLimitBreach(self):
     rm = FxPositionLimitRiskEvaluator(posLimit=100)
     order = OrderEvent('CHF_USD', 10000, 'buy')
     print(order)
     filtered = rm.filter_order(order)
     self.assertNotEquals(filtered.units, 10000)
     self.assertEquals(filtered.units, 100)
 def testHasAppendedShortPos_FilterOrderPositionLimitBreach(self):
     rm = FxPositionLimitRiskEvaluator(posLimit=100)
     rm.append_position('CHF_USD', -10)
     order = OrderEvent('CHF_USD', 10000, 'buy')
     filtered = rm.filter_order(order)
     self.assertNotEquals(filtered.units, 10000)
     self.assertEquals(filtered.units, 110)
    def testFilteredOrderSpecificLimit_2InstrumentsBreahces(self):
        posLimits = {'CHF_USD': 1234, 'EUR_SGD': 10000}
        rm = FxPositionLimitRiskEvaluator(posLimit=100, posLimits=posLimits)
        filtered = rm.filter_order(OrderEvent('CHF_USD', 10000, 'buy'))
        self.assertEquals(filtered.units, 1234)

        filtered = rm.filter_order(OrderEvent('EUR_SGD', 5000, 'buy'))
        self.assertEquals(filtered.units, 5000)

        filtered = rm.filter_order(OrderEvent('EUR_SGD', 50000, 'buy'))
        self.assertEquals(filtered.units, 10000)
    def testFilteredOrderSpecificLimitBreach_2Instruments(self):
        posLimits = {'CHF_USD': 1234}
        rm = FxPositionLimitRiskEvaluator(posLimit=100, posLimits=posLimits)
        order = OrderEvent('CHF_USD', 10000, 'buy')
        filtered = rm.filter_order(order)
        self.assertEquals(filtered.units, 1234)

        order = OrderEvent('EUR_SGD', 1000, 'buy')
        filtered = rm.filter_order(order)
        self.assertNotEquals(filtered.units, 1000)
        self.assertEquals(filtered.units, 100)
Example #7
0
 def test_should_not_allow_to_add_same_risk_manager(self):
     rm = FxPositionLimitRiskEvaluator(posLimitShort=-1000000)
     self.portfolio.add_risk_manager(rm)
     try:
         self.portfolio.add_risk_manager(rm)
         self.fail('Should have failed while adding same risk manager')
     except:
         pass
Example #8
0
 def test_should_reduce_units_of_large_sell_order_using_position_limit_manager(
         self):
     rm = FxPositionLimitRiskEvaluator(posLimitShort=-100)
     self.portfolio.add_risk_manager(rm)
     order = OrderEvent('EUR_USD', 1000, 'sell')
     self.cache.set_rate(TickEvent('EUR_USD', get_time(), 1.0, 1.0))
     try:
         filtered_order = self.portfolio.check_order(order)
         self.assertEqual(rm.posLimitShort, -1 * filtered_order.units)
     except RuntimeError as e:
         self.fail(
             'Expecting a filtered order per currency manager\'s limit, but got exception - [%s]'
             % e)
Example #9
0
 def test_should_reduce_units_of_large_buy_order_using_ccy_exposure_manager_when_pos_limit_manager_is_generous(
         self):
     rm = FxPositionLimitRiskEvaluator(posLimit=1000000)
     self.portfolio.add_risk_manager(rm)
     self.cache.set_rate(TickEvent('EUR_USD', get_time(), 1.0, 1.0))
     try:
         filtered_order = self.portfolio.check_order(self.large_buy_order)
         self.assertEqual(self.ccy_exposure_manager.ccy_limit,
                          filtered_order.units)
     except RuntimeError as e:
         self.fail(
             'Expecting a filtered order per currency manager\'s limit, but got exception - [%s]'
             % e)
Example #10
0
    def wire(self, com_q=None, in_q=None, out_q=None, hb_q=None, e_q=None):
        portfolio = FxPortfolio(self.portfolio_ccy,
                                self.portfolio_balance,
                                port_limit=self.portfolio_limit,
                                port_limit_short=self.portfolio_limit_short)

        ccy_exposure_manager = \
            CcyExposureLimitRiskEvaluator(self.portfolio_ccy, self.prices_cache, ccy_limit=10000, ccy_limit_short=-10000)

        portfolio.set_price_cache(
            self.prices_cache).set_ccy_exposure_manager(ccy_exposure_manager)
        rm = FxPositionLimitRiskEvaluator(posLimit=10000, posLimitShort=-10000)
        portfolio.add_risk_manager(rm)

        portfolio_loop = EventLoop(in_q, portfolio, processed_event_q=out_q)
        portfolio_loop.set_command_q(com_q)
        return portfolio_loop
 def testFilteredOrderSpecificLimitLessThanDefault_Breach(self):
     posLimits = {'CHF_USD': 100}
     rm = FxPositionLimitRiskEvaluator(posLimit=1000, posLimits=posLimits)
     filtered = rm.filter_order(OrderEvent('CHF_USD', 1000, 'buy'))
     self.assertEquals(filtered.units, 100)
 def testHasAppendedShortPos_FilteredOrderSpecificLimitBreach(self):
     posLimits = {'CHF_USD': 1234}
     rm = FxPositionLimitRiskEvaluator(posLimit=100, posLimits=posLimits)
     rm.append_position('CHF_USD', -100)
     filtered = rm.filter_order(OrderEvent('CHF_USD', 10000, 'buy'))
     self.assertEquals(filtered.units, 1334)
 def testFilteredOrderHasCorrectType(self):
     rm = FxPositionLimitRiskEvaluator(posLimit=100)
     order = OrderEvent('CHF_USD', 100, 'buy')
     filtered = rm.filter_order(order)
     self.assertEquals(order.order_type, filtered.order_type)
 def testFilteredOrderSpecificLimitBreachShort(self):
     posLimitsShort = {'CHF_USD': -234}
     rm = FxPositionLimitRiskEvaluator(posLimitShort=-100, posLimitsShort=posLimitsShort)
     filtered = rm.filter_order(OrderEvent('CHF_USD', 10000, 'sell'))
     self.assertEquals(filtered.units, 234)
 def testFilterOrderHasCorrectInstrument(self):
     rm = FxPositionLimitRiskEvaluator(posLimit=100)
     filtered = rm.filter_order(OrderEvent('CHF_USD', 100, 'buy'))
     self.assertEquals(filtered.instrument, 'CHF_USD')
 def testFilteredOrderHasCorrectSide2(self):
     rm = FxPositionLimitRiskEvaluator(posLimit=100)
     filtered = rm.filter_order(OrderEvent('CHF_USD', 100, 'sell'))
     self.assertEquals(filtered.side, 'sell')
 def testFilterOrder(self):
     rm = FxPositionLimitRiskEvaluator()
     filtered = rm.filter_order(OrderEvent('CHF_USD', 1000, 'buy'))
 def testCanAppendPositions(self):
     rm = FxPositionLimitRiskEvaluator()
     rm.append_position('EUR_CHF', 123)
 def testCanSetPerPositionShortLimit(self):
     rm = FxPositionLimitRiskEvaluator()
     rm.set_limit('SHF_USD', posLimitShort=-22)
     self.assertEquals(rm.posLimitsShort['SHF_USD'], -22)
 def testCanSetPerPositionLimit(self):
     rm = FxPositionLimitRiskEvaluator()
     rm.set_limit('SHF_USD', posLimit=10000)
     self.assertEquals(rm.posLimits['SHF_USD'], 10000)
 def testCanAppendedSameIntrumentTwice(self):
     rm = FxPositionLimitRiskEvaluator()
     rm.append_position('EUR_CHF', 123)
     rm.append_position('EUR_CHF', 27)
     self.assertEquals(rm.positions['EUR_CHF'], 150)
Example #22
0
def step_impl(context):
    context.rm = FxPositionLimitRiskEvaluator()
 def testHas2AppendedPositions(self):
     rm = FxPositionLimitRiskEvaluator()
     rm.append_position('EUR_CHF', 123)
     rm.append_position('EUR_USD', 1000)
     self.assertEquals(rm.positions['EUR_CHF'], 123)
     self.assertEquals(rm.positions['EUR_USD'], 1000)
Example #24
0
def step_impl(context, limitAmount):
    context.rm = None
    context.rm = FxPositionLimitRiskEvaluator(posLimitShort=-1 *
                                              float(limitAmount))
    def testHasAppended2ShortPos_FilteredOrderSpecificLimit_2InstrumentsBreahces(self):
        posLimits = {'CHF_USD': 1234, 'EUR_SGD': 10000}
        rm = FxPositionLimitRiskEvaluator(posLimit=100, posLimits=posLimits)
        rm.append_position('CHF_USD', -50)
        rm.append_position('EUR_SGD', -100)
        filtered = rm.filter_order(OrderEvent('CHF_USD', 10000, 'buy'))
        self.assertEquals(filtered.units, 1284)
        rm.append_position(filtered.instrument, filtered.units)

        filtered = rm.filter_order(OrderEvent('EUR_SGD', 5000, 'buy'))
        self.assertEquals(filtered.units, 5000)
        rm.append_position(filtered.instrument, filtered.units)

        filtered = rm.filter_order(OrderEvent('EUR_SGD', 50000, 'buy'))
        self.assertEquals(filtered.units, 5100)