예제 #1
0
        public void PredictCurrencyExchangeRate_ValidData_ShouldSucceed(int[] xVals, double[] yVals, int monthToPredict, double expectedValue)
        {
            // Act
            double actualValue = LinearRegression.PredictCurrencyExchangeRate(xVals, yVals, monthToPredict);

            // Assert
            Assert.Equal(expectedValue, actualValue);
        }
예제 #2
0
        public void PredictCurrencyExchangeRate_DifferentArrayLengths_ShouldFail(int[] xVals, double[] yVals, int monthToPredict)
        {
            // Act
            Action act = () => LinearRegression.PredictCurrencyExchangeRate(xVals, yVals, monthToPredict);

            // Assert
            Assert.Throws <ArgumentException>(act);
        }
예제 #3
0
        /// <summary>
        /// Predict currency exchange rate based on last year data.
        /// </summary>
        /// <param name="openExchangeAppID">A valid app ID from Open Exchange Rates</param>
        /// <param name="fromCurrency">Currency to exchange from (3-letter code)</param>
        /// <param name="toCurrency">Currency to exchange to (3-letter code)</param>
        /// <param name="dateToPredict">The date that needs to be predicted.</param>
        /// <returns></returns>
        public static double PredictCurrencyExchangeRate(string openExchangeAppID, string fromCurrency, string toCurrency, DateTime dateToPredict)
        {
            // Get last year rates
            var oxrHelper     = new OpenExchangeRates(openExchangeAppID);
            var lastYearRates = oxrHelper.GetYearlyRates(fromCurrency, toCurrency, dateToPredict.AddYears(-1));

            // Get predicted value
            double predictedValue = LinearRegression.PredictCurrencyExchangeRate(
                lastYearRates.Select(r => r.Key).ToArray(), lastYearRates.Select(r => r.Value).ToArray(), dateToPredict.Month);

            return(predictedValue);
        }