| Overall Statistics |
|
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 11.198% Drawdown 5.400% Expectancy 0 Net Profit 0% Sharpe Ratio 1.759 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.111 Beta -0.02 Annual Standard Deviation 0.061 Annual Variance 0.004 Information Ratio -0.732 Tracking Error 0.127 Treynor Ratio -5.26 Total Fees $1.81 |
namespace QuantConnect
{
/*
* Shows how to use the scheduled events feature to run code
* every day at a specific time
*/
public class BasicTemplateAlgorithm : QCAlgorithm
{
public const string Symbol = "SPY";
public Security Security;
public ExponentialMovingAverage ema;
//Initialize the data and resolution you require for your strategy:
public override void Initialize()
{
SetStartDate(2013, 01, 01);
SetEndDate(2015, 01, 01);
AddSecurity(SecurityType.Equity, Symbol, Resolution.Minute);
// save off our security to reference the price later
Security = Securities[Symbol];
// we'll build an ema of open/close prices (not sure what it's good for!)
ema = new ExponentialMovingAverage(14);
PlotIndicator(Symbol, ema, Identity(Symbol, Resolution.Hour));
// schedules the 'OnFiveMinutesAfterMarketOpen' function to run 5 minutes after the Symbol's market open
Schedule.On(DateRules.EveryDay(Symbol), TimeRules.AfterMarketOpen(Symbol, 5/*minutes after open*/), OnFiveMinutesAfterMarketOpen);
// schedules the 'OnFiveMinutesBeforeMarketClose' function to run 5 minutes before the Symbol's market close
Schedule.On(DateRules.EveryDay(Symbol), TimeRules.BeforeMarketClose(Symbol, 5/*minutes before close*/), OnFiveMinutesBeforeMarketClose);
}
public void OnFiveMinutesAfterMarketOpen()
{
// updates using the price at 9:35pm
ema.Update(Time, Security.Close);
}
public void OnFiveMinutesBeforeMarketClose()
{
// updates using the price at 3:55pm
ema.Update(Time, Security.Close);
}
//Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol.
public void OnData(TradeBars data)
{
if (!Portfolio.Invested)
{
SetHoldings(Symbol, 0.5m);
}
}
}
}