public bool Sell(string strWKN) { // Verkaufe kompletten Bestand Depot depot = this.RuleEngineInfo.Depot; WorkDate today = this.RuleEngineInfo.Today; depot.Sell(strWKN, 100000, today); return(true); }
public bool Buy(string strWKN) { WorkDate today = this.RuleEngineInfo.Today; Depot depot = this.RuleEngineInfo.Depot; double dPrice = DBEngine.GetInstance().GetPrice(strWKN, today); int nQuantity = (int)(depot.Cash / dPrice); depot.Buy(strWKN, nQuantity, today, dPrice); return(true); }
public static DataContainer CreateFrom(DataContainer source, int nRange) { DataContainer result = new DataContainer(); WorkDate reference = source.OldestDate.Clone(); reference += nRange; WorkDate today = reference.Clone(); today += nRange; WorkDate enddate = source.YoungestDate.Clone(); enddate -= nRange; double dUpperPeak = Double.MaxValue; double dLowerPeak = Double.MinValue; double dTrend = TREND_UNKNOWN; while (today <= source.YoungestDate) { result[today] = dTrend; if (reference <= enddate) { if (IsPeak(reference, nRange, PeakType.UPPER, source)) { dUpperPeak = source[reference]; } if (IsPeak(reference, nRange, PeakType.LOWER, source)) { dLowerPeak = source[reference]; } } if (source[today] > dUpperPeak) { result[today] = OUTPERFORM; dTrend = CANCEL_OUTPERFORM; } if (source[today] < dLowerPeak) { result[today] = UNDERPERFORM; dTrend = CANCEL_UNDERPERFORM; } today++; reference++; } return(result); }
void UpdateDepotPositions() { WorkDate today = m_TradeRule.RuleEngineInfo.Today; Depot depot = m_TradeRule.RuleEngineInfo.Depot; foreach (DepotPosition position in depot) { double dPrice = DBEngine.GetInstance().GetPrice(position.WKN, today); position.Price = dPrice; } depot.UpdateStopLoss(); }
public static DataContainer CreateFrom(DataContainer source, WorkDate referenceDate) { DataContainer result = new DataContainer(); WorkDate workdate = source.OldestDate.Clone(); double dReference = source[referenceDate]; for (; workdate <= source.YoungestDate; workdate++) { result[workdate] = Math.Log(source[workdate] / dReference, 2.0) * 100.0; //result[workdate] = ((source[workdate] / dReference) - 1.0) * 100.0; } return(result); }
public static DataContainer CreateFrom(DataContainer source, int nRange) { DataContainer result = new DataContainer(); WorkDate workdate = source.OldestDate.Clone() + nRange; for (; workdate <= source.YoungestDate; workdate++) { double dPerf = Math.Log(source[workdate] / source[workdate - nRange], 2.0) * 100.0; //double dPerf = ((source[workdate] / source[workdate - 1]) - 1.0) * 100.0; result[workdate] = dPerf; } return(result); }
/// <summary> /// Fuehrt eine Zinseszinsberechnung auf der Basis des angegebenen /// Prozentsatzes und einem Startkapital von 100.0 aus. /// Die Berechnung wird für jeden Arbeitstag (und Feiertage), jedoch /// nicht fuer Wochenenden durchgefuehrt. /// </summary> /// <param name="fromDate">Beginn des Berechnungszeitraumes</param> /// <param name="toDate">Ende des Berechnungszeitraumes</param> /// <param name="dYearGrowth">Jahres-Performance in Prozent, z.B. 3.45</param> public static DataContainer CreateFrom(WorkDate fromDate, WorkDate toDate, double dYearGrowth) { DataContainer result = new DataContainer(); dYearGrowth /= 100.0; double dPerformanceFactor = Math.Pow(1.0 + dYearGrowth, 1.0 / WorkDate.WorkDaysPerYear); double dEquity = 100.0; for (WorkDate workdate = fromDate.Clone(); workdate <= toDate; workdate++) { result[workdate] = dEquity; dEquity *= dPerformanceFactor; } return(result); }
/// <summary> /// Berechnet die relative Differenz und legt das Ergebnis in einem neuen Datencontainer ab. /// </summary> /// <param name="a">Datensatz a, von dem Datensatz B abgezogen werden soll</param> /// <param name="b">Datensatz b, der von Datensatz A abgezogen werden soll</param> /// <returns>Neuer DatenContainer mit den Ergebnisdaten</returns> public static DataContainer CreateFrom(DataContainer a, DataContainer b) { DataContainer result = new DataContainer(); WorkDate workdate = a.OldestDate.Clone(); for (; workdate <= a.YoungestDate; workdate++) { if (b.Contains(workdate)) { result[workdate] = Math.Log(a[workdate] / b[workdate], 2.0) * 100.0; } } return(result); }
protected override bool ParseAndStore(string input, Stock stock) { // plausibility check, if the quotes line matches the expectation if (input.Contains("<tr><td> ") == false) { return(false); } int i = 0; string[] arrTokens = new string[7]; int iStartIndex = input.IndexOf("<tr><td> "); string strLine = input.Substring(iStartIndex); XmlTextReader reader = new XmlTextReader(new StringReader(strLine)); reader.WhitespaceHandling = WhitespaceHandling.None; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Text) { arrTokens[i] = reader.Value; i++; } } reader.Close(); //Date,Open,Close,High,Low,misc // 0 1 2 3 4 5 DateTime priceDate = new DateTime(); DateTime.TryParse(arrTokens[0], out priceDate); WorkDate workdate = new WorkDate(priceDate); double priceClose = Double.Parse(arrTokens[2]); double priceLow = Double.Parse(arrTokens[4]); stock.QuotesClose[workdate] = priceClose; stock.QuotesLow[workdate] = priceLow; System.Console.Write(workdate.ToString() + "\r"); return(true); }
public void PrintInfo() { WorkDate today = m_TradeRule.RuleEngineInfo.Today; Depot depot = m_TradeRule.RuleEngineInfo.Depot; Console.SetCursorPosition(0, 1); Console.Out.WriteLine("Simulation von: " + m_TradeRule.RuleEngineInfo.FromDate + " bis " + m_TradeRule.RuleEngineInfo.ToDate + " Heute: " + today + " Compl.: " + m_TradeRule.RuleEngineInfo.Variants.Completeness + " "); depot.Dump(today); Console.Out.WriteLine("Variante: "); foreach (string strVariantKey in m_TradeRule.RuleEngineInfo.Variants.ItemKeys) { Console.Out.WriteLine(strVariantKey + "=" + m_TradeRule.RuleEngineInfo.Variants[strVariantKey] + " "); } Console.Out.WriteLine("Performance: " + depot.Performance + " dB% "); }
protected override string BuildURI(Stock stock, WorkDate startdate, WorkDate enddate) { //http://ichart.finance.yahoo.com/table.csv?s=D1A9.DE&d=1&e=27&f=2011&g=d&a=4&b=2&c=2007&ignore=.csv string strQuoteString = "http://ichart.finance.yahoo.com/table.csv?"; strQuoteString += "s=" + stock.Symbol; if (startdate.Year > 1900) { strQuoteString += string.Format("&a={0}&b={1}&c={2}", startdate.Month - 1, startdate.Day, startdate.Year); strQuoteString += string.Format("&d={0}&e={1}&f={2}", enddate.Month - 1, enddate.Day, enddate.Year); } strQuoteString += "&g=d"; strQuoteString += "&ignore=.csv"; return(strQuoteString); }
/// <summary> /// Berechnet die Volatilitaet/Standardabweichung und legt das Ergebnis /// in einem neuen Datencontainer ab. /// </summary> /// <param name="source">Datensatz, von dem die Volatilitaet gebildet werden soll</param> /// <param name="nRange">Anzahl der einzubeziehenden Daten pro Berechnung</param> /// <returns>Neuer DatenContainer mit den Ergebnisdaten</returns> public static DataContainer CreateFrom(DataContainer source, int nRange) { if (nRange < 1) { throw new ArgumentOutOfRangeException("Average", nRange, "Must be greater than zero."); } DataContainer result = new DataContainer(); double dSum = 0; double dSumSquare = 0; WorkDate workdate = source.OldestDate.Clone(); WorkDate helperworkdate = source.OldestDate.Clone(); for (int i = 0; i < nRange - 1; i++, workdate++) { double dValue = source[workdate]; dSum += dValue; dSumSquare += dValue * dValue; } do { double dValue = source[workdate]; dSum += dValue; dSumSquare += dValue * dValue; double dVariance = ((nRange * dSumSquare) - (dSum * dSum)) / (nRange * (nRange - 1)); dVariance = Math.Abs(dVariance); double dStdDev = Math.Sqrt(dVariance); result[workdate] = dStdDev; workdate++; double dPastValue = source[helperworkdate]; dSum -= dPastValue; dSumSquare -= dPastValue * dPastValue; helperworkdate++; }while (workdate <= source.YoungestDate); return(result); }
/* * Prüft, ob die Gerade X1/X2 keinen anderen Punkt im Chart * innerhalb der vorgegebenen Grenzen schneidet. * Berührungen sind erlaubt! */ private bool isTangential(DataContainer source, WorkDate left, WorkDate right, LimitType limit) { double iY1 = source[left]; double iY2 = source[right]; double dm = (double)(iY2 - iY1) / (double)(right - left); for (WorkDate i = new WorkDate(left + 1); i < right; i++) { double iDiff = source[i] - source[left] - (double)(dm * (i - left)); if ((limit == LimitType.LOWER && iDiff <= 0) || (limit == LimitType.UPPER && iDiff >= 0)) { return(false); } } return(true); }
///<summary> /// Berechnet den PriceOscillator und legt das Ergebnis in einem neuen Datencontainer ab. /// </summary> /// <param name="source">Daten, von dem der Indikator gebildet werden soll</param> /// <param name="nAverageFast">Anzahl der Daten, des kuerzeren GD</param> /// <param name="nAverageSlow">Anzahl der Daten, des laengerem GD</param> /// <returns>Neuer DatenContainer mit den Ergebnisdaten</returns> public static DataContainer CreateFrom(DataContainer source, int nAverageFast, int nAverageSlow) { if (nAverageFast > nAverageSlow) { throw(new ArgumentOutOfRangeException()); } DataContainer fast = MovingAverage.CreateFrom(source, nAverageFast); DataContainer slow = MovingAverage.CreateFrom(source, nAverageSlow); DataContainer result = new DataContainer(); for (WorkDate workdate = slow.OldestDate.Clone(); workdate <= slow.YoungestDate; workdate++) { //double dPerf = Math.Log(fast[workdate] / slow[workdate], 2.0) * 100.0; double dPerf = (fast[workdate] / slow[workdate]) - 1.0; result[workdate] = dPerf; } return(result); }
/* * Berechnet die obere oder untere Trendlinie eines Charts. */ private void trendLine(DataContainer target, DataContainer source, WorkDate today, LimitType limit) { WorkDate fromDate = new WorkDate(today); fromDate -= m_nRange; WorkDate bestLeft = new WorkDate(fromDate); WorkDate bestRight = new WorkDate(fromDate); for (; fromDate < today; fromDate++) { WorkDate scanDate = new WorkDate(today); scanDate -= m_nRange / 2; for (; scanDate < today; scanDate++) { if (isTangential(source, fromDate, scanDate, limit)) { // laenger, als der bereits gefundene // UND Linkes und rechtes Ende der Gerade muss in jeweils einer haelfte liegen if (scanDate - fromDate > bestRight - bestLeft) { bestLeft = new WorkDate(fromDate); bestRight = new WorkDate(scanDate); } } } } double dm = (double)(source[bestRight] - source[bestLeft]) / (double)(bestRight - bestLeft); target[today] = source[bestLeft] + (double)(dm * (today - bestLeft)); /*fromDate = new WorkDate(today); * fromDate -= m_nRange; * * for (; fromDate < today; fromDate++ ) * { * target[fromDate] = source[bestLeft] + (double)(dm * (fromDate - bestLeft)); * }*/ }
/// <summary> /// Berechnet die ReturnRiskRatio und legt das Ergebnis in einem neuen Datencontainer ab. /// </summary> /// <param name="source">Datensatz, von dem die ReturnRiskRatio gebildet werden soll</param> /// <param name="nRange">Anzahl der einzubeziehenden Daten pro Berechnung</param> /// <returns>Neuer DatenContainer mit den Ergebnisdaten</returns> public static DataContainer CreateFrom(DataContainer source, int nRange) { //DataContainer sourceperf = RelativePerformance.CreateFrom(source); DataContainer sourcechange = RelativeChange.CreateFrom(source); DataContainer changemovavg = MovingAverage.CreateFrom(sourcechange, nRange); DataContainer volatility = Volatility.CreateFrom(sourcechange, nRange); DataContainer result = new DataContainer(); //WorkDate historydate = volatility.OldestDate.Clone() - (int)nRange; WorkDate workdate = volatility.OldestDate.Clone(); for (; workdate <= volatility.YoungestDate; workdate++ /*, historydate++*/) { double dReturn = changemovavg[workdate]; //sourceperf[workdate] - sourceperf[historydate]; double dRisk = volatility[workdate]; // Standardabweichung //result[workdate] = dReturn / (dRisk + 1.0); result[workdate] = dReturn - dRisk; } return(result); }
public bool BuyRule() { //Depot depot = this.RuleEngineInfo.Depot; WorkDate today = RuleEngineInfo.Today; Console.WriteLine("{0} {1}", today, dax_rel_diff[today]); if (dax_rel_diff[today] < -5 && dax_rel_diff[today - 1] < dax_rel_diff[today] ) { if (Buy("dbx1da")) { buy_events[today] = dax_rel_diff[today]; buy_events_dax[today] = dax_close[today]; } return(true); } return(false); }
/// <summary> /// Berechnet Beta und legt das Ergebnis in einem neuen Datencontainer ab. /// </summary> /// <param name="source">Datensatz, von dem Beta gebildet werden soll</param> /// <param name="reference">Referenz, zu dem Beta gebildet werden soll</param> /// <param name="nRange">Anzahl der einzubeziehenden Daten pro Beta-Berechnung</param> /// <returns>Neuer DatenContainer mit den Ergebnisdaten</returns> public static DataContainer CreateFrom(DataContainer source, DataContainer reference, int nRange) { if (nRange < 1) { throw new ArgumentOutOfRangeException("Range", nRange, "Must be greater than zero."); } DataContainer covariance = CoVariance.CreateFrom(source, reference, nRange); DataContainer sigma = Volatility.CreateFrom(reference, nRange); DataContainer result = new DataContainer(); WorkDate workdate = covariance.OldestDate.Clone(); for (; workdate <= covariance.YoungestDate; workdate++) { double dSigma = sigma[workdate]; double dBeta = covariance[workdate] / (dSigma * dSigma); result[workdate] = dBeta; } return(result); }
public bool BuyRule() { Depot depot = this.RuleEngineInfo.Depot; WorkDate today = RuleEngineInfo.Today; if (dax_trend[today] >= 0) { if (depot.Contains("846900") == false) { if (dax_rel_diff[today] < -5 && dax_close[today - 1] < dax_close[today]) { Buy("846900"); buy_events[today] = dax_rel_diff[today]; buy_events_dax[today] = dax_close[today]; return(true); } } } return(false); }
protected static bool IsPeak(WorkDate testdate, int nRange, PeakType peaktype, DataContainer source) { WorkDate workdate = testdate.Clone(); workdate -= nRange; WorkDate rangeend = testdate.Clone(); rangeend += nRange; while (workdate <= rangeend) { if ((peaktype == PeakType.LOWER && source[workdate] < source[testdate]) || (peaktype == PeakType.UPPER && source[workdate] > source[testdate])) { return(false); } workdate++; } return(true); }
/// <summary> /// Berechnet die Korrelation und legt das Ergebnis in einem neuen Datencontainer ab. /// </summary> /// <param name="a">Datensatz A, zwischen denen die Korrelation gebildet werden soll</param> /// <param name="b">Datensatz B, zwischen denen die Korrelation gebildet werden soll</param> /// <param name="nRange">Anzahl der einzubeziehenden Daten pro Korrelationsberechnung</param> /// <returns>Neuer DatenContainer mit den Ergebnisdaten</returns> public static DataContainer CreateFrom(DataContainer a, DataContainer b, int nRange) { if (nRange < 1) { throw new ArgumentOutOfRangeException("Range", nRange, "Must be greater than zero."); } DataContainer covariance = CoVariance.CreateFrom(a, b, nRange); DataContainer sigma_a = Volatility.CreateFrom(a, nRange); DataContainer sigma_b = Volatility.CreateFrom(b, nRange); DataContainer result = new DataContainer(); WorkDate workdate = covariance.OldestDate.Clone(); for (; workdate <= covariance.YoungestDate; workdate++) { double dCorrelation = covariance[workdate] / (sigma_a[workdate] * sigma_b[workdate]); result[workdate] = dCorrelation; } return(result); }
// Called only once to init trade rule public void Setup() { this.RuleEngineInfo.FromDate = new WorkDate(1990, 1, 1); this.RuleEngineInfo.ToDate = new WorkDate(2010, 10, 15); this.RuleEngineInfo.Variants.Add("averaging", new int[] { 38 }); this.RuleEngineInfo.MinimumInvestment = 5000.0; this.RuleEngineInfo.TargetPositions = 10; this.RuleEngineInfo.MaxLoss = 0.90; this.RuleEngineInfo.Depot.DefaultTrailingGap = 10; // Create virtual instuments: // Create DAXex from DAX-Index DataContainer dax = DBEngine.GetInstance().GetQuotes("846900").Clone(); DataContainer put = new DataContainer(); double dRef = dax[dax.OldestDate]; for (WorkDate workdate = dax.OldestDate.Clone(); workdate <= dax.YoungestDate; workdate++) { put[workdate] = 100.0 * dRef / dax[workdate]; dax[workdate] = dax[workdate] / 100.0; } DBEngine.GetInstance().AddVirtualInvestment("dax_long", "DAX EX", dax); DBEngine.GetInstance().AddVirtualInvestment("dax_short", "DAX EX Short", put); // Create some fixed growth investment stocks DataContainer fixedGrowth = FixedGrowthInvestment.CreateFrom(dax.OldestDate, dax.YoungestDate, 2); DBEngine.GetInstance().AddVirtualInvestment("Bond", "Festgeld", fixedGrowth); fixedGrowth = FixedGrowthInvestment.CreateFrom(dax.OldestDate, dax.YoungestDate, 10); DBEngine.GetInstance().AddVirtualInvestment("TargetPerf", "Soll-Performance", fixedGrowth); dax_trend = new DataContainer(); }
public void CreateFrom(DataContainer source, WorkDate today) { Console.Out.WriteLine("TrendChannel CreateFrom called\n"); this.Clear(); m_UpperLimit.Clear(); m_LowerLimit.Clear(); for (WorkDate date = new WorkDate(today); date > today - 300 /*source.GetOldestDate()+m_nRange*/; date--) { trendLine(m_UpperLimit, source, date, LimitType.UPPER); trendLine(m_LowerLimit, source, date, LimitType.LOWER); Console.Out.WriteLine(date); } for (WorkDate date = new WorkDate(m_UpperLimit.OldestDate); date <= m_UpperLimit.YoungestDate; date++) { if (m_LowerLimit.Contains(date)) { this[date] = (m_UpperLimit[date] + m_LowerLimit[date]) / 2.0; } } }
public static DataContainer CreateFrom(DataContainer source, int nRange, PeakType peaktype) { if (nRange < 1) { throw new ArgumentOutOfRangeException("nRange", nRange, "Must be greater than zero."); } DataContainer result = new DataContainer(); WorkDate reference = source.OldestDate.Clone(); reference += nRange; WorkDate today = reference.Clone(); today += nRange; WorkDate enddate = source.YoungestDate.Clone(); enddate -= nRange; double dPeakValue = 0; while (today <= source.YoungestDate) { if (reference <= enddate) { if (IsPeak(reference, nRange, peaktype, source)) { dPeakValue = source[reference]; } } result[today] = dPeakValue; today++; reference++; } return(result); }
//var model = new ValidationViewModel //modle public string this[string columnName] { get { string result = null; if (columnName == "FirstName") { if (string.IsNullOrEmpty(FirstName)) { result = "FirstName is a mandatory field!"; } } if (columnName == "LastName") { if (string.IsNullOrEmpty(LastName)) { result = "LastName is a mandatory field!"; } } if (columnName == "Email") { if (string.IsNullOrEmpty(Email)) { result = "Email a mandatory field!"; } else if (!EmailValidation.IsValidEmailAddress(Email)) { result = "The emails address is not valid!!"; } } if (columnName == "Phone") { if (string.IsNullOrEmpty(Phone)) { result = "Phone is a mandatory field!"; } } if (columnName == "Dob") { DateTime hundredYearsPast = DateTime.Now.AddYears(-100); if (Dob.Equals(null)) { result = "Dob is a mandatory field!"; } else if (Dob.CompareTo(DateTime.Now) > 0) { result = "Dob should be in the past!"; } //else if(DateTime.Compare(hundredYearsPast, DateTime.Now.AddYears(-100))< 1) else if (Dob < hundredYearsPast) { result = "Dob not should be in the 100+ years past"; } } if (columnName == "WorkDate") { DateTime tenYearsPast = DateTime.Now.AddYears(-10); if (WorkDate.Equals(null)) { result = "WorkDate is a mandatory field!"; } else if (WorkDate.CompareTo(DateTime.Now) >= 0) { result = "WorkDate should be in the past or Today!"; } //else if(DateTime.Compare(hundredYearsPast, DateTime.Now.AddYears(-100))< 1) else if (WorkDate < tenYearsPast) { result = "WorkDate should not be in 10+ year past"; } } if (columnName == "Hours") { if (Hours <= 0 || Hours > 24) { result = "Hours must be between 0 and 24"; } } if (columnName == "BeginDate") { DateTime tenYearsPast = DateTime.Now.AddYears(-10); if (BeginDate.Equals(null)) { result = "BeginDate is a mandatory field to Calculate TotalHours for the period!"; } else if (BeginDate.CompareTo(DateTime.Now) >= 0) { result = "BeginDate should be in the past or Today!"; } //else if(DateTime.Compare(hundredYearsPast, DateTime.Now.AddYears(-100))< 1) else if (BeginDate < tenYearsPast) { result = "BeginDate should not be in 10+ year past"; } } if (columnName == "EndDate") { DateTime tenYearsPast = DateTime.Now.AddYears(-10); if (EndDate.Equals(null)) { result = "EndDate is a mandatory field to Calculate TotalHours for the period!"; } else if (EndDate.CompareTo(DateTime.Now) >= 0) { result = "EndDate should be in the past or Today!"; } //else if(DateTime.Compare(hundredYearsPast, DateTime.Now.AddYears(-100))< 1) else if (EndDate < tenYearsPast) { result = "EndDate should not be in 10+ year past"; } } return(result); } }
/// <summary> /// Build a URI to download a set of quotes from a public web site. /// </summary> /// <param name="stock">The stock object that a URI should be build for downloading quotes</param> /// <param name="startdate">The date to start updating quotes</param> /// <param name="enddate">The date to end updating quotes</param> /// <returns>The complete URI that downloaded the quotes from a web site</returns> protected abstract string BuildURI(Stock stock, WorkDate startdate, WorkDate enddate);
//[DisplayName("更新人")] //[Property] //[ManyToOne(Column="UpdateUserID")] //virtual public User UpdateUser { get; set; } public override string ToString() { return(WorkDate.ToShortDateString()); }
public void StepDate() { WorkDate today = RuleEngineInfo.Today; today++; }
private void analyzeFor(String wkn, String title) { const int nInvestPeriodStep = 5; const int nMaxInvestPeriod = 30; DBEngine dbengine = DBEngine.GetInstance(); DataContainer dcPerformancesAvg = new DataContainer(); DataContainer[] dcPerformances = new DataContainer[5]; for (int i = 0; i < dcPerformances.Length; i++) { dcPerformances[i] = new DataContainer(); } if (dbengine.Exists(wkn) == false) { return; } Stock dax = dbengine.GetStock(wkn); DataContainer quotes = dax.Quotes; WorkDate fromDate = quotes.YoungestDate.Clone(); fromDate.Set(fromDate.Year - 4, fromDate.Month, 1); WorkDate endDate = quotes.YoungestDate.Clone() - nMaxInvestPeriod; DataContainer dax_ranged = quotes.Clone(fromDate); DataContainer dax_ma200 = MovingAverage.CreateFrom(quotes, 200); dax_ma200 = dax_ma200.Clone(fromDate); DataContainer dax_ma38 = MovingAverage.CreateFrom(quotes, 38); dax_ma38 = dax_ma38.Clone(fromDate); DataContainer dax_rel_diff_38 = RelativeDifference.CreateFrom(quotes, dax_ma38); dax_rel_diff_38 = dax_rel_diff_38.Clone(fromDate); for (; fromDate < endDate; fromDate++) { for (int nInvestPeriod = 10; nInvestPeriod <= nMaxInvestPeriod; nInvestPeriod += nInvestPeriodStep) { double dPerf = ((quotes[fromDate + nInvestPeriod] / quotes[fromDate]) - 1) * 100.0; dcPerformances[(nInvestPeriod / nInvestPeriodStep) - 2][fromDate] = dPerf; } } foreach (WorkDate keydate in dcPerformances[0].Dates) { double dAvg = dcPerformances[0][keydate] + dcPerformances[1][keydate] + dcPerformances[2][keydate] + dcPerformances[3][keydate] + dcPerformances[4][keydate]; dAvg /= 5; dcPerformancesAvg[keydate] = dAvg; } DataContainer upperBarrier = dax_ranged.Clone(); upperBarrier.Set(5); DataContainer middleBarrier = dax_ranged.Clone(); middleBarrier.Set(0); DataContainer lowerBarrier = dax_ranged.Clone(); lowerBarrier.Set(-5); // Create ProfitStatistik Chart chart = new Chart(); chart.Width = 1500; chart.Height = 800; chart.Format = Chart.OutputFormat.SVG; chart.Clear(); chart.LineWidth = 1; chart.SubSectionsX = 6; chart.TicsYInterval = 5; chart.LogScaleY = false; chart.Title = title + " Performance and MA 38/200\\n" + dax_rel_diff_38.OldestDate.ToString() + " - " + dax_rel_diff_38.YoungestDate.ToString(); chart.LabelY = "Performance (%)"; chart.RightDate = quotes.YoungestDate + 10; /*chart.Add(dcPerformances[0], Chart.LineType.SkyBlue, "10"); * chart.Add(dcPerformances[1], Chart.LineType.SkyBlue, "15"); * chart.Add(dcPerformances[2], Chart.LineType.SkyBlue, "20"); * chart.Add(dcPerformances[3], Chart.LineType.SkyBlue, "25"); * chart.Add(dcPerformances[4], Chart.LineType.SkyBlue, "30");*/ chart.Add(dcPerformancesAvg, Chart.LineType.Fuchsia, "Average Profit (5/10/15/20/25/30)"); chart.Add(dax_rel_diff_38, Chart.LineType.MediumBlue, "Rel. diff. to MA38"); chart.Add(upperBarrier, Chart.LineType.MediumRed); chart.Add(middleBarrier, Chart.LineType.Black); chart.Add(lowerBarrier, Chart.LineType.MediumGreen); chart.Create(World.GetInstance().ResultPath + title + "ProfitStatistik"); // Create DAX chart.Clear(); chart.LogScaleY = true; chart.TicsYInterval = 200; chart.Title = title + "\\n" + dax_ranged.OldestDate.ToString() + " - " + dax_ranged.YoungestDate.ToString(); chart.LabelY = "Punkte (log.)"; chart.RightDate = quotes.YoungestDate + 10; chart.Add(dax_ranged, Chart.LineType.MediumBlue, "Index"); //chart.Add(short_ranged, Chart.LineType.SeaGreen, "DAX Short"); chart.Add(dax_ma38, Chart.LineType.HeavyGreen, "Moving Average (38)"); chart.Add(dax_ma200, Chart.LineType.MediumRed, "Moving Average (200)"); chart.Create(World.GetInstance().ResultPath + title + "Overview"); }
/// <summary> /// Download the most recent stock's quote data from a quote server. /// It downloads max. 500 quote days. This method should be repeatedly called /// until it loads less than 4 quotes. /// </summary> /// <param name="stock">The stock object to be updated</param> /// <returns>The number of imported days</returns> public int Load(Stock stock) { bool bDoImport = false; int nImported = 0; WebRequest webreq; WebResponse webres; WorkDate startdate = stock.QuotesClose.YoungestDate.Clone() - 2; WorkDate enddate = WorkDate.Today; Log.Info("Downloading quotes from " + startdate + " to " + enddate); string strURI = BuildURI(stock, startdate, enddate); Log.Info(strURI); try { webreq = WebRequest.Create(strURI); webres = webreq.GetResponse(); } catch (UriFormatException) { System.Console.WriteLine("URI invalid. Can not send a web request."); return(0); } catch (WebException) { System.Console.WriteLine("Can not send a web request. No network?"); return(0); } Stream stream = webres.GetResponseStream(); StreamReader strrdr = new StreamReader(stream); string strLine = strrdr.ReadLine(); while ((strLine = strrdr.ReadLine()) != null) { if (EnableImport(strLine)) { bDoImport = true; } if (DisableImport(strLine)) { bDoImport = false; } if (bDoImport) { Log.Info(strLine); if (ParseAndStore(strLine, stock)) { nImported++; } } } strrdr.Close(); stream.Close(); Log.Info("Download and import finished."); return(nImported); }