| Overall Statistics |
|
Total Trades 1140 Average Win 1.29% Average Loss -1.24% Compounding Annual Return 1.988% Drawdown 49.400% Expectancy 0.026 Net Profit 15.711% Sharpe Ratio 0.203 Loss Rate 50% Win Rate 50% Profit-Loss Ratio 1.04 Alpha 0.001 Beta 0.504 Annual Standard Deviation 0.246 Annual Variance 0.06 Information Ratio -0.19 Tracking Error 0.245 Treynor Ratio 0.099 Total Fees $3820.58 |
namespace QuantConnect
{
public class BasicTemplateAlgorithm : QCAlgorithm
{
string Dow30 = "MMM,APX,AAPL,BA,CAT,CVX,CSCO,KO,DIS,DD,XOM,GE,GS,HD,IBM,INTC,JNJ,JPM,MCD,MRK,MSFT,NKE,PFE,PG,TRV,UTX,UNH,VZ,V,WMT";
string symbols;
List<IndicatorBase<IndicatorDataPoint>> Daily_Close;
List<string> symbolList;
public override void Initialize()
{
SetStartDate(2008, 1, 1);
SetEndDate(DateTime.Now.Date.AddDays(-1));
//SetEndDate(2008, 4, 1);
SetCash(10000);
symbols = Dow30;
symbolList = new List<string>(symbols.Split(new char[] { ',' }));
Daily_Close = new List<IndicatorBase<IndicatorDataPoint>>();
Daily_Close.Clear();
for (int n = 0; n < symbolList.Count; n++)
{
AddSecurity(SecurityType.Equity, symbolList[n], Resolution.Minute);
Securities[symbolList[n]].DataFilter = new IncludeOnlyBeginningAndEndOfDayFilter();
Daily_Close.Add(SMA(symbolList[n], 1, Resolution.Daily));
}
}
public void OnData(TradeBars data)
{
for (int n=0; n< symbolList.Count; n++)
{
string symbol = symbolList[n];
if (!data.ContainsKey(symbol))
{
continue;
}
if ((!Portfolio.HoldStock) && (Time.TimeOfDay.TotalHours >= 9.54) && (Time.TimeOfDay.TotalHours < 15.75))
{
decimal buyLimit = Daily_Close[n] * 0.98m;
decimal price = data[symbol].Price;
if ( price < buyLimit)
{
int quantity = (int)Math.Floor(Portfolio.Cash * 0.99m / price);
var id = Order(symbol, quantity);
Log("Order: " + Transactions.GetOrderById(id));
break;
}
}
}
if (Portfolio.HoldStock)
{
if ((Time.Minute == 59) && (Time.Hour == 15))
{
Liquidate();
}
}
}
// since this strategy really only needs to make actions at specific times
// we can limit he amount of data that runs through the system using a data
// filtere. here I define a filter which only includes data from the first
// and last 30 minutes of equities trading
class IncludeOnlyBeginningAndEndOfDayFilter : SecurityDataFilter
{
public override bool Filter(Security security, BaseData data)
{
if (data.Time.Hour < 10 || data.Time.TimeOfDay > new TimeSpan(15, 30, 0))
{
// only forward data before 10am or after 3:30pm
return true;
}
return false;
}
}
}
}