/// <summary> /// Clear all loaded data /// </summary> private void btnClearAll_Click(object sender, EventArgs e) { valuedata = new TickList(); webdata = new TickList(); chtBackTest.Series.Clear(); //lstValueData.Items.Clear(); }
/// <summary> /// Loads a stream from a CSV-formatted textfile /// </summary> /// <param name="path">The path to the file that should be loaded</param> public void addStreamFromFile(string path) { TickList newdata = new TickList(path); ticklistholder.Add(newdata); addToChart(newdata, newdata.name, false, chtBackTest); }
public LiveTickList(WebProvider p, String q, TickList l) { this.provider = p; this.query = q; this.list = l.list; isLive = true; }
/// <summary> /// Same as Tuple<decimal, TickList > SimpleHoldStrategy(..) but this /// method only outputs the end result. /// </summary> /// <returns><Remaining value after using the specified strategy/returns> public static decimal SimpleHoldStrategyResult(TickList valuedata, TickList webdata, bool relative, decimal change, int holdtime) { decimal value = 1; TickList absticklist = webdata.AbsoluteDifferences(); List <Tick> absdif = absticklist.getList(); TickList relticklist = webdata.RelativeDifferences(); List <Tick> reldif = relticklist.getList(); for (int i = 0; i < reldif.Count && i != -1;) { if ((relative && reldif[i].getValue() > change) || (!relative && absdif[i].getValue() > change)) { DateTime buydate = reldif[i].getDate(); DateTime selldate = buydate.AddHours(holdtime); decimal buytimevalue = valuedata.valueAt(buydate); decimal selltimevalue = valuedata.valueAt(selldate); if ((buytimevalue != -1) && (selltimevalue != -1)) { value *= selltimevalue / buytimevalue; } i = relticklist.findDate(selldate); } else { i++; } } return(value); }
/// <summary> /// Browse for a file containing tick information. After a file is /// selected, a new TickList will be created and the data will be /// visible in the preview chart. /// </summary> private void btnBrowseFile_Click(object sender, EventArgs e) { if (loadFileDialog.ShowDialog() == DialogResult.OK) { toAdd = new TickList(loadFileDialog.FileName); showInPreviewChart(toAdd, toAdd.name, previewChart); txtName.Text = toAdd.name; txtFilePath.Text = loadFileDialog.FileName; } }
/// <summary> /// Deletes the selected row(s) from the ticklistholder /// </summary> private void btnDeleteStream_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in dgridStreams.SelectedRows) { TickList t = (TickList)row.DataBoundItem; ticklistholder.ticklists.Remove(t); removeFromChart(t.name, chtStreams); } refreshGridView(); }
///// <summary> ///// Test a custom simple hold strategy. ///// </summary> //private void btnTestCustomSimpleHold_Click(object sender, EventArgs e) //{ // Tuple<decimal, TickList> result; // decimal change; // int holdtime; // bool changeerror = !decimal.TryParse(txtChange.Text, out change); // bool holderror = !int.TryParse(txtHoldFor.Text, out holdtime); // bool relative = chkRelative.Checked; // String name = "SimpleH(" + txtChange.Text + ","; // if (relative) // { // name += "rel,"; // change *= (decimal)0.01; // } // else { name += "abs,"; } // name += txtHoldFor.Text + "," + cmbDayYearMonth.Text + ")"; // switch (cmbDayYearMonth.Text) // { // case "Days": holdtime *= 24; break; // case "Weeks": holdtime *= 24 * 7; break; // // this is not completely correct, not all months are 30 days // case "Months": holdtime *= 24 * 7 * 30; break; // } // if (!changeerror && !holderror) // { // result = BackTest.SimpleHoldStrategy(valuedata, webdata, // relative, change, holdtime); // MessageBox.Show("Remaining value: " + result.Item1, "Finished", // MessageBoxButtons.OK, MessageBoxIcon.Information); // addToChart(result.Item2, name, true, chart1); // lstResults.Items.Add(name + ", " + result.Item1); // } // if (changeerror) // { // MessageBox.Show("Enter a valid change value"); // } // if (holderror) // { // MessageBox.Show("Enter a valid hold time value"); // } //} /// <summary> /// Add some data to the chart. /// </summary> /// <param name="ticklist">A TickList containing the values to be added.</param> /// <param name="legend">The string to be displayed in the legend.</param> /// <param name="piecewise">If true, every two other points will be connected, the /// points in between will be left unconnected: 0---1 2---3 etc.</param> private void addToChart(TickList ticklist, String name, bool piecewise, Chart c) { if (c.Series.Contains(c.Series.FindByName(name))) { name += "1"; } if (piecewise) { Series points = new Series { Name = name, ChartType = SeriesChartType.Point, XValueType = ChartValueType.DateTime }; Series line = new Series { Name = name + "_line", ChartType = SeriesChartType.Line, XValueType = ChartValueType.DateTime, IsVisibleInLegend = false }; c.Series.Add(points); c.Series.Add(line); foreach (Tick t in ticklist.getList()) { points.Points.AddXY(t.getDate(), t.getValue()); } for (int i = 0; i < ticklist.getList().Count; i += 2) { int p0 = line.Points.AddXY(ticklist.getList()[i].getDate(), ticklist.getList()[i].getValue()); int p1 = line.Points.AddXY(ticklist.getList()[i + 1].getDate(), ticklist.getList()[i + 1].getValue()); line.Points[p0].Color = Color.Transparent; } } else { Series line = new Series { Name = name, ChartType = SeriesChartType.Line, XValueType = ChartValueType.DateTime, IsVisibleInLegend = true }; c.Series.Add(line); foreach (Tick t in ticklist.getList()) { line.Points.AddXY(t.getDate(), t.getValue()); } } }
/// <summary> /// Calculate the absolute differences between each successive tick. /// Each date is the date at which the difference has been observed, /// so the b in "a - b". /// </summary> /// <returns>A TickList containing the dates at which the differences /// have been observed, and the differences.</returns> public TickList AbsoluteDifferences() { TickList returnlist = new TickList(); for (int i = 1; i < list.Count; i++) { DateTime observeddate = list[i].getDate(); decimal difference = list[i].getValue() - list[i - 1].getValue(); returnlist.Add(new Tick(observeddate, difference)); } return(returnlist); }
/// <summary> /// Calculate the relative differences between each successive tick. /// This means each absolute difference is scaled by the original value. /// For example from 10 to 8 the absolute difference is -2, the relative /// difference is -2/10 = 0.2. /// </summary> /// <returns>A TickList containing the dates at which the differences /// have been observed, and the differences.</returns> public TickList RelativeDifferences() { TickList returnlist = new TickList(); List <Tick> absolutelist = this.AbsoluteDifferences().getList(); for (int i = 0; i < absolutelist.Count; i++) { DateTime observeddate = list[i].getDate(); decimal relativedifference = absolutelist[i].getValue() / list[i].getValue(); returnlist.Add(new Tick(observeddate, relativedifference)); } return(returnlist); }
private void btnSearchWeb_Click(object sender, EventArgs e) { //ProgressForm progress = new ProgressForm(); prgbarLoadStream.Style = ProgressBarStyle.Marquee; String query = txtSearchString.Text; switch (cmbProviders.SelectedIndex) { case 0: GoogleTrends g = new GoogleTrends(); toAdd = g.Download(query); toAdd = new LiveTickList(g, query, toAdd); break; default: break; } showInPreviewChart(toAdd, "Google: " + query); }
/// <summary> /// Add some data to the chart for previewing. /// </summary> /// <param name="ticklist">A TickList containing the values to be added. /// </param> private void showInPreviewChart(TickList ticklist, String name, Chart c) { c.Series.Clear(); Series line = new Series { Name = name, ChartType = SeriesChartType.Line, XValueType = ChartValueType.DateTime, IsVisibleInLegend = true }; c.Series.Add(line); foreach (Tick t in ticklist.getList()) { line.Points.AddXY(t.getDate(), t.getValue()); } }
private void dgridStreams_CellContentClick(object sender, DataGridViewCellEventArgs e) { //Logger.Log("Clicked column: " + e.ColumnIndex); if (e.ColumnIndex == 3) { bool display = (bool)dgridStreams.Rows[e.RowIndex]. Cells[e.ColumnIndex].EditedFormattedValue; TickList selectedlist = (TickList)dgridStreams. Rows[e.RowIndex].DataBoundItem; if (display) { addToChart(selectedlist, selectedlist.name, false, chtStreams); } else { removeFromChart(selectedlist.name, chtStreams); } } }
/// <summary> /// A simple hold strategy. /// When the value of the web data has (absolutely or relatively), increased /// by a certain number or percentage, the asset is held for the specified holdtime. /// </summary> /// <param name="valuedata">A TickList containing the value data.</param> /// <param name="webdata">A TickList containing the Google search data.</param> /// <param name="relative">If true, the change is interpreted as relative change. /// Otherwise, the change is absolute.</param> /// <param name="change">A number representing the change treshold.</param> /// <param name="holdtime">The time for which to hold the asset in hours. /// (this might change into the future when testing high-frequency strategies).</param> /// <returns>A touple containing: a decimal representing the remaing value /// after using this strategy. A TickList containing the buy- and -sell /// values and prices.</returns> public static Tuple <decimal, TickList> SimpleHoldStrategy(TickList valuedata, TickList webdata, bool relative, decimal change, int holdtime) { decimal value = 1; TickList portfolio = new TickList(); TickList absticklist = webdata.AbsoluteDifferences(); List <Tick> absdif = absticklist.getList(); TickList relticklist = webdata.RelativeDifferences(); List <Tick> reldif = relticklist.getList(); for (int i = 0; i < reldif.Count && i != -1;) { if ((relative && reldif[i].getValue() > change) || (!relative && absdif[i].getValue() > change)) { DateTime buydate = reldif[i].getDate(); DateTime selldate = buydate.AddHours(holdtime); try { decimal buyprice = valuedata.valueAt(buydate); decimal sellprice = valuedata.valueAt(selldate); value *= sellprice / buyprice; portfolio.Add(new Tick(buydate, buyprice)); portfolio.Add(new Tick(selldate, sellprice)); } catch (InvalidOperationException e) { MessageBox.Show(e.Message); } i = relticklist.findDate(selldate); } else { i++; } } return(Tuple.Create(value, portfolio)); }
public void Add(TickList l) { ticklists.Add(l); }
public Optimize(TickList cause, TickList effect) { InitializeComponent(); this.cause = cause; this.effect = effect; }
public void update() { TickList fetched = provider.Download(query); list.Union <Tick>(fetched.list); }