Ejemplo n.º 1
0
 function load(ObjectManager $manager)
 {
     $usedSymbols = array();
     $repository = $manager->getRepository('WealthbotAdminBundle:Security');
     $securities = $this->getCsvData('securities.csv');
     foreach ($securities as $index => $item) {
         if ($index === 0) {
             continue;
         }
         $name = trim($item[0]);
         $symbol = trim($item[1]);
         $typeString = 'security-type-' . (trim($item[2]) === 'ETF' ? 'EQ' : 'MU');
         $expenseRatio = round((double) str_replace(',', '.', trim($item[3])), 2);
         /** @var SecurityType $securityType */
         $securityType = $this->getReference($typeString);
         $exist = $repository->findOneBySymbol($symbol);
         if (!$exist && !in_array($symbol, $usedSymbols)) {
             $usedSymbols[] = $symbol;
             $security = new Security();
             $security->setName($name);
             $security->setSymbol($symbol);
             $security->setSecurityType($securityType);
             $security->setExpenseRatio($expenseRatio);
             $manager->persist($security);
         }
     }
     $manager->flush();
 }
Ejemplo n.º 2
0
 public function setUp()
 {
     $subclassMock1 = $this->getMock('Wealthbot\\AdminBundle\\Entity\\Subclass', array('getId'));
     $subclassMock1->expects($this->any())->method('getId')->will($this->returnValue(1));
     $subclassMock1->setName('Subclass1');
     $subclassMock1->setExpectedPerformance(0.5);
     $subclassMock2 = $this->getMock('Wealthbot\\AdminBundle\\Entity\\Subclass', array('getId'));
     $subclassMock2->expects($this->any())->method('getId')->will($this->returnValue(2));
     $subclassMock2->setName('Subclass2');
     $subclassMock2->setExpectedPerformance(0.7);
     $entity1 = new CeModelEntity();
     $security1 = new Security();
     $security1->setExpenseRatio(0.6);
     $securityAssignment1 = new SecurityAssignment();
     $securityAssignment1->setSecurity($security1);
     $securityAssignment1->setSubclass($subclassMock1);
     $entity1->setSubclass($subclassMock1);
     $entity1->setPercent(40);
     $entity1->setSecurityAssignment($securityAssignment1);
     $entity2 = new CeModelEntity();
     $security2 = new Security();
     $security2->setExpenseRatio(0.3);
     $securityAssignment2 = new SecurityAssignment();
     $securityAssignment2->setSecurity($security2);
     $securityAssignment2->setSubclass($subclassMock2);
     $entity2->setSubclass($subclassMock2);
     $entity2->setPercent(60);
     $entity2->setSecurityAssignment($securityAssignment2);
     $entity3 = new CeModelEntity();
     $security3 = new Security();
     $security3->setExpenseRatio(0.7);
     $securityAssignment3 = new SecurityAssignment();
     $securityAssignment3->setSecurity($security3);
     $securityAssignment3->setSubclass($subclassMock1);
     $entity3->setSubclass($subclassMock1);
     $entity3->setPercent(100);
     $entity3->setSecurityAssignment($securityAssignment3);
     $entity3->setIsQualified(true);
     $model = new CeModel('Model');
     $model->addModelEntity($entity1);
     $model->addModelEntity($entity2);
     $model->addModelEntity($entity3);
     $model->setLowMarketReturn(0.6);
     $model->setGenerousMarketReturn(1.3);
     $model->setForecast(0);
     $this->portfolioInformation = new PortfolioInformation();
     $this->portfolioInformation->setModel($model);
 }
Ejemplo n.º 3
0
 private function loadSecurities(ObjectManager $manager)
 {
     $repository = $manager->getRepository('WealthbotAdminBundle:Security');
     foreach ($this->securities as $item) {
         $security = $repository->findOneBySymbol($item['symbol']);
         if (!$security) {
             /** @var SecurityType $securityType */
             $securityType = $this->getReference('security-type-' . $item['security_type']);
             $security = new Security();
             $security->setName($item['name']);
             $security->setSymbol($item['symbol']);
             $security->setSecurityType($securityType);
             $security->setExpenseRatio($item['exp_ratio']);
             $manager->persist($security);
         }
         $this->addReference('security-' . $item['symbol'], $security);
     }
 }
Ejemplo n.º 4
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine')->getEntityManager();
     $em->getConnection()->getConfiguration()->setSQLLogger(null);
     $securityRepo = $em->getRepository('WealthbotAdminBundle:Security');
     $securityTypeRepo = $em->getRepository('WealthbotAdminBundle:SecurityType');
     $i = 0;
     $typeHash = array();
     $securities = $this->loadCsvData('security_full.csv', $maxLength = 10000, $delimiter = ',');
     foreach ($securities as $index => $item) {
         if ($index === 0) {
             continue;
         }
         $type = trim($item[0]);
         $type = $type === 'ETF' ? 'EQ' : 'MU';
         $symbol = trim($item[1]);
         $name = trim($item[2]);
         $ratio = round((double) str_replace(',', '.', trim($item[3])), 2);
         if (isset($typeHash[$type])) {
             $securityType = $typeHash[$type];
         } else {
             $securityType = $securityTypeRepo->findOneByName($type);
             if ($securityType) {
                 $typeHash[$type] = $securityType;
             }
         }
         $security = $securityRepo->findOneBySymbol($symbol);
         if (!$security && $securityType) {
             if (++$i % 100 == 0) {
                 $security = new Security();
                 $security->setName($name);
                 $security->setSymbol($symbol);
                 $security->setSecurityType($securityType);
                 $security->setExpenseRatio($ratio);
                 $em->persist($security);
                 $output->writeln("Security items [{$i}] has been loaded.");
             }
         }
     }
     $em->flush();
     $em->clear();
     $output->writeln("Security items [{$i}] has been loaded.");
     $output->writeln("Success!");
 }