Summary description for DefaultValues
        private DefaultValues CreateAndInitialize(IDbConnection db, int count = 1)
        {
            db.DropAndCreateTable<DefaultValues>();
            db.GetLastSql().Print();

            DefaultValues firstRow = null;
            for (var i = 1; i <= count; i++)
            {
                var defaultValues = new DefaultValues { Id = i };
                db.Insert(defaultValues);

                var row = db.SingleById<DefaultValues>(1);
                row.PrintDump();
                Assert.That(row.DefaultInt, Is.EqualTo(1));
                Assert.That(row.DefaultIntNoDefault, Is.EqualTo(0));
                Assert.That(row.NDefaultInt, Is.EqualTo(1));
                Assert.That(row.DefaultDouble, Is.EqualTo(1.1).Within(.1d));
                Assert.That(row.NDefaultDouble, Is.EqualTo(1.1).Within(.1d));
                Assert.That(row.DefaultString, Is.EqualTo("String"));

                if (firstRow == null)
                    firstRow = row;
            }

            return firstRow;
        }
 public StockMarketSimulation(DefaultValues dv)
 {
     this.defaultValues = dv;
     StockMarketSimulation.simDay = 0;
     stopwatch = new Stopwatch();
     StopwatchTimes = new List<string>();
 }
 public static void Run()
 {
     // 初期化せずにフィールドを読んでみる(規定値が入っている)
     var a = new DefaultValues();
     Console.WriteLine(a.i);
     Console.WriteLine(a.x);
     Console.WriteLine((int)a.c); // '\0' (ヌル文字)は表示できないので数値化して表示
     Console.WriteLine(a.b); // False
     Console.WriteLine(a.s == null); // null は表示できないので比較で。True になる
 }
 private void createAgents(DefaultValues dv)
 {
     int agentNumber = dv.ternaAgentNumber + dv.randomAgentNumber + dv.rsAgentNumber + dv.raAgentNumber;
     for (int i = 0; i < agentNumber; i++)
     {
         if (i < dv.randomAgentNumber) AgentList.Add(new RandomAgent(i, dv));
         else if (i < dv.randomAgentNumber+dv.ternaAgentNumber) AgentList.Add(new TernaAgent(i, dv));
         else if (i < dv.randomAgentNumber+dv.ternaAgentNumber+dv.rsAgentNumber) AgentList.Add(new RiskSeekingAgent(i, dv));
         else if (i < dv.randomAgentNumber + dv.ternaAgentNumber + dv.rsAgentNumber + dv.raAgentNumber) AgentList.Add(new RiskAvoidingAgent(i, dv));
     }
 }
        private void agentPreferencesMenu_Click(object sender, EventArgs e)
        {
            AgentSettingsDialog dialog = new AgentSettingsDialog();
            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                agentValues = new DefaultValues(dialog.EpochNumber, dialog.NumberOfTernaAgents, dialog.NumberOfRandomAgents, dialog.NumberOfRiskSeekingAgents, dialog.NumberOfRiskAvoidingAgents, dialog.NumberOfStocks, dialog.Budget, dialog.MaxOrders, dialog.StopLoss, (float) dialog.ProbOfImitatingMarket,
                                                (float)dialog.ProbOfLocalImitation, (float) dialog.AsymmetricBuySellProb, (float)dialog.ProbBeforeOpening,
                                                (float) dialog.MinCorrection, (float)dialog.MaxCorrection, (float)dialog.FloorPrice, (float)dialog.AgentProbActBelowFloorPrice, dialog.MeanPriceHistoryLength,
                                                dialog.LocalHistoryLength, (float) dialog.AgentProbAdoptStopLoss, (float)dialog.MaxLossRate);
            }
        }
        public RandomAgent(int number, DefaultValues df)
        {
            this.number = number;
            this.maxOrderNumber = df.maxOrderNumber;

            this.minCorrectingCoefficient = df.minCorrectingCoefficient;
            this.maxCorrectingCoefficient = df.maxCorrectingCoefficient;

            this.budget = df.budget;
            this.budgetHistory = new List<float>();
            this.budgetHistory.Add(this.budget);
            this.ownedStocks = new Dictionary<int, int>();
            createStockInventory(df);
        }
        public Form1()
        {
            InitializeComponent();

            //create default values
            defaultValues = new defaultValues();
            defaultValues.days = 100;
            defaultValues.selectedStockNumber = 0;
            defaultValues.numberOfStocks = 5;

            //create stock manager
            stockManager = new StockManager();
            stockManager.loadRealDataStocks(defaultValues.numberOfStocks);

            agentValues = new DefaultValues();
        }
 public TernaAgent(int number, DefaultValues df)
 {
     this.number = number;
     this.maxOrderNumber = df.maxOrderNumber;
     this.stopLossInterval = df.stopLossInterval;
     this.probOfImitatingTheMarket = df.probOfImitatingTheMarket;
     this.probOfLocalImitation = df.probOfLocalImitation;
     this.asymmetricBuySellProb = df.asymmetricBuySellProb;
     this.agentProbToActBeforeOpening = df.agentProbToActBeforeOpening;
     this.minCorrectingCoefficient = df.minCorrectingCoefficient;
     this.maxCorrectingCoefficient = df.maxCorrectingCoefficient;
     this.floorP = df.floorP;
     this.agentProbToActBelowFloorPrice = df.agentProbToActBelowFloorPrice;
     this.meanPriceHistoryLength = df.meanPriceHistoryLength;
     this.localHistoryLength = df.localHistoryLength;
     this.agentProbToAdoptStopLoss = df.agentProbToAdoptStopLoss;
     this.maxLossRate = df.maxLossRate;
     this.budget = df.budget;
     this.budgetHistory = new List<float>();
     this.budgetHistory.Add(this.budget);
     this.ownedStocks = new Dictionary<int, int>();
     createStockInventory(df);
 }
			/// <summary>
			/// Ensure the operating context is in a valid state prior to using it.
			/// </summary>
			internal virtual void Validate()
			{
				if (this.Defaults == null)
					this.Defaults = new DefaultValues();
			}
 protected void createStockInventory(DefaultValues defaultValues)
 {
     for (int i = 0; i < defaultValues.stockNumber; i++)
     {
         this.ownedStocks.Add(i, 0);
     }
 }
Exemple #11
0
        /// <summary>
        /// Organize fields and values to set in a HybridDictionary
        /// </summary>
        /// <param name="defaultValues"></param>
        /// <returns></returns>
        private static DefaultValues[] PrepareDefaultValues(XmlNode defaultValues)
        {
            XmlNodeList nodes = defaultValues.ChildNodes;
            if (nodes.Count == 0)
                return null;

            DefaultValues[] arrDV = new DefaultValues[nodes.Count];
            DefaultValues dvObj;
            for (int i = 0; i < nodes.Count; i++)
            {
                dvObj = new DefaultValues();

                dvObj.ValueToCompare = (nodes[i].Attributes["value"] != null)? nodes[i].Attributes["value"].Value: null;

                if (nodes[i].Name == "equals")
                    dvObj.compareType = CompareType.EQUALS;
                else if (nodes[i].Name == "differs")
                    dvObj.compareType = CompareType.DIFFERS;
                else if (nodes[i].Name == "any")
                    dvObj.compareType = CompareType.NONE;

                if (nodes[i].ChildNodes.Count > 0)
                {
                    dvObj.FieldsToSet = new ArrayList();
                    foreach (XmlNode field in nodes[i].ChildNodes)
                    {
                        dvObj.FieldsToSet.Add(
                            new string[] {
                                field.Attributes["id"].Value,
                                field.Attributes["value"]  != null ? field.Attributes["value"].Value  : null,
                                (field.Attributes["required"] != null && field.Attributes["required"].Value.ToLower() == bool.TrueString.ToLower() ? bool.TrueString : bool.FalseString),
                                (field.Attributes["disabled"] != null && field.Attributes["disabled"].Value.ToLower() == bool.TrueString.ToLower() ? bool.TrueString : bool.FalseString),
                                (field.Attributes["invisible"] != null && field.Attributes["invisible"].Value.ToLower() == bool.TrueString.ToLower() ? bool.TrueString : bool.FalseString),
                                (field.Attributes["set"] != null ? field.Attributes["set"].Value:""),
                                null // this is the value to inspect and is set on DoManegedNodes
                            }
                        );
                    }
                }

                arrDV[i] = dvObj;
            }

            return arrDV;
        }
 public StockMarketSimulation()
 {
     DefaultValues defaultValues = new DefaultValues();
     stopwatch = new Stopwatch();
     StopwatchTimes = new List<string>();
 }
 public AgentManager(DefaultValues dv)
 {
     this.dv = dv;
     createAgents(dv);
 }