| Overall Statistics |
|
Total Trades 286 Average Win 2.09% Average Loss -2.01% Compounding Annual Return -0.403% Drawdown 54.800% Expectancy 0.020 Net Profit -3.050% Sharpe Ratio 0.07 Loss Rate 50% Win Rate 50% Profit-Loss Ratio 1.04 Alpha -0.007 Beta 0.457 Annual Standard Deviation 0.176 Annual Variance 0.031 Information Ratio -0.16 Tracking Error 0.185 Treynor Ratio 0.027 Total Fees $3290.47 |
using QuantConnect.Indicators;
using System;
using System.Collections.Concurrent;
namespace QuantConnect
{
public class VolatilityEffect : QCAlgorithm
{
public readonly ConcurrentDictionary<Symbol, StandardDeviation> _symbolsData = new ConcurrentDictionary<Symbol, StandardDeviation>();
public int _month = 0;
public override void Initialize()
{
// backtest parameters
UniverseSettings.Leverage = 2.0m;
UniverseSettings.Resolution = Resolution.Daily;
SetStartDate(2005, 5, 1);
SetEndDate(2013, 1, 1);
SetCash(100000);
AddUniverse( coarse =>
{
return
(
from cf in coarse
let std = _symbolsData.GetOrAdd(cf.Symbol, sym => new StandardDeviation(600))
where std.Update(cf.EndTime,cf.Price)
where cf.Price > 10.0m
orderby cf.DollarVolume descending
select cf.Symbol
).Take(100);
}
);
}
public override void OnData(Slice data)
{
if(Time.Month != _month)
{
_month = Time.Month;
foreach(var sym in Portfolio.Keys)
{
Liquidate(sym);
}
var leastVolatile = (from _symbol in data.Keys
orderby _symbolsData[_symbol]
select _symbol).Take(2);
foreach(var entry in leastVolatile)
{
SetHoldings(entry,0.5);
}
}
}
}
}