public bool BuyPolicy(StockEntity currentStockEntity, StockEntity lastBoughtStockEntity, StockEntity lastSoldStockEntity, List<StockEntity> sortedAllStockEntities) { if (currentStockEntity.Close == 0) { return false; } bool biasBuyDecesion = false; if (currentStockEntity.GetMA(20) == 0) { biasBuyDecesion = true; } else { double bias = (currentStockEntity.GetMA(5) - currentStockEntity.GetMA(20)) / currentStockEntity.GetMA(5); if (bias <= tooStrongTheashold && bias >= balenceThreshold) { biasBuyDecesion = true; } else if (bias < tooWeakThreshold) { biasBuyDecesion = true; } } return biasBuyDecesion; }
public bool SellPolicy(StockEntity currentStockEntity, StockEntity lastBoughtStockEntity, StockEntity lastSoldStockEntity, List<StockEntity> sortedAllStockEntities) { if (currentStockEntity.Close == 0) { return false; } bool biasSellDecesion = false; if (currentStockEntity.GetMA(20) != 0) { double bias = (currentStockEntity.GetMA(5) - currentStockEntity.GetMA(20)) / currentStockEntity.GetMA(5); if (bias > tooStrongTheashold) { biasSellDecesion = true; int index = sortedAllStockEntities.FindIndex(entity => entity.RowKey == currentStockEntity.RowKey); if (index > 1) { var lastStockEntity = sortedAllStockEntities[index - 1]; if ((currentStockEntity.Close - lastStockEntity.Close) / lastStockEntity.Close > 0.05) { Console.WriteLine("Stock is too strong, ignore sell decesion."); biasSellDecesion = false; } } } else if (bias < balenceThreshold && bias >= tooWeakThreshold) { biasSellDecesion = true; } } return biasSellDecesion; }
public static bool PriceBelowLast5IfCloseToMA5(StockEntity stockEntity, List<StockEntity> sortedStockEntities, double deltaForPrice, double deltaForMA5) { if (stockEntity.Close < stockEntity.GetMA(5) * (1 + deltaForMA5)) { int index = sortedStockEntities.IndexOf(stockEntity); double lastMinPrice = double.MaxValue; for (int i = Math.Max(0, index - 5); i < index; i++) { if (sortedStockEntities[i].Close <= lastMinPrice) lastMinPrice = sortedStockEntities[i].Close; } if (stockEntity.Close < lastMinPrice * (1 - deltaForPrice)) { return true; } } else { return false; } return false; }
public static bool PriceAboveMA20(StockEntity stockEntity, double delta) { return stockEntity.Close > stockEntity.GetMA(20) * (1 + delta); }
public static bool MA5AboveMA20(StockEntity stockEntity, double delta) { return stockEntity.GetMA(5) > stockEntity.GetMA(20) * (1 + delta); }
public static bool PriceBelowMA20(StockEntity stockEntity, double delta) { return stockEntity.Close < stockEntity.GetMA(20) * (1 - delta); }
private StockEntity SellStock(StockEntity stockEntity, ref double money, ref double quantity) { Console.WriteLine("{0}: Sell at price {1}, MA5: {2}, MA20: {3}, Vol: {4}", stockEntity.Date.ToString("yyyy-MM-dd"), stockEntity.Close, stockEntity.GetMA(5), stockEntity.GetMA(20), stockEntity.Volume); money = quantity * stockEntity.Close; quantity = -1; return stockEntity; }