analytics_tablesLibrary "analytics_tables"
๐ Description
This library provides the implementation of several performance-related statistics and metrics, presented in the form of tables.
The metrics shown in the afforementioned tables where developed during the past years of my in-depth analalysis of various strategies in an atempt to reason about the performance of each strategy.
The visualization and some statistics where inspired by the existing implementations of the "Seasonality" script, and the performance matrix implementations of @QuantNomad and @ZenAndTheArtOfTrading scripts.
While this library is meant to be used by my strategy framework "Template Trailing Strategy (Backtester)" script, I wrapped it in a library hoping this can be usefull for other community strategy scripts that will be released in the future.
๐ค How to Guide
To use the functionality this library provides in your script you have to import it first!
Copy the import statement of the latest release by pressing the copy button below and then paste it into your script. Give a short name to this library so you can refer to it later on. The import statement should look like this:
import jason5480/analytics_tables/1 as ant
There are three types of tables provided by this library in the initial release. The stats table the metrics table and the seasonality table.
Each one shows different kinds of performance statistics.
The table UDT shall be initialized once using the `init()` method.
They can be updated using the `update()` method where the updated data UDT object shall be passed.
The data UDT can also initialized and get updated on demend depending on the use case
A code example for the StatsTable is the following:
var ant.StatsData statsData = ant.StatsData.new()
statsData.update(SideStats.new(), SideStats.new(), 0)
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var statsTable = ant.StatsTable.new().init(ant.getTablePos('TOP', 'RIGHT'))
statsTable.update(statsData)
A code example for the MetricsTable is the following:
var ant.StatsData statsData = ant.StatsData.new()
statsData.update(ant.SideStats.new(), ant.SideStats.new(), 0)
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var metricsTable = ant.MetricsTable.new().init(ant.getTablePos('BOTTOM', 'RIGHT'))
metricsTable.update(statsData, 10)
A code example for the SeasonalityTable is the following:
var ant.SeasonalData seasonalData = ant.SeasonalData.new().init(Seasonality.monthOfYear)
seasonalData.update()
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var seasonalTable = ant.SeasonalTable.new().init(seasonalData, ant.getTablePos('BOTTOM', 'LEFT'))
seasonalTable.update(seasonalData)
๐๏ธโโ๏ธ Please refer to the "EXAMPLE" regions of the script for more advanced and up to date code examples!
Special thanks to @Mrcrbw for the proposal to develop this library and @DCNeu for the constructive feedback ๐.
getTablePos(ypos, xpos)
โโGet table position compatible string
โโParameters:
โโโโ ypos (simple string) : The position on y axise
โโโโ xpos (simple string) : The position on x axise
โโReturns: The position to be passed to the table
method init(this, pos, height, width, positiveTxtColor, negativeTxtColor, neutralTxtColor, positiveBgColor, negativeBgColor, neutralBgColor)
โโInitialize the stats table object with the given colors in the given position
โโNamespace types: StatsTable
โโParameters:
โโโโ this (StatsTable) : The stats table object
โโโโ pos (simple string) : The table position string
โโโโ height (simple float) : The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
โโโโ width (simple float) : The width of the table as a percentage of the charts height. By default, 0 auto-adjusts the width based on the text inside the cells
โโโโ positiveTxtColor (simple color) : The text color when positive
โโโโ negativeTxtColor (simple color) : The text color when negative
โโโโ neutralTxtColor (simple color) : The text color when neutral
โโโโ positiveBgColor (simple color) : The background color with transparency when positive
โโโโ negativeBgColor (simple color) : The background color with transparency when negative
โโโโ neutralBgColor (simple color) : The background color with transparency when neutral
method init(this, pos, height, width, neutralBgColor)
โโInitialize the metrics table object with the given colors in the given position
โโNamespace types: MetricsTable
โโParameters:
โโโโ this (MetricsTable) : The metrics table object
โโโโ pos (simple string) : The table position string
โโโโ height (simple float) : The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
โโโโ width (simple float) : The width of the table as a percentage of the charts width. By default, 0 auto-adjusts the width based on the text inside the cells
โโโโ neutralBgColor (simple color) : The background color with transparency when neutral
method init(this, seas)
โโInitialize the seasonal data
โโNamespace types: SeasonalData
โโParameters:
โโโโ this (SeasonalData) : The seasonal data object
โโโโ seas (simple Seasonality) : The seasonality of the matrix data
method init(this, data, pos, maxNumOfYears, height, width, extended, neutralTxtColor, neutralBgColor)
โโInitialize the seasonal table object with the given colors in the given position
โโNamespace types: SeasonalTable
โโParameters:
โโโโ this (SeasonalTable) : The seasonal table object
โโโโ data (SeasonalData) : The seasonality data of the table
โโโโ pos (simple string) : The table position string
โโโโ maxNumOfYears (simple int) : The maximum number of years that fit into the table
โโโโ height (simple float) : The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
โโโโ width (simple float) : The width of the table as a percentage of the charts width. By default, 0 auto-adjusts the width based on the text inside the cells
โโโโ extended (simple bool) : The seasonal table with extended columns for performance
โโโโ neutralTxtColor (simple color) : The text color when neutral
โโโโ neutralBgColor (simple color) : The background color with transparency when neutral
method update(this, wins, losses, numOfInconclusiveExits)
โโUpdate the strategy info data of the strategy
โโNamespace types: StatsData
โโParameters:
โโโโ this (StatsData) : The strategy statistics object
โโโโ wins (SideStats)
โโโโ losses (SideStats)
โโโโ numOfInconclusiveExits (int) : The number of inconclusive trades
method update(this, stats, positiveTxtColor, negativeTxtColor, negativeBgColor, neutralBgColor)
โโUpdate the stats table object with the given data
โโNamespace types: StatsTable
โโParameters:
โโโโ this (StatsTable) : The stats table object
โโโโ stats (StatsData) : The stats data to update the table
โโโโ positiveTxtColor (simple color) : The text color when positive
โโโโ negativeTxtColor (simple color) : The text color when negative
โโโโ negativeBgColor (simple color) : The background color with transparency when negative
โโโโ neutralBgColor (simple color) : The background color with transparency when neutral
method update(this, stats, buyAndHoldPerc, positiveTxtColor, negativeTxtColor, positiveBgColor, negativeBgColor)
โโUpdate the metrics table object with the given data
โโNamespace types: MetricsTable
โโParameters:
โโโโ this (MetricsTable) : The metrics table object
โโโโ stats (StatsData) : The stats data to update the table
โโโโ buyAndHoldPerc (float) : The buy and hold percetage
โโโโ positiveTxtColor (simple color) : The text color when positive
โโโโ negativeTxtColor (simple color) : The text color when negative
โโโโ positiveBgColor (simple color) : The background color with transparency when positive
โโโโ negativeBgColor (simple color) : The background color with transparency when negative
method update(this)
โโUpdate the seasonal data based on the season and eon timeframe
โโNamespace types: SeasonalData
โโParameters:
โโโโ this (SeasonalData) : The seasonal data object
method update(this, data, positiveTxtColor, negativeTxtColor, neutralTxtColor, positiveBgColor, negativeBgColor, neutralBgColor, timeBgColor)
โโUpdate the seasonal table object with the given data
โโNamespace types: SeasonalTable
โโParameters:
โโโโ this (SeasonalTable) : The seasonal table object
โโโโ data (SeasonalData) : The seasonal cell data to update the table
โโโโ positiveTxtColor (simple color) : The text color when positive
โโโโ negativeTxtColor (simple color) : The text color when negative
โโโโ neutralTxtColor (simple color) : The text color when neutral
โโโโ positiveBgColor (simple color) : The background color with transparency when positive
โโโโ negativeBgColor (simple color) : The background color with transparency when negative
โโโโ neutralBgColor (simple color) : The background color with transparency when neutral
โโโโ timeBgColor (simple color) : The background color of the time gradient
SideStats
โโObject that represents the strategy statistics data of one side win or lose
โโFields:
โโโโ numOf (series int)
โโโโ sumFreeProfit (series float)
โโโโ freeProfitStDev (series float)
โโโโ sumProfit (series float)
โโโโ profitStDev (series float)
โโโโ sumGain (series float)
โโโโ gainStDev (series float)
โโโโ avgQuantityPerc (series float)
โโโโ avgCapitalRiskPerc (series float)
โโโโ avgTPExecutedCount (series float)
โโโโ avgRiskRewardRatio (series float)
โโโโ maxStreak (series int)
StatsTable
โโObject that represents the stats table
โโFields:
โโโโ table (series table) : The actual table
โโโโ rows (series int) : The number of rows of the table
โโโโ columns (series int) : The number of columns of the table
StatsData
โโObject that represents the statistics data of the strategy
โโFields:
โโโโ wins (SideStats)
โโโโ losses (SideStats)
โโโโ numOfInconclusiveExits (series int)
โโโโ avgFreeProfitStr (series string)
โโโโ freeProfitStDevStr (series string)
โโโโ lossFreeProfitStDevStr (series string)
โโโโ avgProfitStr (series string)
โโโโ profitStDevStr (series string)
โโโโ lossProfitStDevStr (series string)
โโโโ avgQuantityStr (series string)
MetricsTable
โโObject that represents the metrics table
โโFields:
โโโโ table (series table) : The actual table
โโโโ rows (series int) : The number of rows of the table
โโโโ columns (series int) : The number of columns of the table
SeasonalData
โโObject that represents the seasonal table dynamic data
โโFields:
โโโโ seasonality (series Seasonality)
โโโโ eonToMatrixRow (map)
โโโโ numOfEons (series int)
โโโโ mostRecentMatrixRow (series int)
โโโโ balances (matrix)
โโโโ returnPercs (matrix)
โโโโ maxDDs (matrix)
โโโโ eonReturnPercs (array)
โโโโ eonCAGRs (array)
โโโโ eonMaxDDs (array)
SeasonalTable
โโObject that represents the seasonal table
โโFields:
โโโโ table (series table) : The actual table
โโโโ headRows (series int) : The number of head rows of the table
โโโโ headColumns (series int) : The number of head columns of the table
โโโโ eonRows (series int) : The number of eon rows of the table
โโโโ seasonColumns (series int) : The number of season columns of the table
โโโโ statsRows (series int)
โโโโ statsColumns (series int) : The number of stats columns of the table
โโโโ rows (series int) : The number of rows of the table
โโโโ columns (series int) : The number of columns of the table
โโโโ extended (series bool) : Whether the table has additional performance statistics
