コード例 #1
0
        static void pricesForWeek()
        {
            /*
             * var dtToday = DateTime.Now;
             * var dayOfWeek = Convert.ToInt16(dtToday.DayOfWeek);
             * var sun = dtToday.AddDays(dayOfWeek * -1);
             * var sat = sun.AddDays(6);
             */

            // downloadMissingPriceFiles();

            // var dt = DateTime.Now;
            var dr  = DateTime.Now.ThisWeek();
            var dr1 = DateTime.Now.AddDays(-11).WeekOf();

            ForexiteFile fx = new ForexiteFile(DateTime.Now.Previous(DayOfWeek.Saturday));

            dr = DateTime.Now.PreviousWeek();
            ForexPrices fxp = new ForexPrices();

            foreach (var dt in dr)
            {
                fxp.PriceRecords.AddRange(fx.GetForexPrices(dt).PriceRecords);
            }

            int t = 0;

            // fx.DownloadFile();
            var csv = fxp.SymbolTimeStats.ToCsv(true);

            File.WriteAllLines("symbolTimeStats.csv", csv);

            int u = 0;
        }
コード例 #2
0
        static void splitSymbols()
        {
            var files            = Directory.GetFiles(appConfig.ZipPath, "*.zip").ToList();
            var symbolPricesList = new List <ForexSymbolPrices>();

            foreach (var file in files)
            {
                var finfo = new FileInfo(file);

                var recs = new List <ForexPriceRecord>().UnzipPrices(file);
                recs = recs.OrderBy(r => r.Symbol).ThenBy(r => r.PriceDateTime).ToList();
                var symbols = recs.OrderBy(r => r.Symbol).Select(r => r.Symbol).Distinct();
                foreach (var symbol in symbols)
                {
                    var symbolPrices = new ForexSymbolPrices();
                    symbolPrices.Symbol = symbol;
                    symbolPrices.Prices = recs.Where(r => r.Symbol == symbol).ToList();
                    var fxp = new ForexPrices();
                    fxp.PriceRecords = recs;

                    int z = 2;
                    // symbolPricesList.Add(symbolPrices);
                }
                Console.WriteLine(finfo.Name);
            }
        }
コード例 #3
0
ファイル: Train.cs プロジェクト: mpvyard/forexai
        private static void SetOutputResult(int inputDimensionLocal, int offset, int numRecordLocal)
        {
            double[] priceHigh = ForexPrices.GetHigh(inputDimensionLocal, offset);
            double[] priceLow  = ForexPrices.GetLow(inputDimensionLocal, offset);
            double   diffSize  = 0.00133;

            if (priceHigh[inputDimensionLocal - (priceHigh.Length > Configuration.OutputIndex ? Configuration.OutputIndex : priceHigh.Length - 1)] -
                priceLow[inputDimensionLocal - 1] > diffSize)
            {
                outputSets[numRecordLocal][0] = 1;
                outputSets[numRecordLocal][1] = -1;
                class1++;
            }
            else if (priceHigh[inputDimensionLocal - (priceHigh.Length > Configuration.OutputIndex ? Configuration.OutputIndex : priceHigh.Length - 1)] -
                     priceLow[inputDimensionLocal - 1] < diffSize)
            {
                outputSets[numRecordLocal][0] = -1;
                outputSets[numRecordLocal][1] = 1;
                class2++;
            }
            else
            {
                outputSets[numRecordLocal][0] = -1;
                outputSets[numRecordLocal][1] = -1;
                class0++;
            }
        }
コード例 #4
0
        public ForexPrices GetForexPrices(DateTime dt, string symbol = "")
        {
            this.PricesDate = dt;
            var recs = this.GetPriceRecords(symbol);
            var fxp  = new ForexPrices(recs);

            return(fxp);
        }
コード例 #5
0
        public static async Task <IndicatorPrices> Load(this IndicatorPrices indicatorPrices, string country, string indicator)
        {
            var ntpIndicatorData = new NtpIndicatorData();

            List <IndicatorData> recs = new List <IndicatorData>();

            recs = await ntpIndicatorData.GetIndicatorsForCcyAndName("USD", "Non-Farm Employment Change");

            indicatorPrices           = new IndicatorPrices();
            indicatorPrices.Currency  = "USD";
            indicatorPrices.Indicator = "Non-Farm Employment Change";

            indicatorPrices.IndicatorDetails = (from r in recs
                                                select new IndicatorDetail
            {
                Actual = r.Actual,
                EventId = r.EventId,
                Forecast = r.Forecast,
                Id = r.Id,
                Previous = r.Previous,
                ReleaseDate = r.ReleaseDate,
                ReleaseDateTime = DateTime.Parse(r.ReleaseDate + " " + r.ReleaseTime).AddHours(6).AddMinutes(1),                                     // r.ReleaseDateTime,
                ReleaseTime = r.ReleaseTime
            }).ToList();;

            foreach (var rec in indicatorPrices.IndicatorDetails)
            {
                var fxp = new ForexPrices();
                fxp.Read(rec.ReleaseDateTime.Date);
                fxp.PriceRecords = fxp.PriceRecords
                                   .Where(r => r.PriceDateTime.TimeOfDay >= rec.ReleaseDateTime.TimeOfDay && r.PriceDateTime.TimeOfDay <= rec.ReleaseDateTime.AddMinutes(180).TimeOfDay)
                                   .ToList();

                foreach (var symbol in fxp.Symbols)
                {
                    IndicatorDetailPrices idp = new IndicatorDetailPrices();
                    idp.Symbol       = symbol;
                    idp.PricesDetail = (from r in fxp.PriceRecords where r.Symbol == symbol select new IndicatorDetailPricesDetail
                    {
                        Close = r.Close,
                        High = r.High,
                        Low = r.Low,
                        Open = r.Open,
                        PriceDateTime = r.PriceDateTime.DateTime
                    }).ToList();
                    rec.IndicatorDetailPrices.Add(idp);
                }

                // rec.ForexPrices.Add(fxp);

                Console.WriteLine(rec.ReleaseDateTime.Date);
            }
            return(indicatorPrices);
        }
コード例 #6
0
        public static void Read(this ForexPrices fxp, DateTime dt, string symbol = "")
        {
            // fxp = new ForexPrices();
            var zipDir = @"I:\\ForexData\\Forexite\\ARCHIVE_PRICES\\ZIP_ORIGINAL";
            var fname  = FileUtils.DateToFxiFileName(dt, "zip");
            var fpath  = Path.Combine(zipDir, fname);

            if (string.IsNullOrEmpty(symbol))
            {
                fxp.PriceRecords = fxp.PriceRecords.UnzipPrices(fpath).ToList();
            }
            else
            {
                fxp.PriceRecords = fxp.PriceRecords.UnzipPrices(fpath, symbol).ToList();
            }
            // return fxp;
        }
コード例 #7
0
        static async Task getIndicators()
        {
            var ntpIndicatorData      = new NtpIndicatorData();
            List <IndicatorData> recs = await ntpIndicatorData.GetIndicatorsForCcyAndName("USD", "Non-Farm Employment Change");

            List <string> csvList  = new List <string>();
            List <string> csvStats = new List <string>();

            csvStats.Add(ForexTimePeriodStats.ToTimeStatCsvHeader());
            foreach (var rec in recs)
            {
                // Console.WriteLine(rec.ReleaseDateTime.AddHours(2));
                var dt = DateTime.Parse(rec.ReleaseDate + " " + rec.ReleaseTime).AddHours(6).AddMinutes(1);
                rec.ReleaseDateTime = dt;
                Console.WriteLine(rec.ReleaseDateTime);

                var fxp = new ForexPrices();
                try
                {
                    fxp.Read(dt, "EURUSD");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }
                fxp.PriceRecords = fxp.PriceRecords
                                   .Where(r => r.PriceDateTime.TimeOfDay >= rec.ReleaseDateTime.TimeOfDay && r.PriceDateTime.TimeOfDay <= rec.ReleaseDateTime.AddMinutes(180).TimeOfDay)
                                   .ToList();
                Console.WriteLine("price recs: " + fxp.PriceRecords.Count());
                Console.WriteLine("");
                //csvList.AddRange(fxp.PriceRecords.ToCsvListOHLC());
                //csvList.Add("");
                if (fxp.SymbolTimeStats.Count() > 0)
                {
                    csvStats.AddRange(fxp.SymbolTimeStats.ToCsv());
                }
                else
                {
                    Console.WriteLine("no recs");
                }
            }

            // File.WriteAllLines("nfpList.csv", csvList.ToArray());
            File.WriteAllLines("nfpListTimeStats.csv", csvStats.ToArray());
        }
コード例 #8
0
        static void jsonPriceTests()
        {
            DateTime dt = new DateTime(2019, 7, 5);

            var fxp = new ForexPrices();

            fxp.Read(dt);
            fxp.PriceRecords = fxp.PriceRecords
                               .Where(r => r.PriceDateTime.TimeOfDay >= new TimeSpan(14, 31, 0) && r.PriceDateTime.TimeOfDay <= new TimeSpan(15, 31, 0))
                               .ToList();

            var json          = fxp.ToJson();
            var jsonTimeStats = fxp.SymbolTimeStats.ToJson();
            var jsonPrices    = fxp.PriceRecords.ToJson();

            // File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "fxp.json"), json);
            // File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "fxpTimeStats.json"), jsonTimeStats);
            File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "fxpPriceRecs.json"), jsonPrices);

            fxp.PriceRecords.ToCsvFileOHLC(Path.Combine(Directory.GetCurrentDirectory(), "fxp.csv"), true);
            Console.WriteLine(fxp.PriceRecords.Count());
        }
コード例 #9
0
        public static DataSet ToDataSet(this ForexPrices prices)
        {
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            try
            {
                ds.Tables[0].Columns.Add("dblPrevious", System.Type.GetType("System.Double"));
                ds.Tables[0].Columns.Add("dblActual", System.Type.GetType("System.Double"));
                ds.Tables[0].Columns.Add("dblConsensus", System.Type.GetType("System.Double"));
                ds.Tables[0].Columns.Add("dblDifference", System.Type.GetType("System.Double"));
                ds.Tables[0].Columns.Add("dblRevised", System.Type.GetType("System.Double"));
                ds.Tables[0].Columns.Add("isSelected", System.Type.GetType("System.Boolean"));

                prices.PriceRecords.ForEach(r =>
                {
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ds);
        }
コード例 #10
0
 public static string ToJson(this ForexPrices fxp)
 {
     return(JsonConvert.SerializeObject(fxp, Formatting.Indented));
 }
コード例 #11
0
        /*░░ ♡ ▄▀▀▀▄░░░
         * ▄███▀░◐░░░▌░░░░░░░
         * ░░░░▌░░░░░▐░░░░░░░
         * ░░░░▐░░░░░▐░░░░░░░
         * ░░░░▌░░░░░▐▄▄░░░░░
         * ░░░░▌░░░░▄▀▒▒▀▀▀▀▄
         * ░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
         * ░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
         * ░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
         * ░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄ <<<---.
         * ░░░░░░░░░░░▌▌░▌▌░░░░░
         * ░░░░░░░░░░░▌▌░▌▌░░░░░
         * ░░░░░░░░░▄▄▌▌▄▌▌░░░░░*/
        public FunctionParameters(MethodInfo methodInfo, int numdata, int offset)
        {
            NumData       = numdata;
            Offset        = offset;
            parametersMap = new List <string>();

            // DumpParams(methodInfo);
            Arguments = new object[methodInfo.GetParameters().Length];

            // debug($"function method {methodInfo.Name} offset {offset} numdata {NumData} randomSeed {randomSeed}");
            foreach (ParameterInfo param in methodInfo.GetParameters())
            {
                string paramComment = string.Empty;
                switch (param.Name)
                {
                case "optInVFactor":
                    Arguments[ParamIndex] = 0;
                    break;

                case "outMACDSignal":
                    Arguments[ParamIndex] = 0;
                    break;

                case "outMACDHist":
                    Arguments[ParamIndex] = 0;
                    break;

                case "outMin":
                    Arguments[ParamIndex] = 0;
                    break;

                case "optInNbDevUp":
                    Arguments[ParamIndex] = 0.0;
                    break;

                case "outMACD":
                    Arguments[ParamIndex] = 0.0;
                    break;

                case "outLeadSine":
                    Arguments[ParamIndex] = 0.0;
                    break;

                case "outSine":
                    Arguments[ParamIndex] = 0.0;
                    break;

                case "optInMinPeriod":
                case "optInMaxPeriod":
                case "optInSignalPeriod":
                    Arguments[ParamIndex] = MaTypeGen.GetRandom();
                    paramComment          = $"MaTypeGen";

                    // debug($"{param.Name} optInSignalPeriod=" + arguments[paramIndex]);
                    break;

                case "optInMAType":
                    Arguments[ParamIndex] = MaTypeGen.GetRandom();
                    paramComment          = $"MaTypeGen";

                    // debug($"{param.Name} optInMAType=" + arguments[paramIndex]);
                    break;

                case "optInNbDev":
                    Arguments[ParamIndex] = 0.0;
                    break;

                case "inReal0":
                case "inReal1":
                case "inReal":
                    var index = XRandom.next(3);
                    switch (index)
                    {
                    case 0:
                        Arguments[ParamIndex] = ForexPrices.GetOpen(NumData, Offset);
                        paramComment          = $"Open {NumData}";
                        break;

                    case 1:
                        Arguments[ParamIndex] = ForexPrices.GetClose(numdata, Offset);
                        paramComment          = $"Close {NumData}";
                        break;

                    case 2:
                        Arguments[ParamIndex] = ForexPrices.GetHigh(NumData, Offset);
                        paramComment          = $"High {NumData}";
                        break;

                    case 3:
                        Arguments[ParamIndex] = ForexPrices.GetLow(NumData, Offset);
                        paramComment          = $"Low {NumData}";
                        break;
                    }

                    // debug($"real {param.Name}[0]: " + ((double[])Arguments[ParamIndex])[0]);
                    break;

                case "optInMaximum":
                    Arguments[ParamIndex] = 0.0;
                    break;

                case "optInSlowD_MAType":
                case "optInFastD_MAType":
                case "optInSlowK_MAType":
                    Arguments[ParamIndex] = MaTypeGen.GetRandom();
                    paramComment          = $"MaTypeGen";

                    // debug($"{param.Name} optMAtype=" + arguments[paramIndex]);
                    break;

                case "optInAccelerationShort":
                case "optInAccelerationMaxShort":
                case "optInAccelerationInitShort":
                case "optInAccelerationMaxLong":
                case "optInAccelerationLong":
                case "optInAccelerationInitLong":
                case "optInAcceleration":
                    Arguments[ParamIndex] = 0.0;
                    break;

                case "optInOffsetOnReverse":
                    Arguments[ParamIndex] = 0;
                    break;

                case "optInSlowK_Period":
                case "optInFastK_Period":
                case "optInSlowD_Period":
                case "optInFastD_Period":
                    Arguments[ParamIndex] = MaGen.GetRandom(NumData);
                    paramComment          = $"MaTypeGen";
                    break;

                case "optInSlowPeriod":
                    Arguments[ParamIndex] = XRandom.next(Convert.ToInt32(NumData / 2) + 1, NumData - 1);
                    break;

                case "optInFastPeriod":
                    Arguments[ParamIndex] = MaGen.GetRandom(Convert.ToInt32(NumData / 2));
                    break;

                case "optInTimePeriod":
                    Arguments[ParamIndex] = 2;
                    break;

                case "optInTimePeriod1":
                case "optInTimePeriod3":
                case "optInTimePeriod2":
                    Arguments[ParamIndex] = MaGen.GetRandom(NumData);
                    break;

                case "optInPenetration":
                    Arguments[ParamIndex] = 0;
                    break;

                case "optInStartValue":
                    Arguments[ParamIndex] = 0;
                    break;

                case "startIdx":
                    Arguments[ParamIndex] = 0;
                    break;

                case "endIdx":
                    Arguments[ParamIndex] = NumData - 1;
                    break;

                case "inOpen":
                    Arguments[ParamIndex] = ForexPrices.GetOpen(NumData, Offset);
                    paramComment          = $"Open {NumData}";
                    break;

                case "inHigh":
                    Arguments[ParamIndex] = ForexPrices.GetHigh(NumData, Offset);
                    paramComment          = $"High {NumData}";
                    break;

                case "inLow":
                    Arguments[ParamIndex] = ForexPrices.GetLow(NumData, Offset);
                    paramComment          = $"Low {NumData}";
                    break;

                case "inClose":
                    Arguments[ParamIndex] = ForexPrices.GetClose(NumData, Offset);
                    paramComment          = $"Close {NumData}";
                    break;

                case "inVolume":
                    Arguments[ParamIndex] = ForexPrices.GetVolume(NumData, Offset);
                    paramComment          = $"Volume {NumData}";
                    break;

                case "outBegIdx":
                    Arguments[ParamIndex] = this.OutBegIdx;
                    break;

                case "outNBElement":
                    Arguments[ParamIndex] = OutNbElement;
                    OutNbElement          = ParamIndex;
                    break;

                case "outInteger":
                    Arguments[ParamIndex] = new int[NumData];
                    OutIndex = ParamIndex;
                    break;

                case "outReal":
                    Arguments[ParamIndex] = new double[NumData];
                    OutIndex = ParamIndex;
                    break;

                case "outAroonUp":
                    Arguments[ParamIndex] = new double[1000];
                    break;

                case "outAroonDown":
                    Arguments[ParamIndex] = new double[1000];
                    break;

                case "outSlowD":
                case "outSlowK":
                case "outFastD":
                case "outFastK":
                    Arguments[ParamIndex] = new double[1000];
                    break;

                default:
                    Tools.debug($"nothing found for {param.Name}");
                    break;
                }

                parametersMap.Add($"{ParamIndex}|{param.Name}|{Arguments[ParamIndex]}|{paramComment}");
                ParamIndex++;
            }
        }