public static string ConvertDateForSql(System.DateTime date) { if ((date < System.Convert.ToDateTime("01.01.1753")) || (date.ToShortDateString() == "")) { return "null"; } return string.Format("convert(DateTime,'{0}',104)", (date <= System.DateTime.MinValue) ? ((object) "01.01.1753") : ((object) date.ToShortDateString())); }
public CashChangeCalculatorForm(decimal charge, System.DateTime paymentDate) : this() { if ((this.editCharge != null) && (this.editCash != null)) { this.Charge = charge; this.Cash = charge; this.editCash.Focus(); this.editCash.Select(0, this.editCharge.get_Text().get_Length()); this.lblPaymentDate.set_Text(paymentDate.ToShortDateString()); } }
/// <summary>将日期数据转换成字符串</summary> /// <param name="VarDateTime">日期数据</param> /// <param name="IntDateType">转换格式:0-普通,1-长日期,2-长时间,3-短日期,4-短时间,5-中文日期,6-中文时间,7-中文日期时间</param> /// <returns>返回字符串</returns> public static string DateToStr(System.DateTime VarDateTime, int IntDateType) { string udate = ""; switch (IntDateType) { case 1: udate = VarDateTime.ToLongDateString(); break; case 2: udate = VarDateTime.ToLongTimeString(); break; case 3: udate = VarDateTime.ToShortDateString(); break; case 4: udate = VarDateTime.ToShortTimeString(); break; case 5: { udate = VarDateTime.Year.ToString() + "年"; udate += VarDateTime.Month.ToString() + "月"; udate += VarDateTime.Day.ToString() + "日"; break; } case 6: { udate = VarDateTime.Hour.ToString() + "时"; udate += VarDateTime.Minute.ToString() + "分"; udate += VarDateTime.Second.ToString() + "秒"; break; } case 7: { udate = VarDateTime.Year.ToString() + "年"; udate += VarDateTime.Month.ToString() + "月"; udate += VarDateTime.Day.ToString() + "日 "; udate += VarDateTime.Hour.ToString() + "时"; udate += VarDateTime.Minute.ToString() + "分"; udate += VarDateTime.Second.ToString() + "秒"; break; } default: udate = VarDateTime.ToString(); break; } return udate; }
// ' funciones para sql server de fechas // '-------------------------------------------- // '-------------------------------------------- // ' la insercion siempre con formato yyyymmdd hh:mm // public static Function fechaSql(ByVal fecha As Date) As string // try // Dim cadena As string // ' return Date.MinValue.ToString // cadena = fecha.Year.ToString.PadLeft(4, "0") + fecha.Month.ToString.PadLeft(2, "0") + fecha.Day.ToString.PadLeft(2, "0") + " " + fecha.Hour.ToString.PadLeft(2, "0") + ":" + fecha.Minute.ToString.PadLeft(2, "0") // return cadena // catch ex As System.Exception // ' devolvemos la cadena vacia ya que no se permite // ' insertar del date.minvalue en formato iso, es // ' mejor dejarlo en blanco que es lo mismo // return "" // } // } // ' la insercion siempre con formato yyyymmdd hh:mm // public static Function fechaSqlCorta(ByVal fecha As Date) As string // try // Dim cadena As string // ' return Date.MinValue.ToString // cadena = fecha.Year.ToString.PadLeft(4, "0") + fecha.Month.ToString.PadLeft(2, "0") + fecha.Day.ToString.PadLeft(2, "0") // return cadena // catch ex As System.Exception // ' devolvemos la cadena vacia ya que no se permite // ' insertar del date.minvalue en formato iso, es // ' mejor dejarlo en blanco que es lo mismo // return "" // } // } public static bool esFecha(System.DateTime fecha) { try { switch (fecha.ToShortDateString().ToString()) { case "01/01/0001": return false; break; case "01/01/1900": return false; break; } System.DateTime fechita = new System.DateTime(); fechita = System.DateTime.Parse(fecha.ToString()); return true; } catch (System.Exception ex) { return false; } }
public string GetDateString(System.DateTime date) { if (string.IsNullOrEmpty(Format) == false) { return date.ToString(Format); } if(stringType == DateTimeStringType.ToString) { return date.ToString(); } else if(stringType == DateTimeStringType.ToLongDateString) { return date.ToLongDateString(); } else if(stringType == DateTimeStringType.ToLongTimeString) { return date.ToLongTimeString(); } else if( stringType == DateTimeStringType.ToShortDateString) { return date.ToShortDateString(); } else if(stringType == DateTimeStringType.ToShortTimeString) { return date.ToShortTimeString(); } return date.ToString(); }
public void InsertReportShedulerParameters(long reportId, System.DateTime fromDate, System.DateTime toDate, ObjectList<Organization> houseHolders, ObjectList<Organization> serviceHouseHolders, ObjectList<Organization> accountHouseHolders, ObjectList<Organization> serviceProviders, ObjectList<Organization> resourceProviders, ObjectList<Organization> cashlessTransferrers, ObjectList<ServiceTypeOld> serviceTypes, ObjectList<CanonicalService> canonicalServices, ObjectList<ServiceOld> services, System.Collections.Generic.List<FasetItem> fasetItemApartmentTypes, System.Collections.Generic.List<FasetItem> fasetItemConvenienceTypes, System.Collections.Generic.List<FasetItem> fasetItemRecalcReasons, ObjectList<LocalAddress> localAddresses, Area selectedByUserArea, ObjectList<Benefit> benefits, bool isDebt, bool existsBenefitDiff, string paymentType, string apartamentArea, long minSumm, System.DateTime fromDay, System.DateTime toDay, bool withoutBankrupt, bool withoutClosesApartments, System.Collections.Generic.List<FasetItem> fasetFilterItems, ObjectList<Organization> paymentAgents, System.Collections.Generic.List<FasetItem> fasetItemHouseTypes, FasetItem cityBoroughs, string textParameter) { if (reportId != RepReportSheduler.Null.Id) { RepReportShedulerParameter parameter; if (fromDate != AIS.SN.Model.Constants.NullDate) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "fromDate", Value = fromDate.ToShortDateString(), PrintName = "Начало периода", PrintValue = fromDate.ToShortDateString() }; parameter.SaveChanges(); } if (toDate != AIS.SN.Model.Constants.NullDate) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "toDate", Value = toDate.ToShortDateString(), PrintName = "Окончание периода", PrintValue = toDate.ToShortDateString() }; parameter.SaveChanges(); } if (houseHolders != null) { foreach (Organization organization in houseHolders) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "houseHolderId", Value = ((long) organization.Id).ToString(), PrintName = "Управляющая компания жилья", PrintValue = organization.ShortName }; parameter.SaveChanges(); } } if (serviceHouseHolders != null) { foreach (Organization organization2 in serviceHouseHolders) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "serviceHouseHolderId", Value = ((long) organization2.Id).ToString(), PrintName = "Управляющая компания услуги", PrintValue = organization2.ShortName }; parameter.SaveChanges(); } } if (accountHouseHolders != null) { foreach (Organization organization3 in accountHouseHolders) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "accountHouseHolderId", Value = ((long) organization3.Id).ToString(), PrintName = "Управляющая компания ЛС", PrintValue = organization3.ShortName }; parameter.SaveChanges(); } } if (serviceProviders != null) { foreach (Organization organization4 in serviceProviders) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "serviceProviderId", Value = ((long) organization4.Id).ToString(), PrintName = "Поставщик", PrintValue = organization4.ShortName }; parameter.SaveChanges(); } } if (resourceProviders != null) { foreach (Organization organization5 in resourceProviders) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "resourceProviderId", Value = ((long) organization5.Id).ToString(), PrintName = "Ресурсоснабжающая организация", PrintValue = organization5.ShortName }; parameter.SaveChanges(); } } if (cashlessTransferrers != null) { foreach (Organization organization6 in cashlessTransferrers) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "cashlessTransferrerId", Value = ((long) organization6.Id).ToString(), PrintName = "Организация по безналичным перечислениям", PrintValue = organization6.ShortName }; parameter.SaveChanges(); } } if (serviceTypes != null) { foreach (ServiceTypeOld old in serviceTypes) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "serviceTypeId", Value = ((long) old.Id).ToString(), PrintName = "Группа услуг", PrintValue = old.ShortName }; parameter.SaveChanges(); } } if (canonicalServices != null) { foreach (CanonicalService service in canonicalServices) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "canonicalId", Value = ((long) service.Id).ToString(), PrintName = "Вид благоустройства", PrintValue = service.ShortName }; parameter.SaveChanges(); } } if (services != null) { foreach (ServiceOld old2 in services) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "serviceId", Value = ((long) old2.Id).ToString(), PrintName = "Услуга", PrintValue = old2.ShortName }; parameter.SaveChanges(); } } if (fasetItemApartmentTypes != null) { foreach (FasetItem item in fasetItemApartmentTypes) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "fasetItemApartmentTypeId", Value = ((int) item.Id).ToString(), PrintName = "Тип жилья", PrintValue = item.Name }; parameter.SaveChanges(); } } if (fasetItemHouseTypes != null) { foreach (FasetItem item2 in fasetItemHouseTypes) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "fasetItemHouseTypeId", Value = ((int) item2.Id).ToString(), PrintName = "Тип дома", PrintValue = item2.Name }; parameter.SaveChanges(); } } if (fasetItemConvenienceTypes != null) { foreach (FasetItem item3 in fasetItemConvenienceTypes) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "convenienceTypeId", Value = ((int) item3.Id).ToString(), PrintName = "Тип благоустройства", PrintValue = item3.Name }; parameter.SaveChanges(); } } if (fasetItemRecalcReasons != null) { foreach (FasetItem item4 in fasetItemRecalcReasons) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "typeReasonRecalcId", Value = ((int) item4.Id).ToString(), PrintName = "Причина перерасчёта", PrintValue = item4.Name }; parameter.SaveChanges(); } } if ((localAddresses != null) && (localAddresses.get_Count() != 0)) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "areaId", Value = ((long) Area.GetAreaIdByLocalAddresses(localAddresses)).ToString() }; if (selectedByUserArea == Area.Null) { parameter.Value = ((long) Area.GetAreaIdByLocalAddresses(localAddresses)).ToString(); } else { parameter.Value = ((long) selectedByUserArea.Id).ToString(); } parameter.SaveChanges(); } if (benefits != null) { foreach (Benefit benefit in benefits) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "benefitId", Value = ((long) benefit.Id).ToString(), PrintName = "Льгота", PrintValue = benefit.ShortName }; parameter.SaveChanges(); } } if (isDebt) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "isDebt", Value = "1", PrintName = "Разделение долгов", PrintValue = "учтено" }; parameter.SaveChanges(); } if (existsBenefitDiff) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "isExistsBenefitDiff", Value = "1", PrintName = "Расхождения с КСЗН", PrintValue = "учтены" }; parameter.SaveChanges(); } if (fasetFilterItems != null) { foreach (FasetItem item5 in fasetFilterItems) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "fasetFilterItemId", Value = ((int) item5.Id).ToString(), PrintName = item5.Faset.Name, PrintValue = item5.Name }; parameter.SaveChanges(); } } if (paymentAgents != null) { foreach (Organization organization7 in paymentAgents) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "paymentAgentId", Value = ((long) organization7.Id).ToString(), PrintName = "Платежный агент", PrintValue = organization7.ShortName }; parameter.SaveChanges(); } } RepReportTemplate template = RepReportTemplate.FindById(((RepReportTemplate) this.reportsTree.SelectedNode.get_Tag()).Id); if (template.MinSumm) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "minSumm", Value = this.numMinSumm.Value.ToString(), PrintName = "Минимальная сумма", PrintValue = ((long) minSumm).ToString() }; parameter.SaveChanges(); } if (template.DatePeriod) { if (fromDay != AIS.SN.Model.Constants.NullDate) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "fromDay", Value = fromDay.ToShortDateString(), PrintName = "Дата начала", PrintValue = fromDay.ToShortDateString() }; parameter.SaveChanges(); } if (toDay != AIS.SN.Model.Constants.NullDate) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "toDay", Value = toDay.ToShortDateString(), PrintName = "Дата окончания", PrintValue = toDay.ToShortDateString() }; parameter.SaveChanges(); } } if (template.CalcOperationGroups) { CalcOperationGroup group = ((CalcOperationGroup) this.bsCalcOperationGroups.get_Current()) ?? CalcOperationGroup.Null; if (group != CalcOperationGroup.Null) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "calcOperGroupId", Value = ((long) group.Id).ToString(), PrintName = "Тип оплаты", PrintValue = group.Name }; parameter.SaveChanges(); } } if (paymentType != string.Empty) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "paymentType", Value = paymentType, PrintName = "Тип оплаты", PrintValue = paymentType }; parameter.SaveChanges(); } if (apartamentArea != string.Empty) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "apartamentArea", Value = apartamentArea, PrintName = "Площадь", PrintValue = apartamentArea }; parameter.SaveChanges(); } if (template.PaymentAgentTypes) { FasetItem selectedFasetItem = this.selectPaymentAgentTypes.SelectedFasetItem; if (selectedFasetItem != FasetItem.Null) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "paymentAgentTypeId", Value = ((int) selectedFasetItem.Id).ToString(), PrintName = "Режим работы", PrintValue = selectedFasetItem.Name }; parameter.SaveChanges(); } } if (withoutBankrupt) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "withoutBankrupt", Value = "1", PrintName = "Организации-банкроты", PrintValue = "Не учитывать" }; parameter.SaveChanges(); } if (withoutClosesApartments) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "withoutClosesApartments", Value = "1", PrintName = "Закрытые паспорта жилья", PrintValue = "Не учитывать" }; parameter.SaveChanges(); } if (template.AccountProperty) { FasetItem item7 = this.selectAccountPropertyFaset.SelectedFasetItem; if (item7 != FasetItem.Null) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "accountPropertyId", Value = ((int) item7.Id).ToString(), PrintName = "Параметры ЛС", PrintValue = item7.Name }; parameter.SaveChanges(); } } if (template.AccountProperty) { FasetItem item8 = this.selectAccountPropertyFaset.SelectedFasetItem; if (item8 != FasetItem.Null) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "accountPropertyId", Value = ((int) item8.Id).ToString(), PrintName = "Параметры ЛС", PrintValue = item8.Name }; parameter.SaveChanges(); } } if (template.CityBorough && (cityBoroughs != FasetItem.Null)) { parameter = new RepReportShedulerParameter { ReportId = reportId, Name = "boroughId", Value = ((int) cityBoroughs.Id).ToString(), PrintName = "Район города", PrintValue = cityBoroughs.Name }; parameter.SaveChanges(); } if (!string.IsNullOrEmpty(textParameter)) { new RepReportShedulerParameter { ReportId = reportId, Name = "textParameter", Value = textParameter, PrintName = template.TextParameter, PrintValue = textParameter }.SaveChanges(); } } }
private string BuildAmeriFluxTSURL(string SiteCode, string[] VariableCodes, System.DateTime MinDate, System.DateTime MaxDate) { System.Text.StringBuilder urlBuilder = new System.Text.StringBuilder(200); urlBuilder.Append("http://cdiac.esd.ornl.gov/cgi-bin/broker?_PROGRAM=prog.write_somevars_amersite.sas&_SERVICE=default"); for (long i = 0; i <= VariableCodes.Length - 1; i++) { if (VariableCodes[i] != "") { urlBuilder.Append("¶m=" + VariableCodes[i]); } } urlBuilder.Append("&dataset=" + SiteCode); urlBuilder.Append("&libname=DATA3"); urlBuilder.Append("&mindate=" + MinDate.ToShortDateString()); urlBuilder.Append("&maxdate=" + MaxDate.ToShortDateString()); urlBuilder.Append("&csvfile=download"); return urlBuilder.ToString(); }
protected override void ApplyAtDate(System.DateTime applyDate) { int nbPositions = 10; // Evaluate portofolio value. float[] positionValues = new float[this.Series.Count]; float portfolioValue = this.availableLiquidity; int count = 0; foreach (StockPosition position in this.Positions) { StockSerie serie = this.Series.Find(s => s.StockName == position.StockName); float value = 0; if (serie.ContainsKey(applyDate)) { value = position.Value(serie[applyDate].OPEN); } else { value = position.Value(serie[previousDate].OPEN); } positionValues[count++] = value; portfolioValue += value; } #if USE_LOGS StockLog.Write("Before Selling Arbitrage"); this.Dump(applyDate); #endif // Evaluate performance using RANK indicator Dictionary<StockSerie, float> variations = new Dictionary<StockSerie, float>(); foreach (StockSerie serie in this.Series) { if (serie.ContainsKey(applyDate)) { //variations.Add(serie, serie.GetIndicator("RANK(12,10)").Series[0][serie.IndexOf(applyDate)-1]); //variations.Add(serie, serie.GetIndicator("ADXDIFF(50,25)").Series[0][serie.IndexOf(applyDate)-1]); int index = serie.IndexOf(applyDate) - 1; if (index > 0) { StockSerie rsSerie = StockDictionary[serie.StockName + "_RS"]; IStockIndicator indicator = serie.GetIndicator("OSC(149,150)"); if (indicator.Events[4][index]) { variations.Add(serie, indicator.Series[0][index]); } } } } var sortedList = variations.Where(p => p.Value > 0).OrderByDescending(p => p.Value).Take(nbPositions); // Sell stock not listed as best performers float targetPositionValue = portfolioValue / (float)this.Series.Count; List<StockPosition> trashList = new List<StockPosition>(); foreach (StockPosition position in this.Positions) { if (sortedList.Any(p => p.Key.StockName == position.StockName)) continue; // Keep position in portofolio StockSerie serie = this.Series.First(s => s.StockName == position.StockName); // Sell position StockLog.Write(" ==> " + applyDate.ToShortDateString() + "Selling " + position.Number + " " + position.StockName); StockOrder order; DateTime executionDate = serie.ContainsKey(applyDate) ? applyDate : previousDate; order = StockOrder.CreateExecutedOrder(position.StockName, StockOrder.OrderType.SellAtMarketOpen, false, applyDate, applyDate, position.Number, serie[executionDate].OPEN, 0.0f); this.availableLiquidity += position.Number * serie[executionDate].OPEN; this.Portfolio.OrderList.Add(order); trashList.Add(position); } foreach (var p in trashList) { this.Positions.Remove(p); } #if USE_LOGS StockLog.Write("Before Buying Arbitrage"); this.Dump(applyDate); #endif // Buy stock best perfoming stocks foreach (var pair in sortedList) { if (this.Positions.Count >= nbPositions) break; if (this.Positions.Any(p => p.StockName == pair.Key.StockName)) continue; // already in portfolio // Buy int nbUnit = (int)Math.Floor(this.availableLiquidity / pair.Key[applyDate].OPEN / (nbPositions - this.Positions.Count)); //if (nbUnit <= 0) // StockLog.Write("Unit" + nbUnit); if (nbUnit > 0) { StockLog.Write(" ==> " + applyDate.ToShortDateString() + "Buying " + nbUnit + " " + pair.Key.StockName); StockOrder order = StockOrder.CreateExecutedOrder(pair.Key.StockName, StockOrder.OrderType.BuyAtMarketOpen, false, applyDate, applyDate, nbUnit, pair.Key[applyDate].OPEN, 0.0f); this.availableLiquidity -= nbUnit * pair.Key[applyDate].OPEN; this.Portfolio.OrderList.Add(order); this.Positions.Add(new StockPosition(order)); } } this.Dump(applyDate); previousDate = applyDate; #if USE_LOGS StockLog.Write("After Arbitrage"); #endif }
public ScreenshotAttachProgressEventArgs(System.DateTime sessionStartDate, int current, int total) { this.Message = string.Format("Looking in session from {0} for screenshots", sessionStartDate.ToShortDateString()); this.PercentComplete = current * 100 / ((total == 0) ? 1 : total); }
public static string ToDateText(System.DateTime date) { return date.ToShortDateString(); }
public DataTable GetTransactionByRefNo(string refNo, System.DateTime date) { this.FlushData(); var query = String.Format( "SELECT *, ROW_NUMBER() OVER (ORDER BY id.DATE DESC) as RowNo, datediff(day, id.EurDate, ExpDate) as DBEI " + "FROM IssueDoc id Join ReceiveDoc rd on id.RecievDocID = rd.ID " + "join vwGetAllItems vw on id.ItemID =vw.ID WHERE (id.IsTransfer = 0) and id.RefNo = '{0}' and id.Date = '{1}'", refNo, date.ToShortDateString()); this.LoadFromRawSql(query); return this.DataTable; }
public Rehab.BookingsDataTable GetBookingsByDates(System.DateTime startdate, System.DateTime enddate) { return Adapter.GetBookingsByDates(startdate.ToShortDateString(), enddate.ToShortDateString()); }
public Rehab.BookingsDataTable GetBookingsByDate(System.DateTime date) { return Adapter.GetBookingsByDate(date.ToShortDateString()); }
protected override void ApplyAtDate(System.DateTime applyDate) { // Verify all serie have data // Evaluate portofolio value. float[] positionValues = new float[this.Series.Count]; float[] serieValues = new float[this.Series.Count]; float portfolioValue = this.availableLiquidity; int count = 0; foreach (StockPosition position in this.Positions) { StockSerie serie = this.Series.Find(s => s.StockName == position.StockName); serieValues[count] = serie[applyDate].OPEN; float value = position.Value(serieValues[count]); positionValues[count++] = value; portfolioValue += value; } #if USE_LOGS StockLog.Write("Before Selling Arbitrage"); this.Dump(applyDate); #endif // Sell stock outvaluing the ratio by xx% const float ratioTrigger = 0.05f; float targetPositionValue = portfolioValue / (float)this.Series.Count; count = 0; foreach (StockPosition position in this.Positions) { float delta = positionValues[count] - targetPositionValue; float deltaRatio = delta / portfolioValue; if (deltaRatio > ratioTrigger) { // Sell to reduce postion int nbUnit = (int)Math.Floor(delta / serieValues[count]); if (nbUnit <= 0) StockLog.Write("Unit" + nbUnit); if (nbUnit > 0) { StockLog.Write(" ==> " + applyDate.ToShortDateString() + "Selling " + nbUnit + " " + position.StockName); StockOrder order = StockOrder.CreateExecutedOrder(position.StockName, StockOrder.OrderType.SellAtMarketOpen, false, applyDate, applyDate, nbUnit, serieValues[count], 0.0f); this.availableLiquidity += nbUnit * serieValues[count]; this.Portfolio.OrderList.Add(order); position.Add(order); } } count++; } #if USE_LOGS StockLog.Write("Before Buying Arbitrage"); this.Dump(applyDate); #endif // Buy stock undervaluing the ratio by xx% count = 0; foreach (StockPosition position in this.Positions) { float delta = positionValues[count] - targetPositionValue; float deltaRatio = delta / portfolioValue; if (deltaRatio < -ratioTrigger) { // Buy to increase position int nbUnit = (int)Math.Floor(-delta / serieValues[count]); if (nbUnit <= 0) StockLog.Write("Unit" + nbUnit); if (nbUnit > 0 && this.availableLiquidity > nbUnit * serieValues[count]) { StockLog.Write(" ==> " + applyDate.ToShortDateString() + "Buying " + nbUnit + " " + position.StockName); StockOrder order = StockOrder.CreateExecutedOrder(position.StockName, StockOrder.OrderType.BuyAtMarketOpen, false, applyDate, applyDate, nbUnit, serieValues[count], 0.0f); this.availableLiquidity -= nbUnit * serieValues[count]; this.Portfolio.OrderList.Add(order); position.Add(order); } } count++; } #if USE_LOGS StockLog.Write("After Arbitrage"); this.Dump(applyDate); #endif }
public static string FormatDateTimeShort(System.DateTime Expression) { return Expression.ToShortDateString() + " " + Expression.ToShortTimeString(); }