public double getExpectancy(int scenarioId) { CommisionFactory commFactory = new CommisionFactory(); Comission comm = commFactory.GetCommission(ConfigurationManager.AppSettings["CommissionType"]); GameManager gm = new GameManager(false); gm.relevantScenario = scenarioId; AgentsFactory factory = new AgentsFactory(); InvestAgent agent = factory.CreateAgent(ConfigurationManager.AppSettings["AgentType"], gm, comm, false); int startMoney = int.Parse(ConfigurationManager.AppSettings["InitialMoneyAmount"]); double currMoney = startMoney; History hist = new History(); int roundNum = 1; foreach (KeyValuePair <int, ScenarioTurn> p in _turns) { InvestmentData data = agent.Invest((float)currMoney, hist, p.Key); hist.addRecord(new HistoryRecord(data, currMoney, data.endMoney, roundNum)); currMoney = data.endMoney; ++roundNum; } return(currMoney); }
public HistoryRecord(InvestmentData investmentData, double prevMoney, double currMoney, int roundNum) { _investmentData = investmentData; _prevMoney = prevMoney; _currMoney = currMoney; _roundNum = roundNum; }
override public InvestmentData Invest(double money, History hist, int roundNum) { checkIfInitilized(); InvestmentData result = makeInvestment(money, roundNum, optimalStock, _isTrain); return(result); }
public override InvestmentData Invest(double money, History hist, int roundNum) { checkIfInitilized(); int stockId = getStockId(money, hist, roundNum); DebugFileWriter.writeToFile("output.txt", stockId.ToString()); InvestmentData result = makeInvestment(money, roundNum, stockId, _isTrain); return(result); }
public void RecordInvestment(InvestmentData data, double beforeMoney, double AfterMoney, int roundNum, int scernarioNum, int stockId, bool isTrain) { int isGain = 0; int training = 0; if (data.earn > 0) { isGain = 1; } else if (data.earn < 0) { isGain = -1; } training = isTrain ? 1 : 0; List <DALType> record = new List <DALType>(); record.Add(new DALString(_user.user_id)); record.Add(new DALInt(roundNum)); record.Add(new DALInt(scernarioNum)); record.Add(new DALInt(stockId)); record.Add(new DALDouble(beforeMoney)); record.Add(new DALDouble(data.investmentMoney)); record.Add(new DALDouble(data.earn * 100)); record.Add(new DALDouble(data.earnMoney)); record.Add(new DALDouble(data.commission_percent)); record.Add(new DALDouble(data.commission)); record.Add(new DALDouble(data.endMoney)); record.Add(new DALDouble(AfterMoney)); record.Add(new DALInt(isGain)); record.Add(new DALInt(training)); record.Add(new DALString(DateTime.UtcNow.ToString())); record.Add(new DALString(ConfigurationManager.AppSettings["ExperimentID"])); List <List <DALType> > records = new List <List <DALType> >(); records.Add(record); dal.writeData(investmentsTable, records); }
private void doInvestment(float moneyInput, bool isTrain) { double money = float.Parse(Session["Money"].ToString()); GameManager gm = (GameManager)Session["GM"]; User user = (User)Session["User"]; int roundNum = isTrain ? (int)Session["TrainingRound"] : (int)Session["Round"]; CommisionFactory commFactory = new CommisionFactory(); Comission comm = commFactory.GetCommission(ConfigurationManager.AppSettings["CommissionType"]); AgentsFactory factory = new AgentsFactory(); InvestAgent a = factory.CreateAgent(ConfigurationManager.AppSettings["AgentType"], gm, comm, isTrain); InvestmentData investment_data = a.Invest(moneyInput, (History)Session["History"], roundNum); double AfterMoney = floor2(money - moneyInput + investment_data.endMoney); Session["Money"] = AfterMoney; History hist = (History)Session["History"]; hist.addRecord(new HistoryRecord(investment_data, money, AfterMoney, roundNum)); Session["History"] = hist; InvestmentsRecorder recorder = new InvestmentsRecorder(user); int scenarioNum = isTrain ? gm.relevantTrainingScenario : gm.relevantScenario; recorder.RecordInvestment(investment_data, money, AfterMoney, roundNum, scenarioNum, investment_data.stockId, isTrain); if (isTrain) { Session["TrainingRound"] = (int)Session["TrainingRound"] + 1; if ((int)Session["TrainingRound"] > (int)Session["MinTrainigRounds"]) { Session["isMinTrainingDone"] = 1; } } else { Session["Round"] = (int)Session["Round"] + 1; } MoneyInput.Text = ""; if (investment_data.investmentMoney == 0) { Session["InvestmentMessageInvestedMoney"] = "You invested $0."; Session["InvestmentMessageEarning"] = String.Format("The agent earned $0.", Session["Money"]); Session["InvestmentMessageCommission"] = String.Format("Commission of $0 has been taken from your investment.", Session["Money"]); Session["InvestmentMessageFinal"] = String.Format("You get back $0, so now you have ${0} in your account.", Session["Money"]); } else if (investment_data.earn > 0) { Session["InvestmentMessageInvestedMoney"] = String.Format("You invested ${0}.", investment_data.investmentMoney); Session["InvestmentMessageEarning"] = String.Format("The agent earned ${0} ({1}%).", floor2(investment_data.earnMoney), floor2(100 * investment_data.earn)); Session["InvestmentMessageCommission"] = String.Format("Commission of {0}% (${1}) has been taken from your investment.", floor2(investment_data.commission_percent), floor2(investment_data.commission)); Session["InvestmentMessageFinal"] = String.Format("You get back ${0}, so now you have ${1} in your account", floor2(investment_data.endMoney), Session["Money"]); } else if (investment_data.earn < 0) { Session["InvestmentMessageInvestedMoney"] = String.Format("You invested ${0}.", investment_data.investmentMoney); Session["InvestmentMessageEarning"] = String.Format("The agent lost ${0} ({1}%).", floor2(investment_data.earnMoney) * (-1), floor2(100 * investment_data.earn) * (-1)); Session["InvestmentMessageCommission"] = String.Format("Commission of {0}% (${1}) has been taken from your investment.", floor2(investment_data.commission_percent), floor2(investment_data.commission)); Session["InvestmentMessageFinal"] = String.Format("You get back ${0}, so now you have ${1} in your account", floor2(investment_data.endMoney), Session["Money"]); } else if (investment_data.earn == 0) { Session["InvestmentMessageInvestedMoney"] = String.Format("You invested ${0}.", investment_data.investmentMoney); Session["InvestmentMessageEarning"] = String.Format("The agent earned nothing ({0}%).", floor2(investment_data.earn) * 100); Session["InvestmentMessageCommission"] = String.Format("Commission of {0}% (${1}) has been taken from your investment.", floor2(investment_data.commission_percent), floor2(investment_data.commission)); Session["InvestmentMessageFinal"] = String.Format("You get back ${0}, so now you have ${1} in your account", floor2(investment_data.endMoney), Session["Money"]); } }