예제 #1
0
class TestMultipleAlgorithms(unittest.TestCase):
    def setUp(self):
        self.qc = QCAlgorithm()
        Singleton.Setup(self.qc)
        self.qc.Initialize()
        self.qc.Securities = InternalSecurityManager([(FOO, 5), (BAR, 50)])
        foo = self.qc.AddEquity(FOO, Resolution.Daily).Symbol
        bar = self.qc.AddEquity(BAR, Resolution.Daily).Symbol

        self.algorithm1 = Algorithm(name="alg1", allocation=0.5)
        self.algorithm1.Portfolio.SetCash(200)
        self.algorithm1.Portfolio[foo] = Position(FOO, 10, 5)

        self.algorithm2 = Algorithm(name="alg2", allocation=0.5)
        self.algorithm2.Portfolio.SetCash(200)
        self.algorithm2.Portfolio[bar] = Position(BAR, 3, 50)

    def test_algorithms_cash(self):
        self.assertEqual(self.algorithm1.Portfolio.Cash, 200)
        self.assertEqual(self.algorithm2.Portfolio.Cash, 200)
        self.assertEqual(self.algorithm2.Portfolio.Performance, 75.0)
        self.assertEqual(self.algorithm2.Performance, 75.0)

    def test_algorithms_total_value(self):
        self.assertEqual(self.algorithm1.Portfolio.TotalPortfolioValue, 200 + (10 * 5))
        self.assertEqual(self.algorithm2.Portfolio.TotalPortfolioValue, 200 + (3 * 50))

    def test_algorithm_set_warmup(self):
        self.algorithm1.SetWarmUp(123)
        self.algorithm2.SetWarmUp(321)
        # pylint: disable=E1101
        self.assertEqual(Singleton._warm_up, 321)

    def test_qc_set_warmup_should_not_override_algorithm(self):
        self.algorithm1.SetWarmUp(123)
        self.algorithm2.SetWarmUp(321)
        Singleton.SetWarmUp(444)
        self.assertEqual(Singleton._warm_up, 321)

    def test_qc_set_warmup_from_main(self):
        Singleton.SetWarmUp(444)
        self.assertEqual(Singleton._warm_up, 444)
예제 #2
0
    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)
예제 #3
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)
예제 #4
0
import argparse
import sys
#for bypassing import paths
curpth = os.path.dirname(os.path.abspath(__file__))
targetpth1 = curpth + '/../../src/'
targetpth2 = curpth + '/../../config/'
sys.path.insert(0, targetpth1)
sys.path.insert(0, targetpth2)

from team import Team
from day import Day
from student import Student
from algorithm import AlgorithmManager

if __name__ == "__main__":
    algorithm = AlgorithmManager()
    studentlis = []

    d1 = Day("Tuesday")
    d1.insertTime(10)
    d1.insertTime(13)
    d2 = Day("Wednesday")
    d2.insertTime(10)
    d2.insertTime(14)

    s1 = Student("Hope, Bob", "*****@*****.**")
    days = [d1, d2]
    filters1 = {}
    filters1['Meeting Times'] = days
    s1.setFilters(filters1)
    studentlis.append(s1)
예제 #5
0
def execute_algorithm(args, dm, mm):
    am = AlgorithmManager(args, dm, mm)
    am.new_algorithm(args['name_algorithm'])
    am.run_algorithm(args['name_algorithm'])
    return False