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 { /* * QuantConnect University: Full Basic Template: * * The underlying QCAlgorithm class is full of helper methods which enable you to use QuantConnect. * We have explained some of these here, but the full algorithm can be found at: * https://github.com/QuantConnect/QCAlgorithm/blob/master/QuantConnect.Algorithm/QCAlgorithm.cs */ public class BasicTemplateAlgorithm : QCAlgorithm { private string _symbol = "SPY"; private int _initialCapital = 25000; private ExponentialMovingAverage _ema; private SimpleMovingAverage _sma; private decimal _profitTarget; private OrderTicket _currentOrder; private OrderTicket _trailingStopOrder; //Initialize the data and resolution you require for your strategy: public override void Initialize() { //Start and End Date range for the backtest: SetStartDate(2013, 1, 1); SetEndDate(DateTime.Now.Date.AddDays(-1)); //Cash allocation SetCash(_initialCapital); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, _symbol, Resolution.Minute); _ema = EMA(_symbol, 10); _sma = SMA(_symbol, 30); } //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) { var holdings = Portfolio[_symbol].Quantity; if (_ema > _sma && holdings != 0) PlaceTrade(); if (_currentOrder != null) AmendOrder(); if (_trailingStopOrder != null) { AmendTrailingStop(); return; } if (holdings > 0) { // have we hit our 50% target profit? var currentProfit = GetCurrentProfit(data[_symbol].Close); if (currentProfit > _profitTarget) PlaceTrailingStop(); } } // get the profit since we bought the stock. public decimal GetCurrentProfit(decimal currentPrice) { // not implemented yet. return 0m; } public void PlaceTrailingStop() { // not implemented yet. // options not yet supported in QC } // Place a limit order to buy to open a call option at 1 strike OTM on SPY at the mark price. public void PlaceTrade() { // option not yet supported in QC. // _currentOrder = OptionLimitOrder(optionType, expiry, strike, offerPrice); } // Amend the order based on the new close price of the bar. public void AmendOrder() { // options not yet supported in QC. //var newprice = ??; //_currentOrder.Update(new UpdateOrderFields{LimitPrice=newPrice, Quantity=qty}); } // Amend the trailing stop based on the new close price of the bar. public void AmendTrailingStop() { // options not yet supported in QC. //var newprice = ??; //_currentOrder.Update(new UpdateOrderFields{LimitPrice=newPrice, Quantity=qty}); } public override void OnOrderEvent(OrderEvent fill) { Log("Order has been filled :-) -> " + fill.FillPrice + " QTY: " + fill.FillQuantity); _currentOrder = null; } } }