| Overall Statistics |
|
Total Trades 2 Average Win 0% Average Loss -0.02% Compounding Annual Return -0.575% Drawdown 0.000% Expectancy -1 Net Profit -0.020% Sharpe Ratio -5.292 Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.017 Beta 0.609 Annual Standard Deviation 0.001 Annual Variance 0 Information Ratio -24.549 Tracking Error 0.001 Treynor Ratio -0.009 Total Fees $2.00 |
namespace QuantConnect
{
public class OrderSubmitHelp : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2013, 10, 4);
SetEndDate(2013, 10, 16);
SetCash(10000);
SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Cash);
AddSecurity(SecurityType.Equity, "SPY", Resolution.Minute);
}
public void OnData(TradeBars data)
{
//Make first order and check buying power
if (Portfolio.Invested == false && Portfolio.Cash == 10000)
{
var orderQuantity = CalculateOrderQuantity("SPY", 0.98); //Easy position size
MarketOrder("SPY", orderQuantity, false, "Entry " + "SPY");
Log("Equity Unused = " + Portfolio.Cash + "Margin Remaining = " + Portfolio.MarginRemaining);
Log("Portfolio Holdings = " + Portfolio.TotalHoldingsValue + " Portfolio Invested = " + Portfolio.Invested);
Log("Buying Power Short = " + Portfolio.GetBuyingPower("SPY", OrderDirection.Sell));
Log("Buying Power Long = " + Portfolio.GetBuyingPower("SPY", OrderDirection.Buy));
}
//Liquidate, then immediately reorder (DOESN"T WORK WITH IB Brokers Model)
if (Portfolio.Invested == true)
{
Log("Begin Liquidate and reorder function");
var liqOrder = Liquidate("SPY","Liquidated");
Log("Equity Unused = " + Portfolio.Cash + "Margin Remaining = " + Portfolio.MarginRemaining);
Log("Portfolio Holdings = " + Portfolio.TotalHoldingsValue + " Portfolio Invested = " + Portfolio.Invested);
Log("Buying Power Short = " + Portfolio.GetBuyingPower("SPY", OrderDirection.Sell));
Log("Buying Power Long = " + Portfolio.GetBuyingPower("SPY", OrderDirection.Buy));
Log("Attempt to resubmit new order"); // This throws insufficient buying power
var orderQuantity = CalculateOrderQuantity("SPY", 0.98); //Easy position size
MarketOrder("SPY", orderQuantity, false, "Reorder " + "SPY");
Log("Order Quantity = " + orderQuantity);
}
}
}
}