| Overall Statistics |
|
Total Trades 6218 Average Win 1.91% Average Loss -2.05% Compounding Annual Return 36.560% Drawdown 75.000% Expectancy 0.081 Net Profit 4546.706% Sharpe Ratio 0.846 Probabilistic Sharpe Ratio 12.534% Loss Rate 44% Win Rate 56% Profit-Loss Ratio 0.93 Alpha -0.014 Beta 0.996 Annual Standard Deviation 0.424 Annual Variance 0.179 Information Ratio -0.684 Tracking Error 0.023 Treynor Ratio 0.36 Total Fees $114193.29 Estimated Strategy Capacity $2600000.00 Lowest Capacity Asset SPY R735QTJ8XC9X |
namespace QuantConnect.Algorithm.CSharp
{
public class UPROSim : QCAlgorithm
{
private decimal _lastBenchmarkValue;
private decimal _benchmarkPerformance;
private const string EquityToLeverage = "SPY";
private const string BenchmarkEquity = "UPRO";
private const decimal LeverageFactor = 3.0m;
public override void Initialize()
{
SetStartDate(2009, 7, 1);
SetCash(100000);
var spy = AddEquity(EquityToLeverage, Resolution.Minute);
spy.SetFeeModel(new ExpenseRatioFeeModel(this));
spy.SetLeverage(LeverageFactor);
AddEquity(BenchmarkEquity, Resolution.Minute);
SetBenchmark(BenchmarkEquity);
// Inital benchmark value scaled to match our portfolio
_benchmarkPerformance = Portfolio.TotalPortfolioValue;
}
public override void OnData(Slice data)
{
if (!Portfolio.Invested)
{
SetHoldings(EquityToLeverage, LeverageFactor);
}
}
public override void OnEndOfDay(string symbol)
{
// store the current benchmark close price
var benchmark = Securities["UPRO"].Price;
Liquidate(symbol);
// Calculate the performance of our benchmark and update our benchmark value for plotting
if (_lastBenchmarkValue != default)
{
_benchmarkPerformance = _benchmarkPerformance * ( benchmark / _lastBenchmarkValue);
}
// store today's benchmark close price for use tomorrow
_lastBenchmarkValue = benchmark;
// Render plots
Plot("UPRO-SIM vs UPRO", "UPRO-SIM", Portfolio.TotalPortfolioValue);
Plot("UPRO-SIM vs UPRO", "UPRO", _benchmarkPerformance);
}
private class ExpenseRatioFeeModel : FeeModel
{
private const decimal ExpenseRatio = 0.0093m;
private const int TradingDaysPerYear = 252;
private QCAlgorithm _algorithm;
public ExpenseRatioFeeModel(QCAlgorithm algorithm)
{
_algorithm = algorithm;
}
public override OrderFee GetOrderFee(OrderFeeParameters parameters)
{
if (parameters.Order.Direction == OrderDirection.Buy)
{
var dailyExpenseRatio = ExpenseRatio / TradingDaysPerYear;
var dailyFee = _algorithm.Portfolio.Cash * dailyExpenseRatio;
return new OrderFee(new CashAmount(Math.Abs(dailyFee), "USD"));
}
else
{
return OrderFee.Zero;
}
}
}
}
}