Exemplo n.º 1
0
class TestSimpleAlgorithm(unittest.TestCase):
    def setUp(self):
        self.qc = QCAlgorithm()
        Singleton.Setup(self.qc)
        self.qc.Initialize()
        self.qc.Securities = InternalSecurityManager([(FOO, 5), (BAR, 50)])

        self.algorithm1 = Algorithm(name="alg1", allocation=1.0)
        foo = self.algorithm1.AddEquity(FOO, Resolution.Daily).Symbol
        bar = self.algorithm1.AddEquity(BAR, Resolution.Daily).Symbol
        self.algorithm1.Portfolio.SetCash(200)
        self.algorithm1.Portfolio[foo] = Position(FOO, 10, 5)
        self.algorithm1.Portfolio[bar] = Position(BAR, 3, 50)

    def test_set_up(self):
        cash = 200
        foo_value = 10 * 5
        bar_value = 3 * 50
        total_value = 400
        self.assertEqual(self.algorithm1.Portfolio.Cash, cash)
        self.assertEqual(self.algorithm1.Portfolio.TotalHoldingsValue, foo_value + bar_value)
        self.assertEqual(self.algorithm1.Portfolio.TotalPortfolioValue, total_value)