| Overall Statistics |
|
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 1.972 Tracking Error 0.505 Treynor Ratio 0 Total Fees $0.00 |
using System;
using System.Collections.Concurrent;
using System.Linq;
using QuantConnect.Data.Market;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Indicators;
namespace QuantConnect.Algorithm.CSharp
{
public class CoarseFundamentalTest : QCAlgorithm
{
private const decimal TargetPercent = 0.1m;
private SecurityChanges _changes = SecurityChanges.None;
// holds our coarse fundamental indicators by symbol
private readonly ConcurrentDictionary<Symbol, SelectionData> _averages = new ConcurrentDictionary<Symbol, SelectionData>();
List<Symbol> _invested = new List<Symbol>();
// class used to improve readability of the coarse selection function
private class SelectionData
{
public readonly ExponentialMovingAverage Fast;
public readonly ExponentialMovingAverage Slow;
public SelectionData()
{
Fast = new ExponentialMovingAverage(1);
Slow = new ExponentialMovingAverage(5);
}
// computes an object score of how much large the fast is than the slow
public decimal ScaledDelta
{
get { return (Fast - Slow)/((Fast + Slow)); }
}
// updates the EMA1 and EMA5 indicators, returning true when they're both ready
public bool Update(DateTime time, decimal value)
{
return Fast.Update(time, value) && Slow.Update(time, value);
}
}
public override void Initialize()
{
UniverseSettings.Resolution = Resolution.Hour;
UniverseSettings.ExtendedMarketHours = false;
//UniverseSettings.FillForward = true;
//UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
SetStartDate(2020, 6, 9);
SetEndDate(2020, 6, 11);
SetCash(1000);
AddUniverse(CoarseFilterFunction);
}
IEnumerable<Symbol> CoarseFilterFunction(IEnumerable<CoarseFundamental> coarse) {
var _symbols = coarse
.Where (x => x.Symbol.Value == "TSLA")
.Where(x =>
{
var history = History(x.Symbol, 2, Resolution.Daily);
var close = history.FirstOrDefault()?.Close;
var avg = _averages.GetOrAdd(x.Symbol, sym => new SelectionData());
if (x.Symbol.Value == "TSLA") {
Debug("====T====");
//Debug($"'Current price': {x.Price.ToString()}"); not split adjusted, but equals 0dayago close anyway
Debug($"'1dayago close': {history.ElementAt(0).Close.ToString()}");
Debug($"'1dayago open': {history.ElementAt(0).Open.ToString()}");
Debug($"'0dayago close': {history.ElementAt(1).Close.ToString()}");
Debug($"'0dayago open': {history.ElementAt(1).Open.ToString()}");
Debug($"1 day EMA: {avg.Fast}");
var gapup = history.ElementAt(1).Open / history.ElementAt(0).Open;
gapup = Math.Round((gapup - 1) * 100);
Debug($"Gap up: {gapup}%");
Debug("---------");
}
return false;
})
.Select(x => x.Symbol);
return _symbols;
}
}
}