GeezerVison is showing github.com — Changes quantity calculation in algorithm examples · nuswgg/Lean@b145521
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/CustomChartingAlgorithm.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,7 +116,7 @@ public void OnData(TradeBars data) | 116 | 116 | //On the 5th days when not invested buy: | 117 | 117 | if (!Portfolio.Invested && Time.Day % 13 == 0) | 118 | 118 | { | 119 | | - Order("SPY", (int)(Portfolio.Cash / data["SPY"].Close)); | | 119 | + Order("SPY", (int)(Portfolio.MarginRemaining / data["SPY"].Close)); | 120 | 120 | Plot("Trade Plot", "Buy", lastPrice); | 121 | 121 | } | 122 | 122 | else if (Time.Day % 21 == 0 && Portfolio.Invested) | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/CustomDataBitcoinAlgorithm.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,7 +59,7 @@ public void OnData(Bitcoin data) | 59 | 59 | //Weather used as a tradable asset, like stocks, futures etc. | 60 | 60 | if (data.Close != 0) | 61 | 61 | { | 62 | | - Order("BTC", (Portfolio.Cash / Math.Abs(data.Close + 1))); | | 62 | + Order("BTC", (Portfolio.MarginRemaining / Math.Abs(data.Close + 1))); | 63 | 63 | } | 64 | 64 | Console.WriteLine("Buying BTC 'Shares': BTC: " + data.Close); | 65 | 65 | } | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/CustomDataRegressionAlgorithm.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,7 +51,7 @@ public void OnData(Bitcoin data) | 51 | 51 | //Bitcoin used as a tradable asset, like stocks, futures etc. | 52 | 52 | if (data.Close != 0) | 53 | 53 | { | 54 | | - Order("BTC", (Portfolio.Cash / Math.Abs(data.Close + 1))); | | 54 | + Order("BTC", (Portfolio.MarginRemaining / Math.Abs(data.Close + 1))); | 55 | 55 | } | 56 | 56 | } | 57 | 57 | } | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/ETFGlobalRotationAlgorithm.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -115,7 +115,7 @@ public void OnData(TradeBars data) | 115 | 115 | Liquidate(); | 116 | 116 | } | 117 | 117 | Log(">>BUY>>" + bestGrowth.Symbol + "@" + (100 * bestGrowth.OneMonthPerformance).ToString("00.00")); | 118 | | - decimal qty = Portfolio.Cash / Securities[bestGrowth.Symbol].Close; | | 118 | + decimal qty = Portfolio.MarginRemaining / Securities[bestGrowth.Symbol].Close; | 119 | 119 | MarketOrder(bestGrowth.Symbol, (int) qty); | 120 | 120 | } | 121 | 121 | else | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/FuzzyInferenceAlgorithm.cs +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,8 +26,8 @@ public class FuzzyInferenceAlgorithm : QCAlgorithm | 26 | 26 |
| 27 | 27 | public override void Initialize() | 28 | 28 | { | 29 | | - SetStartDate(2016, 01, 01); //Set Start Date | 30 | | - SetEndDate(2016, 06, 30); //Set End Date | | 29 | + SetStartDate(2015, 01, 01); //Set Start Date | | 30 | + SetEndDate(2015, 06, 30); //Set End Date | 31 | 31 | SetCash(100000); //Set Strategy Cash | 32 | 32 | AddEquity(symbol, Resolution.Daily); | 33 | 33 |
| @@ -49,7 +49,7 @@ public void OnData(TradeBars data) | 49 | 49 | { | 50 | 50 | if (signal > 30) | 51 | 51 | { | 52 | | - int quantity = Decimal.ToInt32(Portfolio.Cash / data[symbol].Price); | | 52 | + int quantity = Decimal.ToInt32(Portfolio.MarginRemaining / data[symbol].Price); | 53 | 53 | Buy(symbol, quantity); | 54 | 54 | Debug("Purchased Stock: " + quantity + " shares"); | 55 | 55 | } | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/IndicatorSuiteAlgorithm.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,7 +52,7 @@ public override void Initialize() | 52 | 52 | SetCash(25000); | 53 | 53 |
| 54 | 54 | //Add as many securities as you like. All the data will be passed into the event handler: | 55 | | - AddSecurity(SecurityType.Equity, _symbol, Resolution.Minute); | | 55 | + AddSecurity(SecurityType.Equity, _symbol, Resolution.Daily); | 56 | 56 |
| 57 | 57 | //Add the Custom Data: | 58 | 58 | AddData<Bitcoin>("BTC"); | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/LiveFeaturesAlgorithm.cs +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,12 +33,12 @@ public class LiveTradingFeaturesAlgorithm : QCAlgorithm | 33 | 33 | /// </summary> | 34 | 34 | public override void Initialize() | 35 | 35 | { | 36 | | - SetStartDate(2013, 1, 1); | 37 | | - SetEndDate(DateTime.Now.Date.AddDays(-1)); | | 36 | + SetStartDate(2013, 10, 7); | | 37 | + SetEndDate(2013, 10, 11); | 38 | 38 | SetCash(25000); | 39 | 39 |
| 40 | 40 | //Equity Data for US Markets: | 41 | | - AddSecurity(SecurityType.Equity, "AAPL", Resolution.Second); | | 41 | + AddSecurity(SecurityType.Equity, "IBM", Resolution.Second); | 42 | 42 |
| 43 | 43 | //FOREX Data for Weekends: 24/6 | 44 | 44 | AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Minute); | @@ -76,11 +76,11 @@ public void OnData(Bitcoin data) | 76 | 76 | /// <param name="data">Data.</param> | 77 | 77 | public void OnData(TradeBars data) | 78 | 78 | { | 79 | | - if (!Portfolio.HoldStock && data.ContainsKey("AAPL")) | | 79 | + if (!Portfolio["IBM"].HoldStock && data.ContainsKey("IBM")) | 80 | 80 | { | 81 | | - int quantity = (int)Math.Floor(Portfolio.Cash / data["AAPL"].Close); | 82 | | - Order("AAPL", quantity); | 83 | | - Debug("Purchased SPY on " + Time.ToShortDateString()); | | 81 | + int quantity = (int)Math.Floor(Portfolio.MarginRemaining / data["IBM"].Close); | | 82 | + Order("IBM", quantity); | | 83 | + Debug("Purchased IBM on " + Time.ToShortDateString()); | 84 | 84 | | 85 | 85 | } | 86 | 86 | } | |
|