TimeSheet |
TimeSheet is like a spreadsheet containing data aligned to time slots. It's main purpose is to align data of several trading systems together, but it works well for a single system too.
We think it will be the main object for many different calculations over time. For now, here are some examples how to use it as a source for TABLE and CHART.
This topic contains the following sections:
This code shows a table with all currently available data of one trading system.
/* This example shows monthly data: - Full equity including commissions and subscription fees [Eq] - Raw equity without commissions and subscription fees [Raw] - Equity differences between two consecutive points in dollars [Diffs] - Returns between two consecutive points in percents [Rets] - Current equity minus a starting capital [Profit] - Rate-of-Change. Equity divided by the starting capital [ROC] - Commissions fees [Comm] - Subscription fees [Fees] - Max. margin used [mrgn] Disclaimer: The system used in this example was selected just because it has a short name and we can see all columns headers easily. Data shown in this example can contain errors.*/ long systemId = 83853157; // AT Pro TABLE = GetEquitiesSheet(systemId, TimeInterval.Month, EquityType.Equity | EquityType.Raw | EquityType.Commiss | EquityType.SubsFees | EquityType.Diff | EquityType.Rets | EquityType.ROC | EquityType.Profit | EquityType.MarginUsed );
This code shows a table with selected data of three trading systems.
/* This example shows several systems data in one TimeSheet and also different time aggregations. Disclaimer: The systems used in this example were selected randomly. Data shown in this example can contain errors.*/ Int64[] systems = new Int64[] { 46106678, // Bob Dylan 90325773, // Ascendatnt 84690231 // Genefish Hong Kong () }; H3 = "Yearly returns"; TABLE = GetEquitiesSheet(systems, TimeInterval.Year, EquityType.Rets); H3 = "Monthly returns"; TABLE = GetEquitiesSheet(systems, TimeInterval.Month, EquityType.Rets); H3 = "Combinations. For example Equity and Commissions columns for each system annually."; TABLE = GetEquitiesSheet(systems, TimeInterval.Year, EquityType.Equity | EquityType.Commiss);
This code shows one possible way how to use data generated by the TimeSheet object.
/* Show me interesting system data in one chart: - Equity - Raw Equity - Commissions - Subscription Fees - Max. Margin Used Disclaimer: The system used in this example was selected randomly. Data shown in this example can contain errors.*/ Int64 systemId = 83853157; // AT Pro // Create a TimeSheet object. Define desired data. ITimeSheet timeSheet = TimeSheetFactory( systemId, TimeInterval.Month, EquityType.Equity | EquityType.Raw | EquityType.Commiss | EquityType.SubsFees | EquityType.MarginUsed ); // Let TimeSheet run timeSheet.EquitiesSheet(); // Extract columns data. var eq = timeSheet.GetColumn(systemId, EquityType.Equity); var raw = timeSheet.GetColumn(systemId, EquityType.Raw); var comm = timeSheet.GetColumn(systemId, EquityType.Commiss); var fees = timeSheet.GetColumn(systemId, EquityType.SubsFees); var mrgn = timeSheet.GetColumn(systemId, EquityType.MarginUsed); // Create a chart object ITimeSeriesChart timeSeriesChart = new TimeSeriesChart(); timeSeriesChart.Name = "AT Pro"; // Add data to the chart timeSeriesChart.Add(eq, "Equity", Color.Green); timeSeriesChart.Add(raw, "Raw", Color.Gray); timeSeriesChart.Add(comm, "Commissions", Color.Red); timeSeriesChart.Add(fees, "Fees", Color.Blue); timeSeriesChart.Add(mrgn, "Max. margin", Color.Brown, ChartTypes.Column); // Max. monthly margin // Show the chart CHART = timeSeriesChart; HR(); // Data in the table format TABLE = timeSheet.GetEquitiesSheet();
Do not forget that you can switch-off some lines to see other lines better.
This code shows how to use data from TimeSheet objects.
Charts show equities and commissions for selected commissions plans.
/* This example shows trading system equities using different commissions plans. Disclaimer: The system used in this example was selected randomly. Data shown in this example can contain errors.*/ Int64 systemId = 83853157; // Create a TimeSheet object using optionsXpress commissions plan. ITimeSheet timeSheetOX = TimeSheetFactory(systemId, TimeInterval.Month, EquityType.Equity | EquityType.Commiss, "ox"); // Create a TimeSheet object using InteractiveBrokers commissions plan. ITimeSheet timeSheetIB = TimeSheetFactory(systemId, TimeInterval.Month, EquityType.Equity | EquityType.Commiss, "ib"); // Create a TimeSheet object using tradeMonster commissions plan. ITimeSheet timeSheetTM = TimeSheetFactory(systemId, TimeInterval.Month, EquityType.Equity | EquityType.Commiss, "tm"); // Let TimeSheets run timeSheetOX.EquitiesSheet(); timeSheetIB.EquitiesSheet(); timeSheetTM.EquitiesSheet(); // ------- Equities graph -------- // Extract columns data. var equityOX = timeSheetOX.GetColumn(systemId, EquityType.Equity); var equityIB = timeSheetIB.GetColumn(systemId, EquityType.Equity); var equityTM = timeSheetTM.GetColumn(systemId, EquityType.Equity); // Create a chart object ITimeSeriesChart eqChart = new TimeSeriesChart(); eqChart.Name = "System equities using OX, IB, TM commissions"; // Add data to the chart eqChart.Add(equityOX, "OX", Color.Red); eqChart.Add(equityIB, "IB", Color.Green); eqChart.Add(equityTM, "TM", Color.Blue); // Show the chart CHART = eqChart; // ------- Commissions graph -------- // Create a chart object ITimeSeriesChart commissChart = new TimeSeriesChart(); commissChart.Name = "OX, IB, TM commissions"; // Add data to the chart commissChart.Add(timeSheetOX.GetColumn(systemId, EquityType.Commiss), "OX", Color.Red); commissChart.Add(timeSheetIB.GetColumn(systemId, EquityType.Commiss), "IB", Color.Green); commissChart.Add(timeSheetTM.GetColumn(systemId, EquityType.Commiss), "TM", Color.Blue); // Show the chart CHART = commissChart;
This code shows how to use data from TimeSheet objects.
Generated chart shows a naive
average of two trading systems equities.
/* Construct an average of equities of two trading systems. Remark: Do not forget that this is a "naive" approach. Commissions and subscription fees included in net equities can't be averaged. Disclaimer: The systems used in this example were selected randomly. Data shown in this example can contain errors.*/ long systemA = 65806998; long systemB = 75976336; // Create a timesheet with default arguments ITimeSheet timeSheet = TimeSheetFactory(new long[] { systemA, systemB }); // Let the timeSheet run timeSheet.EquitiesSheet(); // Extract net equities var eqA = timeSheet.GetColumnAsDouble(systemA, EquityType.Equity); var eqB = timeSheet.GetColumnAsDouble(systemB, EquityType.Equity); // Use data var seriesAvg = (eqA + eqB) / 2; // Create a chart object ITimeSeriesChart timeSeriesChart = new TimeSeriesChart(); timeSeriesChart.Name = String.Format("Naive average of {0} and {1}", systemA, systemB); // Add data timeSeriesChart.Add(eqA, systemA.ToString(), Color.SeaGreen); timeSeriesChart.Add(eqB, systemB.ToString(), Color.MediumSeaGreen); timeSeriesChart.Add(seriesAvg, "Average", Color.Red); // Enjoy! CHART = timeSeriesChart;
This code shows how to use data from TimeSheet objects.
Generated chart shows a naive
linear combinations of two trading systems equities.
Why naive? Because commissions and subscription fees can't be fractional.
/* Generate equities combinations for the portfolio of two trading systems. Remark: Be carefull when using fractions of the net equities. Commissions and subscription fees included in net equities can't be scaled down. Disclaimer: The systems used in this example were selected randomly. Data shown in this example can contain errors.*/ long systemA = 65806998; long systemB = 75976336; // Create a timesheet with default arguments ITimeSheet timeSheet = TimeSheetFactory(new long[] { systemA, systemB }); // Let the timeSheet run timeSheet.EquitiesSheet(); // Extract net equities var eqA = timeSheet.GetColumnAsDouble(systemA, EquityType.Equity); var eqB = timeSheet.GetColumnAsDouble(systemB, EquityType.Equity); // Create a chart object ITimeSeriesChart timeSeriesChart = new TimeSeriesChart(); timeSeriesChart.Name = "Naive Portfolio Games"; // Add original systems equities timeSeriesChart.Add(eqA, systemA.ToString(), Color.SeaGreen); timeSeriesChart.Add(eqB, systemB.ToString(), Color.MediumSeaGreen); int N = 1; // A number of steps double step = 0.1; for (double i = 0.1; i < N - step; i = i + step) { // Equities combination var combination = i * eqA + (N - i) * eqB; // Prepare name and color String name = String.Format("{0}-{1}", i, N - i); Color color = Color.FromArgb(255, 0, (int)(16 * 10 * i)); // Add combination to the chart timeSeriesChart.Add(combination, name, color); } // Enjoy! CHART = timeSeriesChart;