예제 #1
0
        static void Main(string[] args)
        {
            string path = "C:\\Users\\Тимофей\\Documents\\!ТИМА\\УНИВЕР\\!ПРЕДМЕТЫ\\Программирование\\КДЗ_2\\mtcars.csv";

            int[] arr = { 1, 2, 3 };
            //CSVProcessor processor = new CSVProcessor(path);
            //foreach (string str in processor)
            //{
            //    Console.WriteLine(str);
            //}

            //TypeConverter converter = TypeDescriptor.GetConverter(typeof(int));
            CarAttribute <double> attr = new CarAttribute <double>(-1.0, 15.0, "1,9");
            Car           car          = new Car();
            string        str          = "\"ccccccc RX4\",21,6,160,110,3.9,2.62,16.46,0,1,4,4";
            List <string> l            = str.Split(',').ToList <string>();

            //Console.WriteLine("13".T)
            car.SetFromStringList(l, CultureInfo.GetCultureInfo("en-US"));
            List <Car> cars = new List <Car>();

            cars.Add(car);
            CSVProcessor processor = new CSVProcessor(@"C:\Users\Тимофей\Documents\!ТИМА\УНИВЕР\!ПРЕДМЕТЫ\Программирование\КДЗ_2\new1.csv");
            bool         r         = processor.TrySaveRecords(cars);

            Console.WriteLine(r);
        }
예제 #2
0
 public void TestMethod1()
 {
     using (var sr = new StreamReader(@"Files\csvwitherrors.csv"))
     {
         var processor = new CSVProcessor <CSVRecord>();
         processor.Validate(sr);
     }
 }
예제 #3
0
        static void Main(string[] args)
        {
            // CSV Processor Test
            CSVProcessor          csvProcessor = new CSVProcessor(TestCSVFilePath);
            List <List <string> > stringTable  = csvProcessor.GetStringTable();
            List <Credential>     credentials  = csvProcessor.ParseCredentialsFromFile(CSVProcessor.CSVFileFormat.KeePass, stringTable).ToList();

            // JSON Processor Test
            JSONProcessor     jsonProcessor = new JSONProcessor(TestJSONFilePath);
            List <Credential> credentials1  = jsonProcessor.ParseCredentialsFromFile().ToList();
        }
예제 #4
0
        private void buttonImportFile_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = "C:\\";
                openFileDialog.Filter           = "Dashlane-Files (*.json)|*.json|KeePass-Files (*.csv)|*.csv";
                openFileDialog.FilterIndex      = 1;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string            filePath      = openFileDialog.FileName;
                    List <Credential> userPasswords = new List <Credential>();

                    switch (openFileDialog.FilterIndex)
                    {
                    case 1:
                        JSONProcessor jsonProcessor = new JSONProcessor(filePath);
                        userPasswords = jsonProcessor.ParseCredentialsFromFile().ToList();
                        break;

                    case 2:
                        CSVProcessor csvProcessor = new CSVProcessor(filePath);
                        userPasswords = csvProcessor.
                                        ParseCredentialsFromFile(CSVProcessor.CSVFileFormat.KeePass, csvProcessor.GetStringTable()).ToList();
                        break;
                    }

                    if (userPasswords.Count == 0)
                    {
                        return;
                    }

                    foreach (Credential credential in userPasswords)
                    {
                        credentialQueue.Enqueue(credential);
                    }

                    byte[] command =
                    {
                        (byte)SerialCommandLimiter.COMM_BEGIN,
                        (byte)SerialCommand.COMM_GET_UNIQUE_ID,
                        (byte)SerialCommandLimiter.COMM_END
                    };
                    SerialSafeWrite(command, 3);
                }
            }
        }
예제 #5
0
        public void ProcessEmptyFile()
        {
            var mockLogger = new Mock <ILogger <CSVProcessor> >();

            CSVProcessor processor = new CSVProcessor(mockLogger.Object, this.emptyFileReader, this.config);

            processor.Init(new FoundCSVItem()
            {
                FilePath = (this.folderPath + "TOU_5.csv")
            });
            TaskResult result = null;

            Assert.DoesNotThrowAsync(async() => { result = await processor.ProcessAsync(); });
            Assert.True(result.LowerBoundsValues.Count == 0);
            Assert.True(result.UpperBoundsValues.Count == 0);
            Assert.True(result.Median == 0.0);
        }
예제 #6
0
        public void ProcessKnownResultFile3()
        {
            var mockLogger = new Mock <ILogger <CSVProcessor> >();

            CSVProcessor processor = new CSVProcessor(mockLogger.Object, this.emptyFileReader, this.config);

            processor.Init(new FoundCSVItem()
            {
                FilePath = (this.folderPath + "LP_BIG.csv")
            });
            TaskResult result = null;

            Assert.DoesNotThrowAsync(async() => { result = await processor.ProcessAsync(); });
            Assert.True(result.MedianLowerBound == 1.512);
            Assert.True(result.MedianUpperBound == 2.268);
            Assert.True(result.LowerBoundsValues.Count == 42);
            Assert.True(result.UpperBoundsValues.Count == 59);
            Assert.True(result.Median == 1.89);
        }
        public async Task Run()
        {
            Console.WriteLine("Updating VIX and SPX data");
            await ApplyUpdates(true, false);

            Console.WriteLine("Loading VIX file");
            vixPrices = CSVProcessor.ProcessVIXFile(VIXPath);

            Console.WriteLine("Connecting to alpaca trading API");
            alpacaTradingClient = Environments.Paper.GetAlpacaTradingClient(API_KEY, new SecretKey(API_SECRET));

            Console.WriteLine("Connecting to alpaca data API");
            alpacaDataClient = Environments.Paper.GetAlpacaDataClient(API_KEY, new SecretKey(API_SECRET));

            Console.WriteLine("Getting Market Calendars");
            var calendars = (await alpacaTradingClient.ListCalendarAsync(StartDate, EndDate)).ToList();

            Console.WriteLine("Writing header line in output file");
            using (StreamWriter w = File.CreateText(OutputPath))
            {
                w.WriteLine("Symbol, Date, StartTime, EndTime, PatternAlgFound, PatternVisFound, PosOpenTime, PosCloseTime, PosLong, PosReturn");
            }

            foreach (var calDate in calendars)
            {
                List <DateTime> startTimes     = new List <DateTime>();
                DateTime        loopTime       = calDate.TradingOpenTime.AddMinutes(15);
                TimeSpan        timeUntilClose = calDate.TradingCloseTime.Subtract(loopTime);
                while (timeUntilClose.TotalMinutes >= 30)
                {
                    startTimes.Add(loopTime);
                    loopTime       = loopTime.Add(new TimeSpan(0, 30, 0));
                    timeUntilClose = calDate.TradingCloseTime.Subtract(loopTime);
                }

                // High volatility only.
                if (!vixPrices.ContainsKey(calDate.TradingDate.ToString("yyyy-MM-dd")))
                {
                    continue;
                }
                if (vixPrices[calDate.TradingDate.ToString("yyyy-MM-dd")].Open < 28)
                {
                    continue;
                }

                foreach (DateTime dateTime in startTimes)
                {
                    var barSet = (await alpacaDataClient.GetBarSetAsync(symbols, TimeFrame.Minute, 60, true, dateTime.Subtract(TimeSpan.FromMinutes(14)), calDate.TradingCloseTime));


                    foreach (string sym in symbols)
                    {
                        if (!barSet.ContainsKey(sym))
                        {
                            continue;
                        }
                        var bars = barSet[sym].ToList();
                        // Pattern matching algorithm:
                        if (bars.Count < 44)
                        {
                            continue;
                        }

                        int  istr    = 14;
                        int  endtime = 14;
                        bool gr      = false;
                        bool found   = false;

                        for (int i = 14; i < 44; i++)
                        {
                            var price = bars[i];
                            if (price.Close - price.Open > 0)
                            {
                                if (gr)
                                {
                                    continue;
                                }

                                if (i - istr >= 4)
                                {
                                    found   = true;
                                    endtime = i;
                                    break;
                                }

                                istr = i;
                                gr   = true;
                            }
                            else
                            {
                                if (!gr)
                                {
                                    continue;
                                }

                                if (i - istr >= 6)
                                {
                                    found   = true;
                                    endtime = i;
                                    break;
                                }

                                istr = i;
                                gr   = false;
                            }
                        }

                        if (!found)
                        {
                            continue;
                        }

                        bool lng = !gr;

                        decimal entPrice = bars[endtime].Close;
                        decimal exPrice  = bars[43].Close;

                        decimal profit = lng ? exPrice - entPrice : entPrice - exPrice;
                        decimal pct    = profit / entPrice;

                        // End of Algorithm - Should be a pattern match now

                        List <PriceData> prices = new List <PriceData>();
                        for (int i = 0; i < 30; i++)
                        {
                            var price = bars[i + 14];
                            prices.Add(new PriceData(price.Time.ToString("HH:mm"), i, price.Open, price.Close, price.High, price.Low));
                        }

                        AlgoResult match = new AlgoResult(prices, sym, dateTime, dateTime.AddMinutes(30), true, res => {
                            //WriteToOutput(res);
                        }, dateTime.AddMinutes(14 + endtime), dateTime.AddMinutes(44), lng, pct);

                        ChartManager.SendToChartQueue(match);
                        match.PatternVisFound = true;
                        WriteToOutput(match);
                    }
                }
            }
            ChartManager.DoneProcessing();
        }