GeezerVison is showing github.com — Post merge fixes · nuswgg/Lean@6bfea3d
File treeExpand file treeCollapse file tree Open diff view settings Brokerages/InteractiveBrokers
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/FractionalQuantityRegressionAlgorithm.cs +4-10Lines changed: 4 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | * limitations under the License. | 14 | 14 | */ | 15 | 15 |
| 16 | | -using QuantConnect.Data; | 17 | 16 | using QuantConnect.Data.Consolidators; | 18 | 17 | using QuantConnect.Data.Market; | 19 | 18 | using System; | 20 | | -using System.Linq; | 21 | 19 |
| 22 | 20 | namespace QuantConnect.Algorithm.CSharp | 23 | 21 | { | @@ -39,15 +37,14 @@ public override void Initialize() | 39 | 37 |
| 40 | 38 | SetTimeZone(NodaTime.DateTimeZone.Utc); | 41 | 39 | var security = AddSecurity(SecurityType.Forex, "BTCUSD", Resolution.Daily, Market.Bitfinex, false, 3.3m, true); | 42 | | - TradeBarConsolidator con = new TradeBarConsolidator(1); | | 40 | + var con = new QuoteBarConsolidator(1); | 43 | 41 | SubscriptionManager.AddConsolidator("BTCUSD", con); | 44 | 42 | con.DataConsolidated += con_DataConsolidated; | 45 | 43 | SetBenchmark(security.Symbol); | 46 | 44 | } | 47 | 45 |
| 48 | | - void con_DataConsolidated(object sender, TradeBar e) | | 46 | + void con_DataConsolidated(object sender, QuoteBar e) | 49 | 47 | { | 50 | | - | 51 | 48 | var quantity = Math.Truncate(Portfolio.Cash / Math.Abs(e.Value + 1)); | 52 | 49 | if (!Portfolio.Invested) | 53 | 50 | { | @@ -67,16 +64,13 @@ void con_DataConsolidated(object sender, TradeBar e) | 67 | 64 | } | 68 | 65 | else if (Portfolio["BTCUSD"].Quantity == quantity + 0.09m) | 69 | 66 | { | 70 | | - | 71 | 67 | //should fail | 72 | | - var ticket = Order("BTCUSD", 0.001); | | 68 | + Order("BTCUSD", 0.001); | 73 | 69 |
| 74 | 70 | SetHoldings("BTCUSD", -2.0m); | 75 | 71 | SetHoldings("BTCUSD", 2.0m); | 76 | | - this.Quit(); | | 72 | + Quit(); | 77 | 73 | } | 78 | | - | 79 | | - | 80 | 74 | } | 81 | 75 | } | 82 | 76 | } |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/FuzzyInferenceAlgorithm.cs +18-3Lines changed: 18 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -using System; | | 1 | +/* | | 2 | + * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | | 3 | + * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | | 4 | + * | | 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | | 6 | + * you may not use this file except in compliance with the License. | | 7 | + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | | 8 | + * | | 9 | + * Unless required by applicable law or agreed to in writing, software | | 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | | 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | + * See the License for the specific language governing permissions and | | 13 | + * limitations under the License. | | 14 | +*/ | | 15 | + | | 16 | +using System; | 2 | 17 | using QuantConnect.Data.Market; | 3 | 18 | using QuantConnect.Indicators; | 4 | 19 | using Accord.Fuzzy; | @@ -49,7 +64,7 @@ public void OnData(TradeBars data) | 49 | 64 | { | 50 | 65 | if (signal > 30) | 51 | 66 | { | 52 | | - int quantity = Decimal.ToInt32(Portfolio.MarginRemaining / data[symbol].Price); | | 67 | + var quantity = decimal.ToInt32(Portfolio.MarginRemaining / data[symbol].Price); | 53 | 68 | Buy(symbol, quantity); | 54 | 69 | Debug("Purchased Stock: " + quantity + " shares"); | 55 | 70 | } | @@ -58,7 +73,7 @@ public void OnData(TradeBars data) | 58 | 73 | { | 59 | 74 | if (signal < -10) | 60 | 75 | { | 61 | | - int quantity = Portfolio[symbol].Quantity; | | 76 | + var quantity = decimal.ToInt32(Portfolio[symbol].Quantity); | 62 | 77 | Sell(symbol, quantity); | 63 | 78 | Debug("Sold Stock: " + quantity + " shares"); | 64 | 79 | } | |
Collapse file Copy file name to clipboardExpand all lines: Brokerages/InteractiveBrokers/InteractiveBrokersBrokerage.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -644,7 +644,7 @@ private void IBPlaceOrder(Order order, bool needsNewId, string exchange = null) | 644 | 644 |
| 645 | 645 | if (order.Type == OrderType.OptionExercise) | 646 | 646 | { | 647 | | - _client.ClientSocket.exerciseOptions(ibOrderId, contract, 1, order.Quantity, _account, 0); | | 647 | + _client.ClientSocket.exerciseOptions(ibOrderId, contract, 1, decimal.ToInt32(order.Quantity), _account, 0); | 648 | 648 | } | 649 | 649 | else | 650 | 650 | { | |
Collapse file Copy file name to clipboardExpand all lines: Common/Orders/OptionExerciseOrder.cs +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,7 +39,7 @@ public OptionExerciseOrder() | 39 | 39 | /// <param name="quantity">Quantity of the option we're seeking to exercise. Must be a positive value.</param> | 40 | 40 | /// <param name="time">Time the order was placed</param> | 41 | 41 | /// <param name="tag">User defined data tag for this order</param> | 42 | | - public OptionExerciseOrder(Symbol symbol, int quantity, DateTime time, string tag = "") | | 42 | + public OptionExerciseOrder(Symbol symbol, decimal quantity, DateTime time, string tag = "") | 43 | 43 | : base(symbol, quantity, time, tag) | 44 | 44 | { | 45 | 45 | Price = Symbol.ID.StrikePrice; | @@ -64,7 +64,6 @@ protected override decimal GetValueImpl(Security security) | 64 | 64 | return option.GetExerciseQuantity(Quantity) * Price / option.SymbolProperties.ContractMultiplier; | 65 | 65 | } | 66 | 66 |
| 67 | | - | 68 | 67 | /// <summary> | 69 | 68 | /// Creates a deep-copy clone of this order | 70 | 69 | /// </summary> | |
Collapse file Copy file name to clipboardExpand all lines: Common/Securities/Option/Option.cs +2-4Lines changed: 2 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 |
| 16 | 16 | using System; | 17 | 17 | using QuantConnect.Data; | 18 | | -using QuantConnect.Data.Market; | 19 | 18 | using QuantConnect.Orders.Fees; | 20 | 19 | using QuantConnect.Orders.Fills; | 21 | 20 | using QuantConnect.Orders.Slippage; | 22 | 21 | using QuantConnect.Orders.OptionExercise; | 23 | | -using System.Collections.Generic; | 24 | 22 |
| 25 | 23 | namespace QuantConnect.Securities.Option | 26 | 24 | { | @@ -185,9 +183,9 @@ public decimal GetAggregateExerciseAmount() | 185 | 183 | /// we may have 1 option contract with multiplier of 100 with right to buy/sell only 50 shares of underlying stock. | 186 | 184 | /// </summary> | 187 | 185 | /// <returns></returns> | 188 | | - public int GetExerciseQuantity(int quantity) | | 186 | + public decimal GetExerciseQuantity(decimal quantity) | 189 | 187 | { | 190 | | - return (int)(quantity * ContractUnitOfTrade / ContractMultiplier); | | 188 | + return quantity * ContractUnitOfTrade / ContractMultiplier; | 191 | 189 | } | 192 | 190 |
| 193 | 191 | /// <summary> | |
Collapse file Copy file name to clipboardExpand all lines: Tests/RegressionTests.cs +18-18Lines changed: 18 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -499,7 +499,7 @@ private static TestCaseData[] GetRegressionTestParameters() | 499 | 499 | {"Treynor Ratio", "0.391"}, | 500 | 500 | {"Total Fees", "$23.05"}, | 501 | 501 | }; | 502 | | - var optionExerciseAssignRegressionAlgorithmStatistics = new Dictionary<string, string> | | 502 | + var optionExerciseAssignRegressionAlgorithmStatistics = new Dictionary<string, string> | 503 | 503 | { | 504 | 504 | {"Total Trades", "4"}, | 505 | 505 | {"Average Win", "0.30%"}, | @@ -590,28 +590,28 @@ private static TestCaseData[] GetRegressionTestParameters() | 590 | 590 | {"Treynor Ratio", "0"}, | 591 | 591 | {"Total Fees", "$1.00"} | 592 | 592 | }; | 593 | | - | | 593 | + | 594 | 594 | var fractionalQuantityRegressionStatistics = new Dictionary<string, string> | 595 | 595 | { | 596 | 596 | {"Total Trades", "6"}, | 597 | | - {"Average Win", "2.57%"}, | 598 | | - {"Average Loss", "-0.01%"}, | 599 | | - {"Compounding Annual Return", "900.493%"}, | | 597 | + {"Average Win", "1.29%"}, | | 598 | + {"Average Loss", "0.0%"}, | | 599 | + {"Compounding Annual Return", "920.568%"}, | 600 | 600 | {"Drawdown", "3.300%"}, | 601 | | - {"Expectancy", "86.582"}, | 602 | | - {"Net Profit", "2.556%"}, | 603 | | - {"Sharpe Ratio", "3.003"}, | 604 | | - {"Loss Rate", "67%"}, | 605 | | - {"Win Rate", "33%"}, | 606 | | - {"Profit-Loss Ratio", "261.75"}, | 607 | | - {"Alpha", "-0.014"}, | 608 | | - {"Beta", "0.996"}, | 609 | | - {"Annual Standard Deviation", "0.452"}, | 610 | | - {"Annual Variance", "0.204"}, | 611 | | - {"Information Ratio", "-10.05"}, | | 601 | + {"Expectancy", "-0.333"}, | | 602 | + {"Net Profit", "2.578%"}, | | 603 | + {"Sharpe Ratio", "3.031"}, | | 604 | + {"Loss Rate", "33%"}, | | 605 | + {"Win Rate", "67%"}, | | 606 | + {"Profit-Loss Ratio", "0"}, | | 607 | + {"Alpha", "-0.001"}, | | 608 | + {"Beta", "0.995"}, | | 609 | + {"Annual Standard Deviation", "0.451"}, | | 610 | + {"Annual Variance", "0.203"}, | | 611 | + {"Information Ratio", "-3.42"}, | 612 | 612 | {"Tracking Error", "0.002"}, | 613 | | - {"Treynor Ratio", "1.361"}, | 614 | | - {"Total Fees", "$22.33"}, | | 613 | + {"Treynor Ratio", "1.374"}, | | 614 | + {"Total Fees", "$0.00"} | 615 | 615 | }; | 616 | 616 |
| 617 | 617 | return new List<AlgorithmStatisticsTestParameters> | |
|