Keep track of the Annualized Rate of Return loss metric, in any given context.
Annualized rate of return is the equivalent ROI scaled to one year.

In other words, it is the equivalent annual return received over a given period.

The formula:

annualized rate of return = (((investment + profits) / investments) ^ (365 / days)) - 1

In the context of the episode base asset and episode quoted asset, the calculation is done relative to the corresponding assets, and the overall context.

The formulas:

tradingEngine.current.episode.episodeBaseAsset.annualizedRateOfReturn.value = 
((( tradingEngine.current.episode.episodeBaseAsset.beginBalance.value +
tradingEngine.current.episode.episodeBaseAsset.profitLoss.value ) / 
tradingEngine.current.episode.episodeBaseAsset.beginBalance.value) ^
(365 / tradingEngine.current.episode.episodeStatistics.days.value)) - 1

tradingEngine.current.episode.episodeQuotedAsset.annualizedRateOfReturn.value = 
((( tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value +
tradingEngine.current.episode.episodeQuotedAsset.profitLoss.value ) / 
tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value) ^
(365 / tradingEngine.current.episode.episodeStatistics.days.value)) - 1

The JavaScript code:

tradingEngine.current.episode.episodeBaseAsset.annualizedRateOfReturn.value = 
Math.pow(
             ( tradingEngine.current.episode.episodeBaseAsset.beginBalance.value +
             tradingEngine.current.episode.episodeBaseAsset.profitLoss.value ) / 
             tradingEngine.current.episode.episodeBaseAsset.beginBalance.value
             , 
             (365 / tradingEngine.current.episode.episodeStatistics.days.value)
        ) - 1

tradingEngine.current.episode.episodeQuotedAsset.annualizedRateOfReturn.value = 
Math.pow(
             ( tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value +
             tradingEngine.current.episode.episodeQuotedAsset.profitLoss.value ) / 
             tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value
             , 
             (365 / tradingEngine.current.episode.episodeStatistics.days.value)
        ) - 1

In the context of the episode statistics, the calculation is done using the consolidated balance, as explained in the profit loss definition.

The JavaScript code:

tradingEngine.current.episode.episodeStatistics.annualizedRateOfReturn.value =
Math.pow(
            (
                tradingEngine.current.episode.episodeBaseAsset.beginBalance.value * 
                tradingEngine.current.episode.beginRate.value +
                tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value +
                tradingEngine.current.episode.episodeBaseAsset.profitLoss.value +
                tradingEngine.current.episode.episodeQuotedAsset.profitLoss.value
            ) / 
            (
                tradingEngine.current.episode.episodeBaseAsset.beginBalance.value * 
                tradingEngine.current.episode.beginRate.value +
                tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value 
            ) 
        , 
            (
                365 / tradingEngine.current.episode.episodeStatistics.days.value
            ) 
        ) - 1