Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions project-templates/csharp/ai/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
/// </summary>
public class AccordVectorMachinesAlgorithm : QCAlgorithm
{
// Define the size of the data used to train the model
// It will use _lookback sets with _inputSize members
// Those members are rate of return
// Define the size of the data used to train the model.
// It will use _lookback sets with _inputSize members.
// Those members are rate of return.
private const int _lookback = 30;
private const int _inputSize = 5;
private Equity _equity;
Expand All @@ -82,6 +82,7 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

Accord.Math.Random.Generator.Seed = 0;

Expand All @@ -104,11 +105,11 @@ private void TrainAndTrade()
return;
}

// Convert the rolling window of rate of change into the Learn method
// Convert the rolling window of rate of change into the Learn method.
var targets = new double[_lookback];
var inputs = new double[_lookback][];

// Use the sign of the returns to predict the direction
// Use the sign of the returns to predict the direction.
for (var i = 0; i < _lookback; i++)
{
var returns = new double[_inputSize];
Expand All @@ -121,13 +122,13 @@ private void TrainAndTrade()
inputs[i] = returns;
}

// Train SupportVectorMachine using SetHoldings("SPY", percentage);
// Train SupportVectorMachine using SetHoldings("SPY", percentage);.
var teacher = new LinearCoordinateDescent();
teacher.Learn(inputs, targets);

var svm = teacher.Model;

// Compute the value for the last rate of change
// Compute the value for the last rate of change.
var value = svm.Score(new double[] { Math.Sign(_roc.Window[0]) });
if (value.IsNaNOrZero()) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of US Equities with positive sentiment in their latest SEC filings.
_universe = AddUniverse<BrainCompanyFilingLanguageMetricsUniverseAll>(data =>
{
Expand All @@ -26,7 +27,7 @@ where d.ReportSentiment.Sentiment > 0m
select d.Symbol;
});

// Rebalance shortly after the open so today's universe is locked in.
// Rebalance before market open to trade today's universe.
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(9, 0, 0), Rebalance);
}

Expand All @@ -42,7 +43,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of US Equities with positive 7-day media sentiment and active mention coverage.
_universe = AddUniverse<BrainSentimentIndicatorUniverse>(data =>
{
Expand All @@ -25,7 +26,7 @@ where d.TotalArticleMentions7Days > 0m && d.Sentiment7Days > 0m
select d.Symbol;
});

// Rebalance shortly after the open so today's universe is locked in.
// Rebalance before market open to trade today's universe.
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(9, 0, 0), Rebalance);
}

Expand All @@ -41,7 +42,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of US Equities with positive Brain ML rankings across 2-, 3-, and 5-day horizons.
_universe = AddUniverse<BrainStockRankingUniverse>(data =>
{
Expand All @@ -25,7 +26,7 @@ where d.Rank2Days > 0m && d.Rank3Days > 0m && d.Rank5Days > 0m
select d.Symbol;
});

// Rebalance shortly after the open so today's universe is locked in.
// Rebalance before market open to trade today's universe.
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(9, 0, 0), Rebalance);
}

Expand All @@ -41,7 +42,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;
SetAccountCurrency("USD");

// Trade the largest CoinGecko coins on Coinbase quoted in USD.
Expand All @@ -26,7 +27,7 @@ public override void Initialize()
.Select(x => x.Key.Symbol)
.ToList();

UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of the top 10 CoinGecko coins by market cap that we can trade.
_universe = AddUniverse<CoinGecko>("CoinGeckoUniverse", Resolution.Daily, data =>
{
Expand Down Expand Up @@ -56,7 +57,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of US Equities going ex-dividend in the next day with a meaningful payout.
_universe = AddUniverse<EODHDUpcomingDividends>(data =>
{
Expand All @@ -25,7 +26,7 @@ public override void Initialize()
select d.Symbol;
});

// Rebalance shortly after the open so today's universe is locked in.
// Rebalance before market open to trade today's universe.
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(9, 0, 0), Rebalance);
}

Expand All @@ -41,7 +42,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of US Equities reporting earnings in the next 3 days with a positive estimate.
_universe = AddUniverse<EODHDUpcomingEarnings>(data =>
{
Expand All @@ -25,7 +26,7 @@ public override void Initialize()
select d.Symbol;
});

// Rebalance shortly after the open so today's universe is locked in.
// Rebalance before market open to trade today's universe.
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(9, 0, 0), Rebalance);
}

Expand All @@ -41,7 +42,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of confirmed non-penny upcoming IPOs.
_universe = AddUniverse<EODHDUpcomingIPOs>(data =>
{
Expand All @@ -32,7 +33,7 @@ where _dealTypesWanted.Contains(d.DealType)
select d.Symbol;
});

// Rebalance shortly after the open so today's universe is locked in.
// Rebalance before market open to trade today's universe.
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(9, 0, 0), Rebalance);
}

Expand All @@ -48,7 +49,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of US Equities with a forward stock split in the next 3 days.
_universe = AddUniverse<EODHDUpcomingSplits>(data =>
{
Expand All @@ -25,7 +26,7 @@ public override void Initialize()
select d.Symbol;
});

// Rebalance shortly after the open so today's universe is locked in.
// Rebalance before market open to trade today's universe.
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(9, 0, 0), Rebalance);
}

Expand All @@ -41,7 +42,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

// Trade daily on CNBC opinion updates.
UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of US Equities flagged by 3+ positive CNBC opinions.
_universe = AddUniverse<QuiverCNBCsUniverse>(data =>
{
Expand All @@ -29,7 +30,7 @@ where g.Count(x => x.Direction == OrderDirection.Buy) >= 3
select g.Key;
});

// Rebalance shortly after the open so today's universe is locked in.
// Rebalance before market open to trade today's universe.
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(9, 0, 0), Rebalance);
}

Expand All @@ -45,7 +46,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of US Equities with frequent, sizable US government contracts.
_universe = AddUniverse<QuiverGovernmentContractUniverse>(data =>
{
Expand All @@ -25,7 +26,7 @@ where g.Count() >= 3 && g.Sum(x => x.Amount) > 50000m
select g.Key;
});

// Rebalance shortly after the open so today's universe is locked in.
// Rebalance before market open to trade today's universe.
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(9, 0, 0), Rebalance);
}

Expand All @@ -41,7 +42,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of the 10 US Equities with the largest insider-trading dollar volume.
_universe = AddUniverse<QuiverInsiderTradingUniverse>(data =>
{
Expand All @@ -40,7 +41,7 @@ public override void Initialize()
.Select(kvp => kvp.Key);
});

// Rebalance shortly after the open so today's universe is locked in.
// Rebalance before market open to trade today's universe.
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(9, 0, 0), Rebalance);
}

Expand All @@ -56,7 +57,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public override void Initialize()
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(100000);
Settings.SeedInitialPrices = true;

UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Resolution = Resolution.Minute;
// Universe of US Equities with material corporate lobbying spend.
_universe = AddUniverse<QuiverLobbyingUniverse>("QuiverLobbyingUniverse", Resolution.Daily, data =>
{
Expand All @@ -25,7 +26,7 @@ where g.Sum(x => x.Amount) >= 100000m
select g.Key;
});

// Rebalance shortly after the open so today's universe is locked in.
// Rebalance before market open to trade today's universe.
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.At(9, 0, 0), Rebalance);
}

Expand All @@ -41,7 +42,7 @@ private void Rebalance()
.Select(symbol => new PortfolioTarget(symbol, weight))
.ToList();

SetHoldings(targets, liquidateExistingHoldings: true);
SetHoldings(targets, true);
}
}
}
Loading
Loading