Exemple #1
0
    def is_methods(self, key, attr, expect):
        """
        Use for each test is_strategy
        :param key: int
        :param attr: str
        :param expect: bool
        """
        self.ready_all(key)

        for position in Position.objects.all():
            pos_set = PositionSet(position)

            self.identify = Identify(pos_set)

            method = getattr(self.identify, attr)
            result = method()
            print 'symbol: %s, stock qty: %d, options len: %d, result: %s' \
                  % (position.symbol, self.identify.pos_set.stock.quantity,
                     self.identify.pos_set.options.count(), result)

            self.assertEqual(result, expect)

        Position.objects.all().delete()

        print '\n' + '-' * 100 + '\n'
Exemple #2
0
    def setUp(self):
        TestReadyUp.setUp(self)
        self.ready_all(key=3)

        position = Position.objects.first()
        self.pos_set = PositionSet(position)

        self.leg_one_context = leg_one.LegOneContext(self.pos_set)
Exemple #3
0
    def setUp(self):
        TestReadyUp.setUp(self)

        self.ready_all(key=1)

        position = Position.objects.all().first()
        pos_set = PositionSet(position)

        # first create spread
        self.sp = spread.Spread(pos_set)
Exemple #4
0
    def setUp(self):
        TestReadyUp.setUp(self)
        self.ready_all(key=1)

        position = Position.objects.first()
        self.pos_set = PositionSet(position)

        print 'Symbol: %s\n' % self.pos_set.stock.position.symbol

        self.stock_short = stock.StockShort(self.pos_set)
Exemple #5
0
    def setUp(self):
        TestReadyUp.setUp(self)
        self.ready_all(key=2)

        position = Position.objects.first()
        self.pos_set = PositionSet(position)

        self.hedge_context = hedge.HedgeContext(self.pos_set)

        self.set_prices = [12.5, 20.7, 33.94, 8.71, 114.81]
        self.set_conditions = ['>', '<', '==', '<=', '>=']
        self.test_prices = [13.9, 22.67, 33.94, 7.66, 100.88]
Exemple #6
0
    def setUp(self):
        TestReadyUp.setUp(self)
        self.ready_all(key=3)

        position = Position.objects.get(symbol='AAPL')
        self.pos_set = PositionSet(position)

        self.call_long = leg_one.CallLong(self.pos_set)

        self.option_price = float(self.call_long.pos_set.option.trade_price)
        self.option_strike = float(self.call_long.pos_set.option.strike_price)
        self.option_quantity = float(self.call_long.pos_set.option.quantity)
        self.option_right = int(self.call_long.pos_set.option.right)
Exemple #7
0
    def setUp(self):
        TestReadyUp.setUp(self)
        self.ready_all(key=3)

        position = Position.objects.get(symbol='FSLR')
        self.pos_set = PositionSet(position)

        self.put_naked = leg_one.PutNaked(self.pos_set)

        self.option_price = float(self.put_naked.pos_set.option.trade_price)
        self.option_strike = float(self.put_naked.pos_set.option.strike_price)
        self.option_quantity = float(self.put_naked.pos_set.option.quantity)
        self.option_right = int(self.put_naked.pos_set.option.right)
Exemple #8
0
    def test_identify(self):
        """
        Test core method identify
        """
        self.ready_all()

        for position in Position.objects.all():
            pos_set = PositionSet(position)

            self.identify = Identify(pos_set)
            self.identify.identify()

            print self.identify.spread
Exemple #9
0
    def setUp(self):
        TestReadyUp.setUp(self)
        self.ready_all(key=2)

        position = Position.objects.get(symbol='C')
        self.pos_set = PositionSet(position)

        self.covered_put = hedge.CoveredPut(self.pos_set)

        self.stock_price = float(self.covered_put.pos_set.stock.trade_price)
        self.stock_quantity = float(self.covered_put.pos_set.stock.quantity)
        self.option_price = float(self.covered_put.pos_set.option.trade_price)
        self.option_strike = float(
            self.covered_put.pos_set.option.strike_price)
Exemple #10
0
    def test_get_cls_short_stock(self):
        """
        Test get class return long stock position
        """
        self.ready_all(key=1)
        stock = PositionStock.objects.exclude(quantity__gte=0).first()

        stock_identify = StockIdentify(stock)
        cls = stock_identify.get_cls()
        self.assertEqual(cls, StockShort)

        print 'stock quantity: %d' % stock.quantity
        print 'class module: %s\n' % cls

        spread = cls(PositionSet(stock.position))
        print spread
Exemple #11
0
    def test_get_cls(self):
        """
        Test get name using stock identify class
        """
        self.ready_all(key=3)

        for option in PositionOption.objects.exclude(quantity=0).all():
            leg_one_identify = LegOneIdentify(option)

            cls = leg_one_identify.get_cls()

            print 'class name: %s' % cls.__name__

            self.assertIn(cls, [CallLong, CallNaked, PutLong, PutNaked, None])

            print cls(PositionSet(option.position))
Exemple #12
0
    def setUp(self):
        TestReadyUp.setUp(self)

        self.ready_all(key=2)
        position = Position.objects.get(symbol='BAC')
        self.pos_set = PositionSet(position)

        self.protective_call = hedge.ProtectiveCall(self.pos_set)

        self.stock_price = float(
            self.protective_call.pos_set.stock.trade_price)
        self.stock_quantity = float(
            self.protective_call.pos_set.stock.quantity)
        self.option_price = float(
            self.protective_call.pos_set.option.trade_price)
        self.option_strike = float(
            self.protective_call.pos_set.option.strike_price)
Exemple #13
0
    def test_get_cls(self):
        """
        Test get name using stock identify class
        """
        self.ready_all(key=2)

        for position in Position.objects.all():
            stock = PositionStock.objects.filter(position=position).first()
            """:type: PositionStock"""

            option = PositionOption.objects.filter(position=position).first()
            """:type: PositionOption"""

            hedge_identify = HedgeIdentify(stock, option)

            cls = hedge_identify.get_cls()

            self.assertIn(cls, [
                hedge.CoveredCall, hedge.ProtectiveCall, hedge.CoveredPut,
                hedge.ProtectivePut, None
            ])

            print cls(PositionSet(stock.position))