Back

Tail Ratio

Hello, I would like to implement a statistic to show the Tail Ratio.
To psudocode is the following:

// Get all the daily profit returns as a %
// orderedDailyProfits = order them from lowest to highest.
// get 5% of the number of days. (250 days would = 12.5 ~ 13
// get SUM(orderedDailyProfits[0:13]) / SUM(orderedDailyProfits[-13:-1])

So my question is, how can I get a list of all the daily returns? : -)

Update Backtest








Check this implementation:

using System;
using System.Collections.Generic;
using MathNet.Numerics.Statistics;
using QuantConnect.Indicators;

namespace QuantConnect.Algorithm.CSharp
{
public class TailRatioPseudoCode : QCAlgorithm
{
private List<double> dailyResults;
private LogReturn equityLogReturn;

public override void Initialize()
{
equityLogReturn = new LogReturn(1);
dailyResults = new List<double>();
}

public override void OnEndOfDay()
{
equityLogReturn.Update(new IndicatorDataPoint
{
Time = Time.Date,
Value = Portfolio.TotalPortfolioValue
});
dailyResults.Add((double) equityLogReturn.Current.Value);
}

public override void OnEndOfAlgorithm()
{
var tailRatio = dailyResults.Percentile(95) / Math.Abs(dailyResults.Percentile(5));
}
}
}

 

2

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed