private IEnumerable <ScreeningResult> ConvertToScreeningResult(DataTable dt, ScreeningParams Params)
        {
            return(dt.AsEnumerable().Where(row =>
                                           (Convert.ToDouble(row["PER"]) >= Params.MinPER && Convert.ToDouble(row["PER"]) <= Params.MaxPER || !Params.UsePER) &&
                                           (Convert.ToDouble(row["PBR"]) >= Params.MinPBR && Convert.ToDouble(row["PBR"]) <= Params.MaxPBR || !Params.UsePBR) &&
                                           (Convert.ToDouble(row["ROE"]) >= Params.MinROE && Convert.ToDouble(row["ROE"]) <= Params.MaxROE || !Params.UseROE) &&
                                           (Convert.ToDouble(row["DebtRatio"]) >= Params.MinDebtRatio && Convert.ToDouble(row["DebtRatio"]) <= Params.MaxDebtRatio || !Params.UseDebtRatio) &&
                                           (Convert.ToDouble(row["AggregateValue"]) >= (Params.MinAggregateValue * 100000000) && Convert.ToDouble(row["AggregateValue"]) <= (Params.MaxAggregateValue * 100000000) || !Params.UseAggregateValue) &&
                                           (!((Convert.ToString(row["SectorName"]) == "금융지원 서비스업" || Convert.ToString(row["SectorName"]) == "기타 금융업" || Convert.ToString(row["SectorName"]) == "투자기관" || Convert.ToString(row["SectorName"]) == "은행 및 저축기관")) || !Params.OnlyNonFinance)
                                           ).Select(row =>
            {
                Screener screener = new Screener(Convert.ToDouble(row["PER"]), Convert.ToDouble(row["PBR"]), Convert.ToDouble(row["DebtRatio"]));
                double score = screener.Scoring();

                return new ScreeningResult
                {
                    ISIN = Convert.ToString(row[0]),
                    Name = Convert.ToString(row[1]),
                    Date = Convert.ToDateTime(row["Date"]).ToShortDateString(),
                    Score = score.ToString("0.00", CultureInfo.InvariantCulture),
                    Price = String.Format("{0:#,###}", Convert.ToInt32(row["Price"])),
                    EPS = String.Format("{0:#,###}", Convert.ToInt32(row["EPS"])),
                    PER = Convert.ToDouble(row["PER"]).ToString("0.00", CultureInfo.InvariantCulture),
                    PBR = Convert.ToDouble(row["PBR"]).ToString("0.00", CultureInfo.InvariantCulture),
                    ROE = Convert.ToDouble(row["ROE"]).ToString("0.00", CultureInfo.InvariantCulture),
                    DebtRatio = Convert.ToDouble(row["DebtRatio"]).ToString("0.00", CultureInfo.InvariantCulture),
                    StockNumber = String.Format("{0:#,###}", Convert.ToInt32(row["StockNumber"])),
                    NetProfit = String.Format("{0:#,###}", Convert.ToDouble(row["NetProfit"])),
                    AggregateValue = String.Format("{0:#,###}", Convert.ToDouble(row["AggregateValue"]) / 100000000)
                };
            }));
        }
Esempio n. 2
0
        public ScreenshotSource(IntPtr hWnd)
        {
            _screener       = new Screener(hWnd);
            _screenshotItem = new UpdatableItem <BImage>(BImageExtentions.CopyThreadSafty);

            Task.Factory.StartNew(ScreenshotProc);
        }
        public async Task <List <ScreenerResponse> > GetMacdCrossingSignalFromBelowBullish()
        {
            var cacheKey = $"MacdCrossingSignalFromBelowBullish-{DateTime.Now:MMdd}";
            var request  = new Screener {
                TechnicalMacd = 2
            };

            return(await GetScreenerRequest(request, cacheKey));
        }
Esempio n. 4
0
        private void GoNext_OnClick(object sender, RoutedEventArgs e)
        {
            var model    = (ScreenerViewModel)DataContext;
            var screener = new Screener {
                Event = model.Event, Name = model.Name
            };

            Frame.Navigate(typeof(QuestionnairePage), JsonConvert.SerializeObject(screener));
        }
        public async Task <List <ScreenerResponse> > Get52WeekLow()
        {
            var cacheKey = $"52WeekLow-{DateTime.Now:MMdd}";
            var request  = new Screener {
                TechnicalWeekLow52 = 2
            };

            return(await GetScreenerRequest(request, cacheKey));
        }
        public async Task <List <ScreenerResponse> > GreenVolume()
        {
            var cacheKey = string.Format(CACHE_GREEN_VOLUME, $"{DateTime.Now:MMdd}");
            var request  = new Screener {
                DescriptiveChangePercent = 2, TechnicalRelativeStrengthIndex14 = 28, TechnicalVolumeAverage20 = 2
            };

            return(await GetScreenerRequest(request, cacheKey));
        }
        /// <summary>
        /// Oversold <= 30
        /// MA9 below SMA20
        /// </summary>
        /// <returns></returns>
        public async Task <List <ScreenerResponse> > GetOversoldStocks()
        {
            var cacheKey = $"OversoldStocks-{DateTime.Now:MMdd}";
            var request  = new Screener {
                TechnicalMovingAverage9 = 53, TechnicalRelativeStrengthIndex14 = 8
            };

            return(await GetScreenerRequest(request, cacheKey));
        }
        /// <summary>
        /// Oversold
        /// RSI < 10
        /// </summary>
        /// <returns></returns>
        public async Task <List <ScreenerResponse> > GetOversoldStocksLessThan20()
        {
            var cacheKey = $"OversoldStocksLessThan20-{DateTime.Now:MMdd}";
            var request  = new Screener {
                TechnicalRelativeStrengthIndex14 = 9
            };

            return(await GetScreenerRequest(request, cacheKey));
        }
Esempio n. 9
0
        public virtual async Task <List <ScreenerResponse> > GetScreenerResponse(Screener screener)
        {
            var data = await _stockApiRepository.GetScreenerResponse(screener);

            if (data == null)
            {
                throw new InvestagramApiException(_investaCookieExpiredErrorMessage);
            }

            return(data);
        }
Esempio n. 10
0
 public ScreenerViewModel()
 {
     Screener                       = new Screener();
     Screener.ScreenerId            = -1; // it indicates to Viewer that the screener is new
     Screener.PostScreeningActionId = 1;
     SelectedGenres                 = new List <int>();
     SelectedAttributes             = new List <int>();
     Duration                       = new TimePickerViewModel()
     {
         TimeHR = -1, Prefix = "Duration", IsNullable = true, HideAmPm = true
     };
 }
Esempio n. 11
0
        /// <summary>
        /// Computes the compression ratio of the Screener for all files in the given directory.
        /// </summary>
        /// <param name="dir">The folder containing xaml(x) files</param>
        /// <returns>The compression ratio after using the Screener</returns>
        public static double ScreenerStatistics(DirectoryInfo dir)
        {
            IList <double> ratios    = new List <double>();
            double         sumRatios = 0.0;
            string         tempDir   = System.IO.Path.GetTempPath();

            foreach (FileInfo file in dir.GetFiles())
            {
                if (file.Extension.Equals(".xaml") || file.Extension.Equals(".xamlx"))
                {
                    // Compute Filesize (1 Byte = 1 Literal)
                    long sizeBefore = file.Length;
                    // Do Screener
                    string outputPath = tempDir + file.Name + ".temp";

                    Screener screener = new Screener(file.FullName, outputPath); // TODO FilePath In Output
                    screener.ScreenXaml();
                    // Compute Filesize
                    FileInfo outputFile = new FileInfo(outputPath);
                    long     sizeAfter  = outputFile.Length;
                    // Delete Tempfile
                    outputFile.Delete();
                    // Add Ratio
                    double ratio = (double)sizeAfter / sizeBefore;
                    ratios.Add(ratio);
                }
            }
            foreach (DirectoryInfo subDir in dir.GetDirectories())
            {
                double subratio = ScreenerStatistics(subDir);

                if (subratio > 0)
                {
                    ratios.Add(ScreenerStatistics(subDir));
                }
            }

            // Compute Average Ratio
            foreach (double ratio in ratios)
            {
                sumRatios += ratio;
            }

            if (ratios.Count > 0)
            {
                return((double)sumRatios / ratios.Count);
            }
            else
            {
                return(0.0);
            }
        }
        public async Task <List <ScreenerResponse> > GetScreenerRequest(Screener request, string cacheKey)
        {
            //if within trading day and time, always fetch the data
            if (IsTradingHours())
            {
                var data = await base.GetScreenerResponse(request);

                SafeRemoveCache <List <ScreenerResponse> >(cacheKey);
                return(data);
            }

            return(await _cache.GetOrAddAsync(cacheKey, () => base.GetScreenerResponse(request), _marketStatusRepository.NextClosingDateTime()));
        }
Esempio n. 13
0
        static async Task Main(string[] args)
        {
            SetupStaticLogger();

            Settings settings = await GetSettings();

            var telegramBot = new TelegramBot(settings.TelegramBotToken, settings.TelegramChatId);
            await telegramBot.Start();

            var notificationSender = new NotificationSender(telegramBot);

            var screener = new Screener(settings.TcsToken,
                                        settings.TickersToScan.Distinct().ToArray(),
                                        settings.NotificationRules,
                                        notificationSender.SendNotification);

            AppDomain.CurrentDomain.ProcessExit += async(s, e) =>
            {
                await HandleStopCommand(telegramBot);
            };

            Console.CancelKeyPress += async(s, e) =>
            {
                await HandleStopCommand(telegramBot);
            };

            while (!stopCommand)
            {
                try
                {
                    //check working days and stock working hours
                    var dt  = DateTime.UtcNow;
                    var day = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(dt);
                    if (day == DayOfWeek.Sunday || day == DayOfWeek.Saturday || dt.Hour < 6 || dt.Hour > 22)
                    {
                        await Task.Delay(TimeSpan.FromSeconds(10));

                        continue;
                    }

                    await screener.Scan();
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                    await Task.Delay(TimeSpan.FromSeconds(1));
                }
            }
        }
Esempio n. 14
0
        public ActionResult Screener(int?filmId)
        {
            ScreenerViewModel model = new ScreenerViewModel();

            model.ListOfAttributes = new ScreenerRepository().GetListOfAttributes();
            model.ListOfGenres     = new ScreenerRepository().GetListOfGenres();
            model.ListOfFormats    = new ScreenerRepository().GetListOfFormats();
            int      filmSubId = filmId ?? -1;
            Screener scr       = new ScreenerRepository().GetScreener(filmSubId);

            if (scr == null)
            {
                scr = new Screener {
                    ScreenerId = -1, FormatId = -1, FilmSubmissionId = filmSubId, DurationMinutes = 0
                }
            }
            ;
            model.Screener = scr;
            model.Duration.NumberOfMinutes = scr.DurationMinutes ?? 0;

            return(View(model));
        }
Esempio n. 15
0
        public Screener AddScreener(Screener newScreener, List <int> selectedGenres, List <int> selectedAttributes, int userId)
        {
            int      screenerId;
            Screener screenerOld = GetScreener(newScreener.FilmSubmissionId);

            try
            {
                if (screenerOld == null)
                {
                    screenerOld = new Screener();
                    screenerOld.FilmSubmissionId      = newScreener.FilmSubmissionId;
                    screenerOld.ModifiedBy            = userId;
                    screenerOld.FormatId              = newScreener.FormatId;
                    screenerOld.PostScreeningActionId = newScreener.PostScreeningActionId;
                    screenerOld.DurationMinutes       = (newScreener.DurationMinutes ?? 0);
                    screenerOld.ModifiedDate          = DateTime.Now;

                    _context.Screeners.Add(screenerOld);
                }
                else
                {
                    screenerOld.FormatId              = newScreener.FormatId;
                    screenerOld.DurationMinutes       = newScreener.DurationMinutes;
                    screenerOld.PostScreeningActionId = newScreener.PostScreeningActionId;

                    screenerOld.ModifiedDate = DateTime.Now;
                    screenerOld.ModifiedBy   = userId;
                }
                _context.SaveChanges();

                screenerId = screenerOld.ScreenerId;

                // delete previous genres
                var prevGenres = _context.ScreenerGenres.Where(x => x.ScreenerId == screenerId);
                foreach (var pg in prevGenres)
                {
                    _context.ScreenerGenres.Remove(pg);
                }
                _context.SaveChanges();
                // add new genres
                if (selectedGenres != null)
                {
                    foreach (var sg in selectedGenres)
                    {
                        var gnr = _context.Genres.Find(sg);
                        _context.ScreenerGenres.Add(new ScreenerGenre {
                            ScreenerId = screenerId, GenreId = gnr.GenreId
                        });
                        _context.SaveChanges();
                    }
                }

                //// delete previous attributes
                var prevAttr = _context.ScreenerAttributes.Where(x => x.ScreenerId == screenerId);
                foreach (var pa in prevAttr)
                {
                    _context.ScreenerAttributes.Remove(pa);
                }
                _context.SaveChanges();

                // add new attributes
                if (selectedAttributes != null)
                {
                    foreach (var sa in selectedAttributes)
                    {
                        var attr = _context.Attributes.Find(sa);
                        _context.ScreenerAttributes.Add(new ScreenerAttribute {
                            ScreenerId = screenerId, AttributeId = attr.AttributeId
                        });
                        _context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message + ", " + ex.InnerException.InnerException.Message;
            }
            return(screenerOld);
        }
Esempio n. 16
0
        public async Task <List <ScreenerResponse> > GetScreenerResponse(Screener data)
        {
            var result = await PostToApi <List <ScreenerResponse> >(data, $"{_stockApiPath}/FilterStocksForScreenerPlus", Method.POST);

            return(result.Data);
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            Bitmap a = new Bitmap("./images/A.png");
            Bitmap b = new Bitmap("./images/B.png");
            Bitmap c = new Bitmap("./images/C.png");
            Bitmap d = new Bitmap("./images/D.png");
            Bitmap e = new Bitmap("./images/D.png");


            // Test cases enabling
            bool testBitmapEditor          = true;
            bool testBitmapDifference      = true;
            bool testBitmapComparator      = true;
            bool testBitmapBatchComparator = true;
            bool testIntegration           = true;


            // CLASS BitmapEditor
            if (testBitmapEditor)
            {
                // BitmapEditor.SetPixel()
                // Bitmap <-> BitmapEditor implicit conversions
                {
                    Bitmap       bitmap       = new Bitmap(4, 4, PixelFormat.Format24bppRgb);
                    BitmapEditor bitmapEditor = bitmap;
                    bitmapEditor.SetPixel(0, 0, Color.Cyan);
                    bitmapEditor.SetPixel(1, 1, Color.Cyan);
                    bitmapEditor.SetPixel(2, 2, Color.Cyan);
                    bitmap = bitmapEditor;
                    bitmap.Save("./bitmapEditorConversions1.png");
                }


                // BitmapEditor.SetPixel()
                // Bitmap <-> BitmapEditor explicit conversions
                {
                    BitmapEditor bitmapEditor = new BitmapEditor(new Bitmap(a));
                    bitmapEditor.SetPixel(0, 0, Color.Cyan);
                    bitmapEditor.SetPixel(1, 1, Color.Cyan);
                    bitmapEditor.SetPixel(2, 2, Color.Cyan);
                    bitmapEditor.SetPixel(3, 3, Color.Cyan);
                    bitmapEditor.SetPixel(4, 4, Color.Cyan);
                    bitmapEditor.SetPixel(5, 5, Color.Cyan);
                    bitmapEditor.SetPixel(6, 6, Color.Cyan);
                    bitmapEditor.SetPixel(100, 100, Color.Cyan);
                    bitmapEditor.SetPixel(101, 100, Color.Cyan);
                    bitmapEditor.SetPixel(102, 100, Color.Cyan);
                    bitmapEditor.SetPixel(103, 100, Color.Cyan);
                    ((Bitmap)(bitmapEditor)).Save("./bitmapEditorConversions2.png");
                }
            }


            // CLASS BitmapDifference TEST
            if (testBitmapDifference)
            {
                {
                    // BitmapDifference from Bitmap
                    // BitmapDifference.SetPixel() - marking pixels as different
                    // BitmapDifference.GetBitmapDifferenceImage

                    BitmapDifference bitmapDifferenceA = new BitmapDifference(a);
                    bitmapDifferenceA.SetPixel(100, 100, true);
                    bitmapDifferenceA.SetPixel(100, 101, true);
                    bitmapDifferenceA.SetPixel(100, 102, true);
                    bitmapDifferenceA.SetPixel(100, 103, true);
                    bitmapDifferenceA.GetBitmapDifferenceImage().Save("./bitmapDifferenceImage.png");


                    // BitmapDifference from Bitmap
                    // BitmapDifference.AddMask()
                    // BitmapDifference.GetBitmapMaskedImage()

                    BitmapDifference bitmapDifferenceB = new BitmapDifference(a);
                    bitmapDifferenceB.AddMask(bitmapDifferenceA.GetBitmapDifferenceImage());
                    bitmapDifferenceB.GetBitmapMaskedImage().Save("./bitmapDifferenceMaskedImage.png");
                }
            }


            // CLASS BitmapComparator TEST
            if (testBitmapComparator)
            {
                BitmapComparator bitmapComparator = new BitmapComparator(a, b);
                bitmapComparator.GetBitmapDifferenceImage().Save("./bitmapComparatorDiffImg.png");
            }


            // CLASS BitmapBatchComparator TEST
            if (testBitmapBatchComparator)
            {
                BitmapBatch bitmapBatch = new BitmapBatch();
                bitmapBatch.Add(a);
                bitmapBatch.Add(b);
                bitmapBatch.Add(c);
                bitmapBatch.Add(d);
                bitmapBatch.Add(e);
                BitmapBatchComparator bitmapBatchComparator = new BitmapBatchComparator(bitmapBatch);
                bitmapBatchComparator.GetBitmapDifferenceImage().Save("./bitmapBatchComparatorDiffImg.png");
            }


            // CLASS integration TEST
            if (testIntegration)
            {
                stopwatch.Restart();

                BitmapBatch bbb = new BitmapBatch();

                Console.WriteLine("A: " + stopwatch.ElapsedMilliseconds);

                bbb = Screener.GetScreenshotBatch(3000, 250);

                Console.WriteLine("B: " + stopwatch.ElapsedMilliseconds);

                BitmapBatchComparator bbcb = new BitmapBatchComparator(bbb);

                Console.WriteLine("C: " + stopwatch.ElapsedMilliseconds);

                bbcb.GetBitmapDifferenceImage().Save("./bitmapBatchDifference.png");

                Console.WriteLine("D: " + stopwatch.ElapsedMilliseconds);

                BitmapComparator ndnjjcd = new BitmapComparator(a, b);

                Console.WriteLine("E: " + stopwatch.ElapsedMilliseconds);
            }

            Console.WriteLine("Done.");
            Console.ReadKey();
        }
Esempio n. 18
0
        public void Download(IJobCancellationToken cancellationToken)
        {
            bool didFindAny = false;

            foreach (var screenerType in uow.ScreenerTypes.getToDownload())
            {
                if (screenerType.TimeInterval.Duration != TimeSpan.FromDays(1))
                {
                    screenerType.LastResult = "Only Daily Screeners are implemented so far";
                    //_log.LogError("Only Daily Screeners are implemented so far");
                    break;
                }

                DateTimeOffset?dateLookingFor =
                    screenerType?.BrokerInstrumentScreenerTypes.FirstOrDefault()?.BrokerInstrument.BrokerSymbol.Exchange
                    .LastCloseTime;
                if (dateLookingFor == null)
                {
                    screenerType.LastResult = "Keine Member / Exchange Close Time eingetragen";
                    break;
                }
                if (screenerType.Screeners.FirstOrDefault(s => s.TimeStamp.Date == dateLookingFor?.Date) != null)
                {
                    screenerType.LastResult = "Aktuellster Screener ist schon in DB";
                    continue;
                }
                var urlDate = screenerType.UseToday ? DateTimeOffset.Now : dateLookingFor;
                var url     = screenerType.URL.Replace("YYYY", urlDate?.Year.ToString("D"))
                              .Replace("/M/", "/" + urlDate?.Month.ToString("D") + "/")
                              .Replace("DATE", urlDate?.Date.ToString("ddMM"));
                var filename = screenerType.Path + "temp\\" + screenerType.Name + ".gif";
                var file     = new System.IO.FileInfo(filename);
                //_log.LogDebug(url + " => " + filename);
                MagickImage image;
                try
                {
                    file.Directory.Create();
                    using (var webclient = new WebClient()) webclient.DownloadFile(url, filename);
                    image = new MagickImage(file);
                }
                catch (Exception ex)
                {
                    //_log.LogError(ex, "Error on Downloading Screener");
                    screenerType.LastResult = ex.ToString();
                    break;
                }
                var signature = image.Signature;
                if (screenerType.LastHash == signature)
                {
                    screenerType.LastCheck = DateTime.Now;
                    continue;
                }
                screenerType.LastHash = signature;
                // if (VerifyColorSignature(screenerType, image) == false) break;

                string destFileName = screenerType.Path + dateLookingFor?.Year.ToString("0000") + "\\" +
                                      dateLookingFor?.Month.ToString("00") + "\\" +
                                      dateLookingFor?.Day.ToString("00") + "_" + screenerType.Name + ".gif";
                try
                {
                    var destFile = new FileInfo(destFileName);
                    destFile.Directory.Create();
                    if (File.Exists(destFileName))
                    {
                        File.Delete(destFileName);
                    }
                    file.MoveTo(destFileName);
                }
                catch (Exception ex)
                {
                    //_log.LogError(ex, "Error on saving screener in destfile");
                    screenerType.LastResult = ex.ToString();
                    break;
                }
                if (!uow.Screeners.ImageExists(destFileName))
                {
                    var newScreener = new Screener();
                    newScreener.ImageFile    = destFileName;
                    newScreener.TimeStamp    = (DateTimeOffset)dateLookingFor;
                    newScreener.ImageHash    = signature;
                    newScreener.ScreenerType = screenerType;
                    uow.Screeners.Add(newScreener);
                    image.Dispose();
                    didFindAny             = true;
                    screenerType.LastCheck = DateTime.Now;
                }
            }
            uow.Complete();
            if (didFindAny)
            {
                BackgroundJob.Enqueue <ScreenerParseScheduler>(x => x.Schedule(JobCancellationToken.Null));
            }
        }