ci / test (postgres) (push) Successful in 8m20s
ci / test (sqlite) (push) Successful in 4m25s
ci / test (postgres) (pull_request) Successful in 8m13s
ci / test (sqlite) (pull_request) Successful in 4m38s
ci / image (push) Successful in 2m5s
ci / image (pull_request) Successful in 2m6s
Confirmed serious events hold new purchases of an instrument for 72 hours and keep its stop where it is; confirmed negative news holds them for 24 hours; an unconfirmed rumour only gets a diary note and a check two hours later. Coming earnings keep mean reversion out and macro figures hold entries around their release, now in the live engine too. The strictest row wins, every row can be switched off in the settings, and windows count from the fact, so after an absence only effects still in force apply. A held purchase moves to the end of its restriction while the order is still valid and keeps its first due time, so the price drift check of SPEC 5.6 still compares with the decision. Each restriction is written to the diary once, with its motive. The per-instrument state keeps the tone over one and three days, the story count against its norm and the active restriction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
547 lines
21 KiB
C#
547 lines
21 KiB
C#
using Anubis.Data;
|
|
|
|
namespace Anubis.Strategies;
|
|
|
|
/// <summary>
|
|
/// The stock universe of SPEC 8.2 computed from the bars known on the day: common shares on NYSE and Nasdaq,
|
|
/// fractionable, no funds, real close above 10 $, at least 300 sessions, ranked by the median traded value of the last
|
|
/// 60 sessions. Live, the universe saved "as of the date" is used instead (SPEC 6.7).
|
|
/// </summary>
|
|
public static class EquityUniverseRanking
|
|
{
|
|
public static IReadOnlyList<string> Rank(UniverseContext context, int size)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(context);
|
|
var ranked = new List<(string Symbol, double Value)>();
|
|
foreach (var symbol in context.Available)
|
|
{
|
|
if (context.Spec(symbol) is not { } spec || !EquityUniverse.Eligible(spec))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var bars = context.Bars(symbol);
|
|
var last = bars.Count - 1;
|
|
if (bars.Count < EquityUniverse.MinSessions || bars.Day(last) < context.Day.AddDays(-7) || bars.RealClose(last) <= EquityUniverse.MinPrice)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
ranked.Add((symbol, Indicators.MedianValue(bars, EquityUniverse.Window, last) ?? 0));
|
|
}
|
|
|
|
return [.. ranked.OrderByDescending(r => r.Value).ThenBy(r => r.Symbol, StringComparer.Ordinal).Take(size).Select(r => r.Symbol)];
|
|
}
|
|
|
|
/// <summary>Monday of the week of a day: two days are in the same week when their Mondays match.</summary>
|
|
public static DateOnly WeekOf(DateOnly day) => day.AddDays(-(((int)day.DayOfWeek + 6) % 7));
|
|
}
|
|
|
|
/// <summary>The fixed rules of <c>equity_momentum</c> (SPEC 8.2).</summary>
|
|
public sealed record EquityMomentumSettings
|
|
{
|
|
public int UniverseSize { get; init; } = EquityUniverse.Size;
|
|
|
|
public IReadOnlyList<int> Lookbacks { get; init; } = [63, 126, 252];
|
|
|
|
/// <summary>The returns skip the last sessions (short-term reversal).</summary>
|
|
public int Skip { get; init; } = 5;
|
|
|
|
/// <summary>New entries among the first of the ranking…</summary>
|
|
public int Top { get; init; } = 12;
|
|
|
|
/// <summary>…and a stock held leaves when it falls out of these.</summary>
|
|
public int Keep { get; init; } = 30;
|
|
|
|
public int MaxPositions { get; init; } = 12;
|
|
|
|
/// <summary>Each stock must close above its own average of these sessions.</summary>
|
|
public int Trend { get; init; } = 100;
|
|
|
|
/// <summary>The market filter: SPY above its average of these sessions.</summary>
|
|
public int MarketTrend { get; init; } = 200;
|
|
|
|
public string MarketSymbol { get; init; } = "SPY";
|
|
|
|
public int AtrLength { get; init; } = 20;
|
|
|
|
public double AtrMultiple { get; init; } = 3;
|
|
|
|
public int VolatilityWindow { get; init; } = 60;
|
|
|
|
public double StrategyVolatility { get; init; } = 0.20;
|
|
|
|
public decimal Cap { get; init; } = 0.15m;
|
|
|
|
/// <summary>A position already open is resized only when this far from its target, relative to the target.</summary>
|
|
public decimal Rebalance { get; init; } = 0.25m;
|
|
}
|
|
|
|
/// <summary>
|
|
/// <c>equity_momentum</c> (SPEC 8.2): the strongest US stocks, only while the market rises. The weekly review runs on
|
|
/// the close of the last session before a new week, so its orders go at the open of the first session of the week
|
|
/// (live: 09:35 of that session, on the same data). Every close moves the trailing stops.
|
|
/// </summary>
|
|
public sealed class EquityMomentum(EquityMomentumSettings? settings = null) : IStrategy
|
|
{
|
|
private readonly EquityMomentumSettings _settings = settings ?? new EquityMomentumSettings();
|
|
|
|
public string Id => EquityMomentumFamily.FamilyId;
|
|
|
|
public string Version => EquityMomentumFamily.FamilyVersion;
|
|
|
|
public EquityMomentumSettings Settings => _settings;
|
|
|
|
public IReadOnlyList<DecisionTime> Schedule() => [DecisionTime.AfterClose];
|
|
|
|
public IReadOnlyList<string> Universe(UniverseContext context)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(context);
|
|
return context.Members?.Invoke(Id, context.Day) ?? EquityUniverseRanking.Rank(context, _settings.UniverseSize);
|
|
}
|
|
|
|
/// <summary>True when the next session opens a new week: the close of today is the time of the weekly review.</summary>
|
|
public static bool IsReview(StrategyContext context)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(context);
|
|
return context.NextSession is { } next && EquityUniverseRanking.WeekOf(next) != EquityUniverseRanking.WeekOf(context.Day);
|
|
}
|
|
|
|
public IReadOnlyList<Intent> Decide(StrategyContext context)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(context);
|
|
var equity = context.Portfolio.Equity;
|
|
var held = context.Portfolio.Holdings.Where(h => h.Value.Quantity > 0m).Select(h => h.Key).Order(StringComparer.Ordinal).ToList();
|
|
var stops = new Dictionary<string, decimal>(StringComparer.Ordinal);
|
|
foreach (var symbol in held)
|
|
{
|
|
if (TrailingStop(context, symbol) is { } stop)
|
|
{
|
|
stops[symbol] = stop;
|
|
}
|
|
}
|
|
|
|
var intents = new SortedDictionary<string, Intent>(StringComparer.Ordinal);
|
|
foreach (var (symbol, stop) in stops)
|
|
{
|
|
intents[symbol] = new Intent(symbol, null, Reasons.StopMoved) { Stop = stop };
|
|
}
|
|
|
|
if (!IsReview(context) || equity <= 0m)
|
|
{
|
|
return [.. intents.Values];
|
|
}
|
|
|
|
// The ranking: average of the 63, 126 and 252 session returns, each skipping the last 5 sessions.
|
|
var scores = new List<(string Symbol, double Score)>();
|
|
foreach (var symbol in context.Universe)
|
|
{
|
|
var bars = context.Bars(symbol);
|
|
var parts = _settings.Lookbacks.Select(n => Indicators.Momentum(bars, n, _settings.Skip)).ToList();
|
|
if (parts.All(p => p is not null))
|
|
{
|
|
scores.Add((symbol, parts.Average(p => p!.Value)));
|
|
}
|
|
}
|
|
|
|
var ranking = scores.OrderByDescending(s => s.Score).ThenBy(s => s.Symbol, StringComparer.Ordinal).Select(s => s.Symbol).ToList();
|
|
var rank = ranking.Select((s, i) => (s, i)).ToDictionary(x => x.s, x => x.i, StringComparer.Ordinal);
|
|
bool AboveTrend(string symbol)
|
|
{
|
|
var bars = context.Bars(symbol);
|
|
return Indicators.Sma(bars, _settings.Trend) is { } average && bars.Count > 0 && bars.Close(bars.Count - 1) > average;
|
|
}
|
|
|
|
var market = context.Bars(_settings.MarketSymbol);
|
|
var marketUp = Indicators.Sma(market, _settings.MarketTrend) is { } spyAverage && market.Close(market.Count - 1) > spyAverage;
|
|
|
|
var keep = new List<string>();
|
|
foreach (var symbol in held)
|
|
{
|
|
if (!rank.TryGetValue(symbol, out var r) || r >= _settings.Keep)
|
|
{
|
|
intents[symbol] = new Intent(symbol, 0m, Reasons.ExitRank);
|
|
}
|
|
else if (!AboveTrend(symbol))
|
|
{
|
|
intents[symbol] = new Intent(symbol, 0m, Reasons.ExitTrend);
|
|
}
|
|
else
|
|
{
|
|
keep.Add(symbol);
|
|
}
|
|
}
|
|
|
|
// New entries only while SPY is above its average, and only among the first 12.
|
|
var entries = new List<string>();
|
|
if (marketUp)
|
|
{
|
|
foreach (var symbol in ranking.Take(_settings.Top))
|
|
{
|
|
if (keep.Count + entries.Count >= _settings.MaxPositions)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if (!held.Contains(symbol) && AboveTrend(symbol))
|
|
{
|
|
entries.Add(symbol);
|
|
}
|
|
}
|
|
}
|
|
|
|
var weights = Weights(context, [.. keep, .. entries]);
|
|
foreach (var symbol in entries)
|
|
{
|
|
if (weights.GetValueOrDefault(symbol) is > 0m and var weight && Indicators.Atr(context.Bars(symbol), _settings.AtrLength) is { } atr)
|
|
{
|
|
intents[symbol] = new Intent(symbol, weight, Reasons.Entry) { StopOffset = Math.Round((decimal)(atr * _settings.AtrMultiple), 8) };
|
|
}
|
|
}
|
|
|
|
foreach (var symbol in keep)
|
|
{
|
|
var bars = context.Bars(symbol);
|
|
var holding = context.Portfolio.Of(symbol)!;
|
|
var current = holding.Quantity * (decimal)bars.Close(bars.Count - 1) / equity;
|
|
var target = weights.GetValueOrDefault(symbol, current);
|
|
if (!marketUp)
|
|
{
|
|
target = Math.Min(target, current); // With SPY below its average the strategy can only sell.
|
|
}
|
|
|
|
if (Math.Abs(target - current) > _settings.Rebalance * target)
|
|
{
|
|
intents[symbol] = new Intent(symbol, target, target > current ? Reasons.Increase : Reasons.Reduce) { Stop = stops.GetValueOrDefault(symbol, holding.Stop ?? 0m) is > 0m and var s ? s : null };
|
|
}
|
|
}
|
|
|
|
return [.. intents.Values];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Weights in inverse proportion to the 60-session volatility, the 15% cap (what it cuts stays cash), then one
|
|
/// factor, never above 1, when the strategy's estimated volatility is above 20% a year.
|
|
/// </summary>
|
|
private Dictionary<string, decimal> Weights(StrategyContext context, IReadOnlyList<string> members)
|
|
{
|
|
var inverse = new Dictionary<string, double>(StringComparer.Ordinal);
|
|
foreach (var symbol in members)
|
|
{
|
|
if (Indicators.Volatility(context.Bars(symbol), _settings.VolatilityWindow, 252) is > 0 and var vol)
|
|
{
|
|
inverse[symbol] = 1 / vol;
|
|
}
|
|
}
|
|
|
|
var sum = inverse.Values.Sum();
|
|
var raw = inverse.ToDictionary(p => p.Key, p => Math.Min(p.Value / sum, (double)_settings.Cap), StringComparer.Ordinal);
|
|
var portfolio = Indicators.PortfolioVolatility([.. raw.Select(p => (context.Bars(p.Key), p.Value))], _settings.VolatilityWindow, 252);
|
|
var factor = portfolio is > 0 && portfolio.Value > _settings.StrategyVolatility ? _settings.StrategyVolatility / portfolio.Value : 1;
|
|
return raw.ToDictionary(p => p.Key, p => Math.Round((decimal)(p.Value * factor), 6, MidpointRounding.ToZero), StringComparer.Ordinal);
|
|
}
|
|
|
|
/// <summary>3 ATR(20) below the highest close since the entry; it can only rise.</summary>
|
|
private decimal? TrailingStop(StrategyContext context, string symbol)
|
|
{
|
|
var holding = context.Portfolio.Of(symbol)!;
|
|
var bars = context.Bars(symbol);
|
|
if (Indicators.Atr(bars, _settings.AtrLength) is not { } atr || Indicators.HighestCloseSince(bars, holding.EnteredOn) is not { } high)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var candidate = Math.Round((decimal)(high - (_settings.AtrMultiple * atr)), 8);
|
|
if (candidate <= 0m || (holding.Stop is { } current && candidate <= current))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return candidate;
|
|
}
|
|
|
|
public static class Reasons
|
|
{
|
|
public const string Entry = "momentum_entry";
|
|
public const string Increase = "momentum_increase";
|
|
public const string Reduce = "momentum_reduce";
|
|
public const string ExitRank = "momentum_exit_rank";
|
|
public const string ExitTrend = "momentum_exit_trend";
|
|
public const string StopMoved = "momentum_stop";
|
|
}
|
|
}
|
|
|
|
public sealed class EquityMomentumFamily : IStrategyFamily
|
|
{
|
|
public const string FamilyId = "equity_momentum";
|
|
|
|
public const string FamilyVersion = "1";
|
|
|
|
public static EquityMomentumFamily Instance { get; } = new();
|
|
|
|
public string Id => FamilyId;
|
|
|
|
public string Version => FamilyVersion;
|
|
|
|
public string Name => "Momentum azioni";
|
|
|
|
public string Description =>
|
|
"Ogni settimana compra le azioni americane salite di più nell'ultimo anno, fino a 12, ma solo quando il mercato nel suo insieme sale. " +
|
|
"Vende quelle che perdono forza o scendono sotto la loro media; ognuna ha uno stop che sale con il prezzo.";
|
|
|
|
public IReadOnlyList<ParameterSpec> Parameters =>
|
|
[
|
|
new("positions", "Numero massimo di titoli", 12m, [8m, 12m, 16m], 3m, 30m, Whole: true),
|
|
new("stop_atr", "Stop in ATR sotto il massimo", 3m, [2m, 3m, 4m], 1m, 10m, Whole: true),
|
|
];
|
|
|
|
public IStrategy Create(StrategyParameters parameters)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(parameters);
|
|
var positions = parameters.Whole("positions");
|
|
return new EquityMomentum(new EquityMomentumSettings
|
|
{
|
|
Top = positions,
|
|
MaxPositions = positions,
|
|
AtrMultiple = (double)parameters["stop_atr"],
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>The fixed rules of <c>equity_meanrev</c> (SPEC 8.3).</summary>
|
|
public sealed record EquityMeanrevSettings
|
|
{
|
|
public int UniverseSize { get; init; } = 100;
|
|
|
|
public int Trend { get; init; } = 200;
|
|
|
|
public int RsiLength { get; init; } = 2;
|
|
|
|
public double EntryRsi { get; init; } = 10;
|
|
|
|
public double ExitRsi { get; init; } = 70;
|
|
|
|
public int Fast { get; init; } = 5;
|
|
|
|
public int MaxPositions { get; init; } = 3;
|
|
|
|
/// <summary>The entry session is the first: the time exit comes at the close of the fifth.</summary>
|
|
public int MaxSessions { get; init; } = 5;
|
|
|
|
public int AtrLength { get; init; } = 14;
|
|
|
|
public double AtrMultiple { get; init; } = 2.5;
|
|
|
|
/// <summary>Risk of one operation, as a share of the reference equity of SPEC 9.2.</summary>
|
|
public decimal RiskPerTrade { get; init; } = 0.004m;
|
|
|
|
public decimal Cap { get; init; } = 0.30m;
|
|
|
|
/// <summary>The day-trade guard of SPEC 9.2, off by default: never exit on the entry day.</summary>
|
|
public bool PdtGuard { get; init; }
|
|
|
|
/// <summary>Sessions after the entry in which an earnings report keeps the strategy out.</summary>
|
|
public int EarningsSessions { get; init; } = 3;
|
|
}
|
|
|
|
/// <summary>
|
|
/// <c>equity_meanrev</c> (SPEC 8.3): buys the short dips of solid stocks. On the close, RSI(2) below 10 and the close
|
|
/// below its 5-session average; buys at the next open the lowest RSI, up to 3 positions. It exits at 15:55 (in the
|
|
/// backtest: the close) above the 5-session average, with RSI(2) above 70, before earnings, or at the fifth session.
|
|
/// </summary>
|
|
public sealed class EquityMeanrev(EquityMeanrevSettings? settings = null) : IStrategy
|
|
{
|
|
private readonly EquityMeanrevSettings _settings = settings ?? new EquityMeanrevSettings();
|
|
|
|
public string Id => EquityMeanrevFamily.FamilyId;
|
|
|
|
public string Version => EquityMeanrevFamily.FamilyVersion;
|
|
|
|
public EquityMeanrevSettings Settings => _settings;
|
|
|
|
public IReadOnlyList<DecisionTime> Schedule() => [DecisionTime.AfterClose];
|
|
|
|
/// <summary>The first 100 stocks of the universe of 8.2, in its order, that close above their 200-session average.</summary>
|
|
public IReadOnlyList<string> Universe(UniverseContext context)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(context);
|
|
var ranked = context.Members?.Invoke(EquityMomentumFamily.FamilyId, context.Day) ?? EquityUniverseRanking.Rank(context, EquityUniverse.Size);
|
|
return [.. ranked.Where(s =>
|
|
{
|
|
var bars = context.Bars(s);
|
|
return Indicators.Sma(bars, _settings.Trend) is { } average && bars.Close(bars.Count - 1) > average;
|
|
}).Take(_settings.UniverseSize)];
|
|
}
|
|
|
|
public IReadOnlyList<Intent> Decide(StrategyContext context)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(context);
|
|
var equity = context.Portfolio.Equity;
|
|
var intents = new List<Intent>();
|
|
var freeCash = context.Portfolio.Cash;
|
|
var open = 0;
|
|
foreach (var (symbol, holding) in context.Portfolio.Holdings.Where(h => h.Value.Quantity > 0m).OrderBy(h => h.Key, StringComparer.Ordinal))
|
|
{
|
|
var bars = context.Bars(symbol);
|
|
if (bars.Count == 0)
|
|
{
|
|
open++;
|
|
continue;
|
|
}
|
|
|
|
var close = bars.Close(bars.Count - 1);
|
|
var sessions = Indicators.SessionsSince(bars, holding.EnteredOn);
|
|
var reason = ExitReason(context, symbol, bars, close, sessions);
|
|
if (reason is not null && !(_settings.PdtGuard && sessions <= 1))
|
|
{
|
|
intents.Add(new Intent(symbol, 0m, reason) { AtClose = true });
|
|
freeCash += holding.Quantity * (decimal)close; // Sold at this close, before tomorrow's entries.
|
|
}
|
|
else
|
|
{
|
|
open++;
|
|
}
|
|
}
|
|
|
|
var slots = _settings.MaxPositions - open;
|
|
if (slots <= 0 || equity <= 0m)
|
|
{
|
|
return intents;
|
|
}
|
|
|
|
var candidates = new List<(string Symbol, double Rsi, double Close, double Atr)>();
|
|
foreach (var symbol in context.Universe)
|
|
{
|
|
if (context.Portfolio.Holds(symbol) || context.Restricted?.Invoke(symbol) == true || EarningsAhead(context, symbol))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var bars = context.Bars(symbol);
|
|
if (Indicators.Rsi(bars, _settings.RsiLength) is not { } rsi || Indicators.Sma(bars, _settings.Fast) is not { } fast
|
|
|| Indicators.Atr(bars, _settings.AtrLength) is not { } atr)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var close = bars.Close(bars.Count - 1);
|
|
if (rsi < _settings.EntryRsi && close < fast)
|
|
{
|
|
candidates.Add((symbol, rsi, close, atr));
|
|
}
|
|
}
|
|
|
|
foreach (var c in candidates.OrderBy(c => c.Rsi).ThenBy(c => c.Symbol, StringComparer.Ordinal))
|
|
{
|
|
if (slots == 0)
|
|
{
|
|
break;
|
|
}
|
|
|
|
// Risk of 0.4% of the reference equity at the stop distance, capped at 30% of the strategy's capital.
|
|
var distance = Math.Round((decimal)(c.Atr * _settings.AtrMultiple), 8);
|
|
if (distance <= 0m)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var value = _settings.RiskPerTrade * context.ReferenceEquity / distance * (decimal)c.Close;
|
|
value = Math.Min(value, _settings.Cap * equity);
|
|
if (value > freeCash)
|
|
{
|
|
continue; // Not enough free capital for this candidate: it is dropped.
|
|
}
|
|
|
|
intents.Add(new Intent(c.Symbol, Math.Round(value / equity, 6, MidpointRounding.ToZero), Reasons.Entry) { StopOffset = distance });
|
|
freeCash -= value;
|
|
slots--;
|
|
}
|
|
|
|
return intents;
|
|
}
|
|
|
|
private string? ExitReason(StrategyContext context, string symbol, BarSeries bars, double close, int sessions)
|
|
{
|
|
if (Indicators.Sma(bars, _settings.Fast) is { } fast && close > fast)
|
|
{
|
|
return Reasons.ExitAverage;
|
|
}
|
|
|
|
if (Indicators.Rsi(bars, _settings.RsiLength) is > 0 and var rsi && rsi > _settings.ExitRsi)
|
|
{
|
|
return Reasons.ExitRsi;
|
|
}
|
|
|
|
if (context.NextEarnings?.Invoke(symbol) is { } earnings && context.NextSession is { } next && earnings <= next)
|
|
{
|
|
return Reasons.ExitEarnings; // The report comes out by the close of the next session.
|
|
}
|
|
|
|
return sessions >= _settings.MaxSessions ? Reasons.ExitTime : null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Earnings in the entry session or the three after it, or out after today's close (live only: the backtest has no
|
|
/// earnings calendar, SPEC 8.3).
|
|
/// </summary>
|
|
private bool EarningsAhead(StrategyContext context, string symbol)
|
|
{
|
|
if (!context.EarningsEntries || context.NextEarnings?.Invoke(symbol) is not { } earnings || context.NextSession is not { } entry)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var last = entry;
|
|
for (var i = 0; i < _settings.EarningsSessions; i++)
|
|
{
|
|
last = last.AddDays(last.DayOfWeek == DayOfWeek.Friday ? 3 : 1);
|
|
}
|
|
|
|
return earnings >= context.Day && earnings <= last;
|
|
}
|
|
|
|
public static class Reasons
|
|
{
|
|
public const string Entry = "meanrev_entry";
|
|
public const string ExitAverage = "meanrev_exit_average";
|
|
public const string ExitRsi = "meanrev_exit_rsi";
|
|
public const string ExitEarnings = "meanrev_exit_earnings";
|
|
public const string ExitTime = "meanrev_exit_time";
|
|
}
|
|
}
|
|
|
|
public sealed class EquityMeanrevFamily : IStrategyFamily
|
|
{
|
|
public const string FamilyId = "equity_meanrev";
|
|
|
|
public const string FamilyVersion = "1";
|
|
|
|
public static EquityMeanrevFamily Instance { get; } = new();
|
|
|
|
public string Id => FamilyId;
|
|
|
|
public string Version => FamilyVersion;
|
|
|
|
public string Name => "Mean reversion azioni";
|
|
|
|
public string Description =>
|
|
"Compra le azioni solide, sopra la loro media di 200 giorni, dopo un calo di pochi giorni, e le rivende al primo rimbalzo o dopo cinque sedute. " +
|
|
"Al massimo 3 posizioni, ognuna con un rischio piccolo e uno stop fisso.";
|
|
|
|
public IReadOnlyList<ParameterSpec> Parameters =>
|
|
[
|
|
new("entry_rsi", "RSI a 2 giorni per entrare (sotto)", 10m, [5m, 10m, 15m], 1m, 50m, Whole: true),
|
|
new("max_sessions", "Sedute al massimo in portafoglio", 5m, [3m, 5m, 7m], 1m, 20m, Whole: true),
|
|
];
|
|
|
|
public IStrategy Create(StrategyParameters parameters)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(parameters);
|
|
return new EquityMeanrev(new EquityMeanrevSettings
|
|
{
|
|
EntryRsi = (double)parameters["entry_rsi"],
|
|
MaxSessions = parameters.Whole("max_sessions"),
|
|
});
|
|
}
|
|
}
|