Hello!
All fields from the C2ExplorerDB.c2ex_publicsystems
database table are accessible from the IC2TradingSystem interface now.
A documentation is not yet updated - a list of fields is here:
See https://collective2.com/c2explorer_help/html/T_C2ExplorerDB_c2ex_publicsystems.htm
It means you can modify the Tail Ratio code like this (for example):
object trdata = new
{
Name = system.Name,
Id = system.Id,
Started = system.Started,
Trades = system.Trades.Count(),
Percentile5 = Math.Round((decimal)percentile5, 4),
Percentile95 = Math.Round((decimal)percentile95, 4),
TailRatio = Math.Round((decimal)tailRatio, 2),
// --------------- New fields -------------
AvgWin = system.AvgWin,
AvgLoss = system.AvgLoss,
WinPercent = (decimal)Math.Round((double)system.NumWins / (double)system.NumTrades , 4) * 100
};
Other info (Sharpe,…) is not so easy and need to be added from the database.
Here is an example how to get Sharpe:
TABLE = from item in C2STATS
where systems.Contains(item.SystemId)
where item.StatName == "jSharpe"
select item;
Based on this example, you can add the following code:
// Get Sharpe
var sharpe = (from item in C2STATS
where item.SystemId == system.Id
where item.StatName == "jSharpe"
select item.StatValueVal).FirstOrDefault();
and use the result in object trdata = new { ... }
Here is a new code with those modifications:
// Your systems selection.
// For example - last week most popular systems.
var popularLastWeek = from stat in C2STATS
where stat.StatName == "popular10080"
orderby stat.StatValueVal descending
select stat.SystemId;
// Get 10 most popular systems Ids
Int64[] systems = popularLastWeek.Take(10).ToArray();
// A list for results.
List<object> result = new List<object>();
// And something for fun.
IColumnChart chart = new ColumnChart("Tail Ratio - last week most popular systems", "Systems", "Tail Ratio");
foreach (var systemId in systems)
{
// Get a system for Name, Started date, ...
IC2TradingSystem system = GetC2SYSTEM(systemId);
// Create a TimeSheet object. It calculates daily returns.
ITimeSheet timeSheet = TimeSheetFactory(systemId, TimeInterval.Day, EquityType.Rets);
// Let TimeSheet run for this system.
timeSheet.EquitiesSheet();
// Get the Returns column for statistics.
Series<DateTime, Double> returnsColumn = timeSheet.GetColumnAsDouble(systemId, EquityType.Rets);
// Percentiles
double percentile5 = Statistics.Percentile(returnsColumn.Values, 5);
double percentile95 = Statistics.Percentile(returnsColumn.Values, 95);
double tailRatio = 0.0;
if (percentile5 != 0.0)
{
// Calculate Tail Ratio
tailRatio = percentile95 / Math.Abs(percentile5);
// Get Sharpe
var sharpe = (from item in C2STATS
where item.SystemId == system.Id
where item.StatName == "jSharpe"
select item.StatValueVal).FirstOrDefault();
// Prepare data for output
object trdata = new
{
Name = system.Name,
Id = system.Id,
Started = system.Started,
Trades = system.Trades.Count(),
Percentile5 = Math.Round((decimal)percentile5, 4),
Percentile95 = Math.Round((decimal)percentile95, 4),
TailRatio = Math.Round((decimal)tailRatio, 2),
AvgWin = system.AvgWin,
AvgLoss = system.AvgLoss,
WinPercent = (decimal)Math.Round((double)system.NumWins / (double)system.NumTrades , 4) * 100,
Sharpe = (decimal)sharpe
};
// Add to the results list
result.Add(trdata);
// add to the chart
chart.Add(system.Name, Math.Round((decimal)tailRatio, 2));
}
}
CHART = chart;
HR();
H3 = "Tail Ratio - last week most popular systems";
TABLE = result;
// H3 = "Daily returns visualized";
// TABLE = GetEquitiesSheet(systems, TimeInterval.Day, EquityType.Rets);