Overall Statistics |
Total Trades 8 Average Win 0.48% Average Loss -0.05% Compounding Annual Return 290404.668% Drawdown 0.400% Expectancy 7.294 Net Profit 2.814% Sharpe Ratio 82.441 Loss Rate 25% Win Rate 75% Profit-Loss Ratio 10.06 Alpha 4.001 Beta -0.214 Annual Standard Deviation 0.043 Annual Variance 0.002 Information Ratio 5.313 Tracking Error 0.242 Treynor Ratio -16.421 Total Fees $16.00 |
using System; using System.Linq; using QuantConnect.Data.Consolidators; using QuantConnect.Indicators; using QuantConnect.Data.Market; using QuantConnect.Algorithm; using QuantConnect.Data.Custom; namespace QuantConnect { public class KYJIndicators : QCAlgorithm { //string crude = "CME/CLN2015"; string symbol = "SPY"; MovingAverageConvergenceDivergence macd; RelativeStrengthIndex rsi; MoneyFlowIndex mfi; decimal price; TradeBar symbolDaily; //Initialize the data and resolution you require for your strategy: public override void Initialize () { SetStartDate (2015, 1, 7); SetEndDate (2015, 1, 8); SetCash (25000); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity (SecurityType.Equity, symbol, Resolution.Minute, fillDataForward: false); //AddData<QuandlFuture> (crude, Resolution.Daily); //Set up Indicators macd = MACD (symbol, 12, 26, 9, MovingAverageType.Simple, Resolution.Minute); rsi = RSI (symbol, 14, MovingAverageType.Simple, Resolution.Minute); mfi = MFI (symbol, 14, Resolution.Minute); //Setup Consolidators // define our daily trade bar consolidator. we can access the daily bar // from the DataConsolidated events var dailyConsolidator = new TradeBarConsolidator (TimeSpan.FromDays (1)); // attach our event handler. the event handler is a function that will be called // each time we produce a new consolidated piece of data dailyConsolidator.DataConsolidated += OnDataDaily; // this call adds our daily consolidator to the manager to receive updates // from the engine SubscriptionManager.AddConsolidator (symbol, dailyConsolidator); var chart = new Chart("rsi"); var buy = new Series("buy", SeriesType.Scatter); var sell = new Series("sell", SeriesType.Scatter); var rsis = new Series("rsi"); chart.AddSeries(buy); chart.AddSeries(sell); chart.AddSeries(rsis); AddChart(chart); } public void OnDataDaily (object sender, TradeBar consolidated) { symbolDaily = consolidated; Log(Time.ToString("u") + " Close price: " + consolidated.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 (Quandl data) public void OnData (TradeBars data) { /* if (!macd.IsReady || !rsi.IsReady || !mfi.IsReady) { return; } */ decimal macdLine = macd.Fast - macd.Slow; decimal macdHistogram = Math.Round(macdLine - macd.Signal,3); price = Math.Round(data[symbol].Close, 3); // MFI not working (always 100) Plot("rsi","rsi",rsi); if (!Portfolio.Invested && (rsi < 30) ) { Plot("rsi", "buy", rsi); Plot("rsi", "rsi", rsi); SetHoldings (symbol, 0.75); Log (Time.ToString ("u") + " Purchased: " + symbol + " price = " + price + " MACDHis = " + macdHistogram + " RSI = " + rsi + " MFI = " + mfi); } else if (Portfolio.Invested && (rsi > 70) ) { Plot("rsi", "sell", rsi); Plot("rsi", "rsi", rsi); Liquidate (symbol); Log (Time.ToString ("u") + " Sold: " + symbol + " price = " + price + " MACDHis = " + macdHistogram + " RSI = " + rsi + " MFI = " + mfi); } } // Fire plotting events once per day: public override void OnEndOfDay (string symbol) { /* if (!macd.IsReady || !rsi.IsReady || !mfi.IsReady) { return; } */ //Plot("MACD", "Price", price); //Plot("MACD", macd.Fast, macd.Slow); //Plot ("RSI", "rsi", rsi); //Plot ("RSI", "price", price); //Plot ("MFI", mfi); } } // Custom quandl data type for setting customized value column name. // Value column is used for the primary trading calculations and charting. public class QuandlFuture : Quandl { public QuandlFuture () : base (valueColumnName: "Settle") { } } }