| 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 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
namespace QuantConnect.Algorithm.CSharp
{
public class BasicTemplateFrameworkAlgorithm : QCAlgorithmFramework
{
List<string> top5 = new List<string>();
public override void Initialize()
{
SetStartDate(2019, 1, 28); //Set Start Date
SetEndDate(2019, 1, 30); //Set End Date
SetCash(100000); //Set Strategy Cash
// Coarse Fine Universe Selection Models.
SetUniverseSelection(new FineFundamentalUniverseSelectionModel(CoarseSelectionFunction, FineSelectionFunction));
SetAlpha(new CustomAlphaModel());
SetPortfolioConstruction(new NullPortfolioConstructionModel());
SetExecution(new ImmediateExecutionModel());
//Set your own execution model to place approriately weighted orders
//SetExecution(new CustomExecutionModel());
SetRiskManagement(new MaximumDrawdownPercentPerSecurity(0.05m));
}
public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
{
var numberOfSymbolsCoarse = 100;
// select only symbols with fundamental data and sort descending by daily dollar volume
var sortedByDollarVolume = coarse
.Where(x => x.HasFundamentalData)
.OrderByDescending(x => x.DollarVolume);
// take the top entries from our sorted collection
var top5 = sortedByDollarVolume.Take(numberOfSymbolsCoarse);
// we need to return only the symbol objects
return top5.Select(x => x.Symbol);
}
// sort the data by P/E ratio and take the top 'numberOfSymbolsFine'
public IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine)
{
var numberOfSymbolsFine = 5;
// sort descending by P/E ratio
var sortedByPeRatio = fine.OrderByDescending(x => x.ValuationRatios.PERatio);
// take the top entries from our sorted collection
var topFine = sortedByPeRatio.Take(numberOfSymbolsFine);
// we need to return only the symbol objects
List<string> temptop5 = new List<string>();
var temp = topFine.Select(x => x.Symbol);
foreach (String s in temp)
{
string str = s.Substring(0,3);
Log("adding " + s.Substring(0,3));
temptop5.Add(s.Substring(0,3));
}
top5 = temptop5;
return topFine.Select(x => x.Symbol);
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
if (orderEvent.Status.IsFill())
{
// Debug($"Purchased Stock: {orderEvent.Symbol}");
}
}
}
class CustomAlphaModel : AlphaModel
{
private DateTime _date;
/// <summary>
/// Create a new leveraged ETF rebalancing alpha
/// </summary>
/// <summary>
/// Scan to see if the returns are greater than 1% at 2.15pm to emit an insight.
/// </summary>
public override IEnumerable<Insight> Update(QCAlgorithmFramework algorithm, Slice data)
{
// Initialize:
var insights = new List<Insight>();
// You can evaluation data in this method and access securities information
foreach (String symbol in algorithm.Securities.Keys)
{
algorithm.Log("Top5 symbol: " + symbol.ToString());
}
return insights;
}
}
//class CustomExecutionModel : ExecutionModel
//{
// Create a custom execution model to execute tradingg code
// based on insights
//}
}