Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return -86.147% Drawdown 68.00% Expectancy 0 Net Profit 0% Sharpe Ratio -1.318 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -1.117 Beta -0.99 Annual Standard Deviation 1.048 Annual Variance 1.099 Information Ratio -1.541 Tracking Error 1.07 Treynor Ratio 1.396 |
namespace QuantConnect { /* * QuantConnect University: Binary Options are a different way of trading than traditional equities. * * Although QuantConnect does not support live binary option trading yet, we do support backtesting your binary option strategies! * This framework algorithm will get you started on how to setup a Binary Option Backtest. */ public class BinaryOptionsFrameworkAlgorithm : QCAlgorithm { //Setup your variables for the strategy: //1. Starting cash and the internal cash counter. private decimal _cash = 2000; //2. Record keeping of the entry price for the strategy private decimal _entryPrice = 0; //3. Bet size private decimal _stakeSize = 200; //4. Win fraction of the stake size private decimal _winFraction = 0.8m; //5. Timeframe for the Holdings: private DateTime _entry = new DateTime(); private TimeSpan _period = TimeSpan.FromSeconds(180); //Other working variables: private TradeBars _data; public static QCAlgorithm Reference; private List<BinaryBet> _bets = new List<BinaryBet>(); //Initialize the algorithm parameters such as symbols and dates: public override void Initialize() { SetStartDate(2013, 1, 1); SetEndDate(2013, 6, 30); SetCash(_cash); AddSecurity(SecurityType.Equity, "SPY", Resolution.Minute); Reference = this; } //Data Event Handler: Process new financial data. public void OnData(TradeBars data) { //Scan for Entry: if (Time.DayOfWeek == DayOfWeek.Wednesday) { if (Time.Hour == 12 && Time.Minute == 30) { _bets.Add( new BinaryBet("SPY", Direction.Long, _stakeSize, _period, _winFraction) ); } } //Scan Bets: foreach (var bet in _bets) { if (!bet.Paid && bet.Expired) { if (bet.Scan()) { _cash += bet.ProfitLoss; bet.Paid = true; } } } Portfolio.SetCash(_cash); } } // End of Algorithm } // End of Namespace
using System; using System.Collections; using System.Collections.Generic; using QuantConnect.Securities; using QuantConnect.Models; namespace QuantConnect { //Container for holding bet information. public class BinaryBet { private QCAlgorithm _algorithm; private Direction _direction; private string _symbol; private DateTime _entryTime; private decimal _entryPrice; private decimal _exitPrice; private TimeSpan _period; private decimal _stake; private bool _paid; private decimal _winFraction; public BinaryBet(string symbol, Direction direction, decimal stake, TimeSpan period, decimal winFraction = 0.8m) { this._algorithm = BinaryOptionsFrameworkAlgorithm.Reference; this._symbol = symbol; this._period = period; this._stake = stake; this._winFraction = winFraction; this._entryTime = _algorithm.Time; this._entryPrice = _algorithm.Securities[_symbol].Price; this._direction = direction; this._paid = false; } //Option has passed its expiration date. public bool Expired { get { return (_algorithm.Time > (_entryTime + _period)); } } //Flag indicating the bet has been paid. public bool Paid { get { return _paid; } set { _paid = value; } } public decimal ProfitLoss { get { if (!Expired) return 0; switch (_direction) { default: case Direction.Long: return (_algorithm.Securities[_symbol].Price > _entryPrice) ? (_stake * _winFraction) : (-1*_stake); case Direction.Short: return (_algorithm.Securities[_symbol].Price < _entryPrice) ? (_stake * _winFraction) : (-1*_stake); } } } // Scan the algorithm time and price public bool Scan() { if (_exitPrice == Decimal.Zero && Expired) { _exitPrice = _algorithm.Securities[_symbol].Price; return true; } return false; } } //Long or Short Bet public enum Direction { Long, Short } }