Example #1
0
        static void Main(string[] args)
        {
            BasicConfigurator.Configure();
            SetConsoleCtrlHandler(new HandlerRoutine(ConsoleCtrlCheck), true);
            log.Info("Application Started");
            _priceEngine = new PriceEngine(new SecurityPriceRetrieverStrategy(new YahooMarketDataPriceSource()));
            string apiKey = ConfigurationManager.AppSettings["EdgarApiKey"];

            _statementEngine = new StatementEngine(new StatementRetrieverStrategy(new EdgarMarketDataFinancialStatementSource(apiKey)));
            _ncavEngine      = new NcavEngine();
            log.Info("Starting to retrieve prices");
            while (_priceEngine.ShouldWork)
            {
                _priceEngine.DoCycle();
            }
            log.Info("Prices retrieved.");
            log.Info("Starting to retrieve financial statements");
            while (_statementEngine.ShouldWork)
            {
                _statementEngine.DoCycle();
            }
            log.Info("Financial statements retrieved.");
            log.Info("Starting to Update Ncav and discounts on Ncav");
            while (_ncavEngine.ShouldWork)
            {
                _ncavEngine.DoCycle();
            }
            log.Info("Calculus on Net current asset value done.");
            //log.Info("Exiting Application.");
            using (var unitOfWork = new UnitOfWork(new MidasContext()))
            {
                var securitiesToInvest =
                    SecurityDalFactory.GetInstance()
                    .GetSecurityDal()
                    .GetAllSecurities()
                    .Where(x => x.DiscountOnNcav > (Decimal)0.25)
                    .Where(x => !BlackList.IsBlackListed(x.Ticker))
                    .OrderBy(x => x.DiscountOnNcav).Reverse()
                    .ToList();
                foreach (var security in securitiesToInvest)
                {
                    log.Info(string.Format("Found security {0} with discount on Ncav : {1}", security.Ticker, security.DiscountOnNcav));
                }
                log.Info(string.Format("Total : {0}", securitiesToInvest.Count));

                //var ssl = unitOfWork.Securities.Find(s => s.Ticker == "NTWK").First();
                //var statements = unitOfWork.FinancialStatements.Find(s => s.PrimarySymbol == "NTWK");
                //var latestStatement = statements.OrderBy(s => s.PeriodEnd).Last();
                //var ncav = latestStatement.BalanceSheet.TotalCurrentAssets -
                //           latestStatement.BalanceSheet.TotalCurrentLiabilities;
                //var last = ssl.Last;
                //var ticker = "DAL";
                //var fcau = unitOfWork.Securities.Find(x => x.Ticker == ticker);
                //var statements = unitOfWork.FinancialStatements.GetAll().Where(s => s.PrimarySymbol == ticker).Where(x => x.FormType == "10-K");
                int test = 0;

                Console.ReadLine();
            }
        }
Example #2
0
        public async Task <bool> ImportSecurities()
        {
            var factory    = new SecurityImporterFactory();
            var importer   = factory.GetSecurityImporter(SelectedMarket);
            var securities = await importer.ImportSecuritiesAsync(PathFile);

            var success = SecurityDalFactory.GetInstance().GetSecurityDal().ImportSecurities(securities);

            RefreshSecurities();
            return(success);
        }
Example #3
0
 public void RefreshNetNets()
 {
     NetNetSecurities.Clear();
     SecurityDalFactory.GetInstance()
     .GetSecurityDal()
     .GetAllSecurities()
     .Where(x => x.DiscountOnNcav > DiscountOnNcavThresholdPercent / 100)
     .Where(x => !BlackList.IsBlackListed(x.Ticker))
     .OrderBy(x => x.DiscountOnNcav).Reverse()
     .ToList()
     .ForEach(NetNetSecurities.Add);
 }
Example #4
0
        public void DoCycle()
        {
            Log.Info("Starting Ncav Engine Cycle");
            var securitiesToHandle = SecurityDalFactory.GetInstance().GetSecurityDal().GetAllSecurities().Where(x => x.IsNotADuplicate()).Where(x => x.HasStatements()).Where(x => x.HasNotNullMarketCap()).Where(x => x.IsCalculusOnNcavOutDated()).Take(BufferSecuritySize);
            var toHandle           = securitiesToHandle as IList <Security> ?? securitiesToHandle.ToList();

            if (!toHandle.Any())
            {
                Log.Info("Securities up to date. Stopping the Engine.");
                ShouldWork = false;
            }
            securitiesToHandle = CalculateNcavOnSecurities(toHandle);
            RefreshSecurities(securitiesToHandle);
            Log.Info("Price Ncav Cycle Ended.");
        }
Example #5
0
        public void DoCycle()
        {
            Log.Info("Starting Price Engine Cycle");
            var securitiesToHandle = SecurityDalFactory.GetInstance().GetSecurityDal().GetAllSecurities().Where(x => x.IsNotADuplicate()).Where(x => x.LastPriceIsTooOld()).Where(x => x.HasNotTooManyFailedAttempts()).Take(BufferSecuritySize);
            var toHandle           = securitiesToHandle as IList <Security> ?? securitiesToHandle.ToList();

            if (!toHandle.Any())
            {
                Log.Info("Securities up to date. Stopping the Engine.");
                ShouldWork = false;
            }
            securitiesToHandle = _priceStrategy.RetrievePriceForSecurities(toHandle);
            Log.Info("Prices retrieved. Saving.");
            RefreshSecurities(securitiesToHandle);
            Log.Info("Price Engine Cycle Ended.");
        }
Example #6
0
        public void RefreshSecurities()
        {
            AcquirersMultipleSecurityViewModels.Clear();
            var allSecurities =
                SecurityDalFactory.GetInstance()
                .GetSecurityDal()
                .GetAllSecurities()
                .Where(x => x.AcquirersMultiple > 0)
                .Where(x => x.IsMarketCapBigEnough(MarketCapitalizationMin))
                .Where(x => !x.IsMarketCapTooBig(MarketCapitalizationMax))
                .Where(x => !BlackList.IsBlackListed(x.Ticker))
                .Where(x => x.OperatingEarnings > 0)
                .OrderBy(x => x.AcquirersMultiple)
                .ToList();
            var currentRank = 0;

            foreach (var security in allSecurities)
            {
                currentRank++;
                AcquirersMultipleSecurityViewModels.Add(new AcquirersMultipleSecurityViewModel(security, currentRank));
            }
        }
Example #7
0
        public void DoCycle()
        {
            Log.Info("Starting Statement Engine Cycle");
            var securitiesToHandle =
                SecurityDalFactory.GetInstance()
                .GetSecurityDal()
                .GetAllSecurities()
                //.Where(x => x.HasNotANullPrice())
                //.Where(x => x.HasNotNullMarketCap())
                .Where(x => x.IsNotADuplicate())
                .Where(x => !x.StatementsAreUpToDate())
                .Where(x => x.NbOfFailedAttemptsToGetStatements < 3)
                .Take(BufferSecuritySize).ToList();


            var toHandle = (IList <Security>)securitiesToHandle;

            if (!toHandle.Any())
            {
                Log.Info("Securities up to date. Stopping the Engine.");
                ShouldWork = false;
                Log.Info("Statement Engine Cycle Ended.");
                return;
            }
            try
            {
                var securitiesAndStatements = _statementStrategy.RetrieveStatementsForSecurities(securitiesToHandle).ToList();
                RefreshSecurities(securitiesAndStatements);
            }
            catch (Exception exception)
            {
                Log.Error(exception.Message);
            }

            Log.Info("Statement Engine Cycle Ended.");
        }
Example #8
0
 public void RefreshSecurities()
 {
     Securities.Clear();
     SecurityDalFactory.GetInstance().GetSecurityDal().GetAllSecurities().ToList().ForEach(Securities.Add);
 }