Exemple #1
0
        public static void Main(string[] args)
        {
            int i = 3;

            Console.WriteLine("Operation on dataset: Item ({0})...", Constants.id[i]);
            //get initial data from files
            var RawData = DataPreparer.Splicer(i);

            Console.WriteLine("Getting data from files");
            //subset length, total set size is 4*n (buy/sell quant, buy/sell price)
            //trim dataset to n before singleton implemented!
            int n = 4000;

            Console.WriteLine("trimmng datset...");
            DataPreparer.Trimmer(RawData, n);
            //get item specific data for raw dataset as a singleton class
            Console.WriteLine("Getting item...");
            Constants.Item    item = Constants.Item.GetItem(RawData, n);
            Constants.RawData Data = Constants.Item.GetRawData();
            //standardised dataset as well as weighted and standardised weighted data
            Console.WriteLine("Standardising dataset");
            Constants.StrdData strdData = DataPreparer.Z_Score(Data);
            //LSR fitting solutions to each set (standardised & non-standardised)
            Console.WriteLine("Fitting function parameters");
            double[,] FitEq     = FittingFunctions.FitLin(Data, n);
            double[,] StrdFitEq = FittingFunctions.StrdFitLin(strdData, n);
            Constants.DataInfo Info = DataPreparer.DataInfo();
            Console.WriteLine("Getting model information");
            double[] Corrs = ModelInfo.CorrCoeff(Data, Info);
            //Get prediction lists and convert to List<int> for StrdDev function
            var        _DemPreds = FittingFunctions.Predictor(Data.BuyPrice, FitEq[0, 0], FitEq[1, 0]);
            List <int> DemPreds  = _DemPreds.Select(x => (int)x).ToList();
            var        _SupPreds = FittingFunctions.Predictor(Data.SellPrice, FitEq[0, 1], FitEq[1, 1]);
            List <int> SupPreds  = _SupPreds.Select(x => (int)x).ToList();

            //Standard deviations of data, standard deviations of predicted data & correlations
            double[] FitData =
            {
                ModelInfo.StrdDev(Data.SellQuantity, Info.SellQuantInfo, n),
                ModelInfo.StrdDev(Data.BuyQuantity,  Info.BuyQuantInfo,  n),
                ModelInfo.StrdDev(DemPreds,          Info.BuyQuantInfo,  n),
                ModelInfo.StrdDev(SupPreds,          Info.BuyQuantInfo,  n),
                ModelInfo.RMSE(FitEq[2,                              0], n),ModelInfo.RMSE(FitEq[2,1], n),
                Corrs[0],                            Corrs[1]
            };
            Console.WriteLine("Printing results to files...");
            DataWriter.FileMaker(Info, i, FitEq, StrdFitEq, FitData);
            Console.Write("Check the desktop!");
            Console.ReadLine();
        }
Exemple #2
0
        /// <summary>
        /// Fits a line in a univariate analysis to data
        /// </summary>
        /// <param name="data">Input</param>
        /// <param name="n">Range of Input</param>
        /// <returns>Fit Param's, first column is gradients</returns>
        public static double[,] FitLin(Constants.RawData data, int n)
        {
            //S(p)=BuyQuantity = b + m*SellPrice
            //D(p)=SellQuantity = b - m*BuyPrice
            double[,] Params = new double[3, 2];
            var BQuant = data.BuyQuantity;
            var BPrice = data.BuyPrice;
            var SQuant = data.SellQuantity;
            var SPrice = data.SellPrice;

            //array location 0, 0 is mean value
            var InfoObject = DataPreparer.DataInfo();
            var BPMean     = (double)InfoObject.BuyPriceInfo[0, 0];
            var BQMean     = (double)InfoObject.BuyQuantInfo[0, 0];
            var SPMean     = (double)InfoObject.SellPriceInfo[0, 0];
            var SQMean     = (double)InfoObject.SellQuantInfo[0, 0];

            //return B1/Grad for demand and supply
            var GradDem = GradSolver(BPrice, SQuant, n, BPMean, SQMean);
            var GradSup = GradSolver(SPrice, BQuant, n, SPMean, BQMean);
            //return B0/intercept for demand and supply
            var DemInt = IntSolver(GradDem, SQMean, BPMean);
            var SupInt = IntSolver(GradSup, BQMean, SPMean);
            //create predictions of data and add to predictions lists
            var PredDem = Predictor(BPrice, GradDem, DemInt);
            var PredSup = Predictor(SPrice, GradSup, SupInt);
            //return error on predicitons
            var DemErr = ErrorSolver(SQuant, PredDem);
            var SupErr = ErrorSolver(BQuant, PredSup);

            //add to Params and return
            Params[0, 0] = Math.Round(GradDem);
            Params[0, 1] = Math.Round(GradSup);
            Params[1, 0] = Math.Round(DemInt);
            Params[1, 1] = Math.Round(SupInt);
            Params[2, 0] = Math.Round(DemErr);
            Params[2, 1] = Math.Round(SupErr);
            Console.WriteLine(Params[2, 1]);
            return(Params);
        }