public Deal(Deal other) { stock = other.stock; analyzData = new AnalyzeData(other.analyzData); buy_date = other.buy_date; buy_price = other.buy_price; buy_shares = other.buy_shares; buy_money = other.buy_money; buy_poundage = other.buy_poundage; buy_total_money = other.buy_total_money; sell_date = other.sell_date; sell_price = other.sell_price; sell_low = other.sell_low; sell_money = other.sell_money; sell_poundage = other.sell_poundage; sell_total_money = other.sell_total_money; bonus = other.bonus; ESellReason = other.ESellReason; }
public int AddDeal(Deal deal) { if (deal.eType == Deal.EBuy) { shares += deal.buy_shares; //cur_price = deal.buy_price; cost_money += deal.buy_total_money; } else if (deal.eType == Deal.ESell) { if (shares_available < deal.sell_shares) { Utility.Assert("shares_available < deal.sell_shares"); return(EST.EST_ERROR); } shares -= deal.sell_shares; shares_available -= deal.sell_shares; //cur_price = deal.sell_price; cost_money -= deal.sell_total_money; } cost_money = Math.Round(cost_money, 2); return(EST.EST_OK); }
public void CalcDeal_HighFrequency(Stock stock, TickData tickData, Deal deal) { TrendData trend = stock.trend_day; StrategyData strategyData = trend.mStrategyData; //sell if (stock.position.shares_available > 0) { if (openPrice == 0) { openPrice = tickData.price; } if (tickData.price > highPrice) { highPrice = tickData.price; } double costPrice = stock.position.getCostPrice(); double diff = highPrice - costPrice; if (diff >= 0.03) { double sPrice = openPrice + Math.Floor(diff / 1.6 * 100) / 100; if (tickData.price < sPrice) { deal.sell_shares = stock.position.shares_available; deal.sell_price = tickData.price; deal.eType = Deal.ESell; } } //final wall /* * DateTime endDt = new DateTime(tickData.dt.Year, tickData.dt.Month, tickData.dt.Day, 14, 50, 0); * if (tickData.dt.Ticks > endDt.Ticks) * { * deal.sell_shares = stock.position.shares_available; * deal.sell_price = tickData.price; * deal.eType = Deal.ESell; * } */ } //buy if (stock.position.shares == 0) { if (tickData.price <= strategyData.ma5.low) { deal.buy_price = tickData.price; deal.buy_shares = deal.getBuyShares(StartMoney * 10); if (deal.buy_shares == 0) { return; } if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } }
public void CalcDeal_Add(Stock stock, TickData tickData, Deal deal) { TrendData trend = stock.trend_30m; StrategyData strategyData = trend.mStrategyData; if (times == 0) { if (strategyData.ma10.ma == 0) { return; } if (trend.mPartData.close > strategyData.ma10.ma && tickData.price < strategyData.ma10.ma) { deal.buy_shares = StartShares; deal.buy_price = tickData.price; if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } else if (times > 0) { if (tickData.price > stock.position.getCostPrice() * SellPriceRate) { if (stock.position.shares_available != stock.position.shares) { return; } deal.sell_shares = stock.position.shares; deal.sell_price = tickData.price; //if (deal.sell_shares > stock.position.shares_available) return; deal.eType = Deal.ESell; } else if (tickData.price < stock.position.getCostPrice() * BuyPriceRate) { //EarnMoney = sMoney1 - bMoney1 = sMoney2 - bMoney1 - bMoney2; //sMoney1 = sMoney2 - bMoney2; //sPrice1*bShares1 = sPrice2*(bShares1+bShares2) - bPrice2*bShares2; //sPrice1 = bPrice1*SellPriceRate; //bPrice2 = bPrice1*BuyPriceRate; //(sPrice2-bPrice2)*bShares2 = (sPrice1-sPrice2)*bShares1 //bShares2 = bShares1 * (sPrice1-sPrice2) / (sPrice2-bPrice2) //if (times == 10) { return; } deal.buy_price = tickData.price; double bPrice1 = stock.position.getCostPrice(); double bPrice2 = deal.buy_price; double sPrice1 = sellPrice1; double sPrice2 = bPrice2 * SellPriceRate; double bShares1 = stock.position.shares; double denominator = sPrice1 - sPrice2; double numerator = sPrice2 - bPrice2; double x = denominator / numerator * bShares1; x = Math.Ceiling(x / 100) * 100; deal.buy_shares = Convert.ToInt32(x); if (deal.buy_shares == 0) { return; } if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } }
public void CalcDeal_Multi(Stock stock, TickData tickData, Deal deal) { TrendData trend = stock.trend_30m; StrategyData strategyData = trend.mStrategyData; if (times == 0) { if (strategyData.ma10.ma == 0) { return; } if (trend.mPartData.close < strategyData.ma10.ma && tickData.price > strategyData.ma10.ma) { deal.buy_shares = StartShares; deal.buy_price = tickData.price; if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } else if (times > 0) { if (tickData.price > stock.position.getCostPrice() * SellPriceRate) { if (stock.position.shares_available != stock.position.shares) { return; } deal.sell_shares = stock.position.shares; deal.sell_price = tickData.price; //if (deal.sell_shares > stock.position.shares_available) return; deal.eType = Deal.ESell; } else if (tickData.price < stock.position.getCostPrice() * BuyPriceRate) { //EarnRate = 1.01; //PriceRate = 0.02; //SellPriceRate = 1 + PriceRate; //bPrice2 = tickData.price; //SellPrice = bPrice2 * SellPriceRate; //CostMoney * EarnRate = SellMoney; //(bPrice1*bShares1 + bPrice2*bShares2)*EarnRate = SellPrice*TotalShares; //Mid = SellPrice / EarnRate; //bPrice1*bShares1 + bPrice2*bShares2 = Mid*bShares1 + Mid*bShares2; //bShares2*(bPrice2 - Mid) = bShares1*(Mid - bPrice1); //bShares2 = bShares1*(Mid - bPrice1) / (bPrice2 - Mid); if (times == TopTimes) { return; } deal.buy_price = tickData.price; double bPrice1 = stock.position.getCostPrice(); double bPrice2 = deal.buy_price; double sellPrice = bPrice2 * SellPriceRate; double mid = sellPrice / (1 + EarnRate); double denominator = mid - stock.position.getCostPrice(); double numerator = deal.buy_price - mid; double x = denominator / numerator * stock.position.shares; x = Math.Ceiling(x / 100) * 100; deal.buy_shares = Convert.ToInt32(x); if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } }
public void CalcDeal(Stock stock, TickData tickData, Deal deal) { CalcDeal_MACD(stock, tickData, deal); }