GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Changes quantity calculation in algorithm examples · nuswgg/Lean@b145521

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Algorithm.CSharp
    • CustomChartingAlgorithm.cs
    • CustomDataBitcoinAlgorithm.cs
    • CustomDataRegressionAlgorithm.cs
    • ETFGlobalRotationAlgorithm.cs
    • FuzzyInferenceAlgorithm.cs
    • IndicatorSuiteAlgorithm.cs
    • LiveFeaturesAlgorithm.cs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Algorithm.CSharp/CustomChartingAlgorithm.cs‎

Copy file name to clipboardExpand all lines: Algorithm.CSharp/CustomChartingAlgorithm.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void OnData(TradeBars data)
116116
//On the 5th days when not invested buy:
117117
if (!Portfolio.Invested && Time.Day % 13 == 0)
118118
{
119-
Order("SPY", (int)(Portfolio.Cash / data["SPY"].Close));
119+
Order("SPY", (int)(Portfolio.MarginRemaining / data["SPY"].Close));
120120
Plot("Trade Plot", "Buy", lastPrice);
121121
}
122122
else if (Time.Day % 21 == 0 && Portfolio.Invested)
Collapse file

‎Algorithm.CSharp/CustomDataBitcoinAlgorithm.cs‎

Copy file name to clipboardExpand all lines: Algorithm.CSharp/CustomDataBitcoinAlgorithm.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void OnData(Bitcoin data)
5959
//Weather used as a tradable asset, like stocks, futures etc.
6060
if (data.Close != 0)
6161
{
62-
Order("BTC", (Portfolio.Cash / Math.Abs(data.Close + 1)));
62+
Order("BTC", (Portfolio.MarginRemaining / Math.Abs(data.Close + 1)));
6363
}
6464
Console.WriteLine("Buying BTC 'Shares': BTC: " + data.Close);
6565
}
Collapse file

‎Algorithm.CSharp/CustomDataRegressionAlgorithm.cs‎

Copy file name to clipboardExpand all lines: Algorithm.CSharp/CustomDataRegressionAlgorithm.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void OnData(Bitcoin data)
5151
//Bitcoin used as a tradable asset, like stocks, futures etc.
5252
if (data.Close != 0)
5353
{
54-
Order("BTC", (Portfolio.Cash / Math.Abs(data.Close + 1)));
54+
Order("BTC", (Portfolio.MarginRemaining / Math.Abs(data.Close + 1)));
5555
}
5656
}
5757
}
Collapse file

‎Algorithm.CSharp/ETFGlobalRotationAlgorithm.cs‎

Copy file name to clipboardExpand all lines: Algorithm.CSharp/ETFGlobalRotationAlgorithm.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void OnData(TradeBars data)
115115
Liquidate();
116116
}
117117
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;
119119
MarketOrder(bestGrowth.Symbol, (int) qty);
120120
}
121121
else
Collapse file

‎Algorithm.CSharp/FuzzyInferenceAlgorithm.cs‎

Copy file name to clipboardExpand all lines: Algorithm.CSharp/FuzzyInferenceAlgorithm.cs
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class FuzzyInferenceAlgorithm : QCAlgorithm
2626

2727
public override void Initialize()
2828
{
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
3131
SetCash(100000); //Set Strategy Cash
3232
AddEquity(symbol, Resolution.Daily);
3333

@@ -49,7 +49,7 @@ public void OnData(TradeBars data)
4949
{
5050
if (signal > 30)
5151
{
52-
int quantity = Decimal.ToInt32(Portfolio.Cash / data[symbol].Price);
52+
int quantity = Decimal.ToInt32(Portfolio.MarginRemaining / data[symbol].Price);
5353
Buy(symbol, quantity);
5454
Debug("Purchased Stock: " + quantity + " shares");
5555
}
Collapse file

‎Algorithm.CSharp/IndicatorSuiteAlgorithm.cs‎

Copy file name to clipboardExpand all lines: Algorithm.CSharp/IndicatorSuiteAlgorithm.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public override void Initialize()
5252
SetCash(25000);
5353

5454
//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);
5656

5757
//Add the Custom Data:
5858
AddData<Bitcoin>("BTC");
Collapse file

‎Algorithm.CSharp/LiveFeaturesAlgorithm.cs‎

Copy file name to clipboardExpand all lines: Algorithm.CSharp/LiveFeaturesAlgorithm.cs
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public class LiveTradingFeaturesAlgorithm : QCAlgorithm
3333
/// </summary>
3434
public override void Initialize()
3535
{
36-
SetStartDate(2013, 1, 1);
37-
SetEndDate(DateTime.Now.Date.AddDays(-1));
36+
SetStartDate(2013, 10, 7);
37+
SetEndDate(2013, 10, 11);
3838
SetCash(25000);
3939

4040
//Equity Data for US Markets:
41-
AddSecurity(SecurityType.Equity, "AAPL", Resolution.Second);
41+
AddSecurity(SecurityType.Equity, "IBM", Resolution.Second);
4242

4343
//FOREX Data for Weekends: 24/6
4444
AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Minute);
@@ -76,11 +76,11 @@ public void OnData(Bitcoin data)
7676
/// <param name="data">Data.</param>
7777
public void OnData(TradeBars data)
7878
{
79-
if (!Portfolio.HoldStock && data.ContainsKey("AAPL"))
79+
if (!Portfolio["IBM"].HoldStock && data.ContainsKey("IBM"))
8080
{
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());
8484
Notify.Email("[email protected]", "Test", "Test Body", "test attachment");
8585
}
8686
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.