Lexical Density Filings
Trading rules
Read the latest published plain-text filing for each security. Tokens are Unicode letter/mark sequences; normalize case with invariant .NET casing. Lexical density = distinct normalized tokens / all tokens, not candle compression or an inferred financial score. In February, May, August and November allocate only within the first three trading dates of the first security's exchange calendar. Delay within that window until at least Quintile filings are available; otherwise wait until the next review month. Long the highest-density bucket and short the lowest, floor(eligible count / Quintile) per side. Hold between reviews.
All observations must be published by the signal candle close. Intraday execution uses daily prices strictly before its UTC date; a finished one-day candle contributes its own completed date. Never warm a decision with future CSV dates.
The publication cutoff is the latest actual CloseTime among synchronized finished candles. A trading session can finish before the configured candle interval has elapsed.
Input data
FilingsFile is required CSV: SecurityId,PeriodEnd,PublishedAt,DocumentPath. Dates use yyyy-MM-dd and UTC yyyy-MM-ddTHH:mm:ssZ. DocumentPath refers to a UTF-8 plain-text file, absolute or relative to the manifest directory. Paths cannot contain commas. Empty documents, duplicate revisions and publications before PeriodEnd are rejected. Choose the newest period/revision published by the signal close; limit age by MaxReportAgeDays. The first security must provide an exchange calendar, including holidays.
Word boundaries use Unicode text elements whose leading category is a letter or combining mark; punctuation and digits separate tokens. Case normalization is invariant; no stemming or accent normalization is applied.
Parameters
| Parameter | Default |
|---|---|
Universe |
required |
Capital |
100000 |
Leverage |
1 |
MinTradeUsd |
200 |
CandleType |
TimeSpan.FromDays(1).TimeFrame() |
Quintile |
5 |
MaxReportAgeDays |
550 |
FilingsFile |
required |
Execution
Set Universe explicitly. Prices and Capital use USD, with one price unit per traded unit. Capital is a fixed budget; Leverage controls gross exposure. No stop loss or take profit is added.
Long and short baskets each receive half of Capital × Leverage. Divide each side equally, convert USD to units at the signal close and round toward zero to VolumeStep. Reconcile against actual filled positions, wait for pending orders, respect MinVolume/MaxVolume and split large adjustments across later candles. MinTradeUsd filters small adjustments; full liquidation bypasses it.
Verification
Tests run both languages using packaged BTC/TON execution data and explicit rate, financial, score, text and warmup fixtures. Calendar fixtures relocate archive OHLC/volume and provide deterministic execution quotes; they are not multi-year market history. Independent formulas, order direction/size, actual fills, residual positions and forbidden decision dates are checked. Two buckets, K=1 and AssetDecile=1 are declared mechanics profiles, not evidence of the complete production universe. No profitability claim is made.
namespace StockSharp.Samples.Strategies;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using Ecng.Common;
using Ecng.ComponentModel;
using StockSharp.Algo.Strategies;
using StockSharp.BusinessEntities;
using StockSharp.Messages;
/// <summary>Lexical Density Filings with point-in-time inputs and execution-based portfolio accounting.</summary>
public class LexicalDensityFilingsStrategy : Strategy
{
private readonly StrategyParam<IEnumerable<Security>> _universe;
private readonly StrategyParam<decimal> _capital;
private readonly StrategyParam<decimal> _leverage;
private readonly StrategyParam<decimal> _minTradeUsd;
private readonly StrategyParam<DataType> _candleType;
private readonly StrategyParam<int> _quintile;
private readonly StrategyParam<int> _maxReportAgeDays;
private readonly StrategyParam<string> _filingsFile;
private Security[] _securities = [];
private readonly Dictionary<Security, (DateTime time, decimal price, DateTime closed)> _latest = [];
private readonly Dictionary<Security, decimal> _targets = [];
private readonly List<Order> _pending = [];
private int _lastRebalance;
private DateTime? _lastBar;
private sealed record Filing(Security Security, DateTime Period, DateTime Published, decimal Density);
private readonly List<Filing> _filings = [];
/// <summary>Explicit execution securities with valid native volume metadata.</summary>
public IEnumerable<Security> Universe { get => _universe.Value; set => _universe.Value = value; }
/// <summary>Fixed capital budget in USD.</summary>
public decimal Capital { get => _capital.Value; set => _capital.Value = value; }
/// <summary>Gross target exposure divided by the capital budget.</summary>
public decimal Leverage { get => _leverage.Value; set => _leverage.Value = value; }
/// <summary>Minimum USD adjustment; complete liquidation bypasses this filter.</summary>
public decimal MinTradeUsd { get => _minTradeUsd.Value; set => _minTradeUsd.Value = value; }
/// <summary>Finished execution candle type.</summary>
public DataType CandleType { get => _candleType.Value; set => _candleType.Value = value; }
/// <summary>Number of lexical-density buckets.</summary>
public int Quintile { get => _quintile.Value; set => _quintile.Value = value; }
/// <summary>Maximum age of the latest filing period end in calendar days.</summary>
public int MaxReportAgeDays { get => _maxReportAgeDays.Value; set => _maxReportAgeDays.Value = value; }
/// <summary>Required filing manifest containing publication dates and document paths.</summary>
public string FilingsFile { get => _filingsFile.Value; set => _filingsFile.Value = value; }
/// <summary>Initialize the strategy parameters.</summary>
public LexicalDensityFilingsStrategy()
{
_universe = Param<IEnumerable<Security>>(nameof(Universe)).SetRequired()
.SetDisplay("Universe", "Explicit execution securities with valid native volume metadata", "Parameters");
_capital = Param(nameof(Capital), 100000m).SetGreaterThanZero()
.SetDisplay("Capital", "Fixed capital budget in USD", "Parameters");
_leverage = Param(nameof(Leverage), 1m).SetGreaterThanZero()
.SetDisplay("Leverage", "Gross target exposure divided by the capital budget", "Parameters");
_minTradeUsd = Param(nameof(MinTradeUsd), 200m).SetRange(0m, decimal.MaxValue)
.SetDisplay("MinTradeUsd", "Minimum USD adjustment; complete liquidation bypasses this filter", "Parameters");
_candleType = Param(nameof(CandleType), TimeSpan.FromMinutes(1440).TimeFrame())
.SetDisplay("CandleType", "Finished execution candle type", "Parameters");
_quintile = Param(nameof(Quintile), 5).SetRange(2, int.MaxValue)
.SetDisplay("Quintile", "Number of lexical-density buckets", "Parameters");
_maxReportAgeDays = Param(nameof(MaxReportAgeDays), 550).SetRange(1, int.MaxValue)
.SetDisplay("MaxReportAgeDays", "Maximum age of the latest filing period end in calendar days", "Parameters");
_filingsFile = Param<string>(nameof(FilingsFile)).SetRequired()
.SetDisplay("FilingsFile", "Required filing manifest containing publication dates and document paths", "Parameters");
}
/// <inheritdoc />
public override IEnumerable<(Security sec, DataType dt)> GetWorkingSecurities()
=> (Universe ?? []).Where(s => s is not null).DistinctBy(s => s.Id, StringComparer.OrdinalIgnoreCase).Select(s => (s, CandleType));
/// <inheritdoc />
protected override void OnReseted()
{
base.OnReseted();
_securities = [];
_latest.Clear();
_targets.Clear();
_pending.Clear();
_lastRebalance = 0;
_lastBar = null;
_filings.Clear();
}
/// <inheritdoc />
protected override void OnStarted2(DateTime time)
{
_securities = (Universe ?? []).ToArray();
if (_securities.Length == 0 || _securities.Any(s => s is null || string.IsNullOrWhiteSpace(s.Id))
|| _securities.Select(s => s.Id).Distinct(StringComparer.OrdinalIgnoreCase).Count() != _securities.Length)
throw new InvalidOperationException("Universe must contain distinct execution securities.");
foreach (var security in _securities)
{
if (security.VolumeStep is not > 0m || security.MinVolume is not > 0m || security.MaxVolume is not > 0m)
throw new InvalidOperationException("Every security needs positive VolumeStep, MinVolume and MaxVolume.");
}
if (_securities.Any(s => s.Board is null)) throw new InvalidOperationException("A review calendar requires exchange boards.");
LoadFilings();
base.OnStarted2(time);
foreach (var security in _securities)
SubscribeCandles(CandleType, security: security).Bind(candle => ProcessCandle(security, candle)).Start();
}
private void ProcessCandle(Security security, ICandleMessage candle)
{
if (candle.State != CandleStates.Finished || candle.ClosePrice <= 0m) return;
_latest[security] = (candle.OpenTime, candle.ClosePrice, candle.CloseTime);
if (_latest.Count != _securities.Length || _latest.Values.Any(v => v.time != candle.OpenTime)
|| _lastBar == candle.OpenTime || !IsFormedAndOnlineAndAllowTrading()) return;
_lastBar = candle.OpenTime;
var month = candle.OpenTime.Year * 100 + candle.OpenTime.Month;
if (_lastRebalance != month && SelectTargets(candle.OpenTime, _latest.Values.Max(v => v.closed)))
_lastRebalance = month;
ReconcileTargets();
}
private decimal Budget => Capital * Leverage;
private decimal UnitPrice(Security security) => _latest[security].price;
private decimal Units(Security security, decimal notional)
=> Math.Floor(notional / UnitPrice(security) / security.VolumeStep.Value) * security.VolumeStep.Value;
private void ReconcileTargets()
{
if (_pending.Any(o => o.State is not (OrderStates.Done or OrderStates.Failed))) return;
_pending.Clear();
foreach (var security in _securities)
{
if (!_targets.TryGetValue(security, out var target)) continue;
var delta = target - GetPositionValue(security, Portfolio).GetValueOrDefault();
if (delta == 0m || (target != 0m && Math.Abs(delta) * UnitPrice(security) < MinTradeUsd)) continue;
var step = security.VolumeStep.Value;
var quantity = Math.Floor(Math.Min(Math.Abs(delta), security.MaxVolume.Value) / step) * step;
if (quantity < security.MinVolume.Value) continue;
var order = new Order
{
Security = security, Portfolio = Portfolio, Type = OrderTypes.Market,
Side = delta > 0m ? Sides.Buy : Sides.Sell, Volume = quantity, Comment = "0376Rebalance",
};
_pending.Add(order);
RegisterOrder(order);
}
}
private static DateTime ParseUtc(string value)
=> DateTime.ParseExact(value.Trim(), "yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
private static IEnumerable<string[]> ReadRows(string path, string header, int fields)
{
using var lines = File.ReadLines(path).GetEnumerator();
if (!lines.MoveNext() || lines.Current.Trim() != header)
throw new InvalidOperationException("Invalid CSV header: expected " + header + ".");
while (lines.MoveNext())
{
if (string.IsNullOrWhiteSpace(lines.Current)) continue;
var row = lines.Current.Split(',');
if (row.Length != fields) throw new InvalidOperationException("Invalid CSV field count.");
yield return row;
}
}
private void LoadFilings()
{
var keys = new HashSet<(Security, DateTime, DateTime)>();
foreach (var row in ReadRows(FilingsFile, "SecurityId,PeriodEnd,PublishedAt,DocumentPath", 4))
{
var security = _securities.SingleOrDefault(s => string.Equals(s.Id, row[0].Trim(), StringComparison.OrdinalIgnoreCase));
if (security is null) continue;
var period = DateTime.ParseExact(row[1].Trim(), "yyyy-MM-dd", CultureInfo.InvariantCulture);
var published = ParseUtc(row[2]);
if (published.Date < period || !keys.Add((security, period, published)))
throw new InvalidOperationException("Filing revisions need causal, unique publication dates.");
var path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Path.GetFullPath(FilingsFile)), row[3].Trim()));
var words = Words(File.ReadAllText(path)).ToArray();
if (words.Length == 0) throw new InvalidOperationException("A filing must contain word tokens.");
_filings.Add(new(security, period, published, (decimal)words.Distinct(StringComparer.Ordinal).Count() / words.Length));
}
}
private static IEnumerable<string> Words(string text)
{
var buffer = new List<string>();
var elements = StringInfo.GetTextElementEnumerator(text);
while (elements.MoveNext())
{
var element = elements.GetTextElement();
var category = CharUnicodeInfo.GetUnicodeCategory(element, 0);
if (category is UnicodeCategory.UppercaseLetter or UnicodeCategory.LowercaseLetter or UnicodeCategory.TitlecaseLetter
or UnicodeCategory.ModifierLetter or UnicodeCategory.OtherLetter or UnicodeCategory.NonSpacingMark
or UnicodeCategory.SpacingCombiningMark or UnicodeCategory.EnclosingMark)
buffer.Add(element);
else if (buffer.Count > 0)
{
yield return CultureInfo.InvariantCulture.TextInfo.ToLower(string.Concat(buffer));
buffer.Clear();
}
}
if (buffer.Count > 0) yield return CultureInfo.InvariantCulture.TextInfo.ToLower(string.Concat(buffer));
}
private bool SelectTargets(DateTime time, DateTime asOf)
{
if (time.Month is not (2 or 5 or 8 or 11)) return false;
var calendar = _securities[0].Board.WorkingTime;
if (!calendar.IsWorkingDate(time.Date, true)) return false;
var first = new DateTime(time.Year, time.Month, 1);
if (Enumerable.Range(0, time.Day).Count(i => calendar.IsWorkingDate(first.AddDays(i), true)) > 3) return false;
var ranked = _securities.Select(s => _filings.Where(f => f.Security == s && f.Published <= asOf)
.OrderByDescending(f => f.Period).ThenByDescending(f => f.Published).FirstOrDefault())
.Where(f => f is not null && (time.Date - f.Period).TotalDays <= MaxReportAgeDays)
.OrderByDescending(f => f.Density).ThenBy(f => f.Security.Id, StringComparer.Ordinal).Select(f => f.Security).ToArray();
if (ranked.Length < Quintile) return false;
var count = ranked.Length / Quintile;
SetBasketTargets(ranked.Take(count), ranked.TakeLast(count), Budget);
return true;
}
private void SetBasketTargets(IEnumerable<Security> longBasket, IEnumerable<Security> shortBasket, decimal grossCapital)
{
var longs = longBasket.ToArray();
var shorts = shortBasket.ToArray();
foreach (var security in _securities) _targets[security] = 0m;
foreach (var security in longs) _targets[security] = Units(security, grossCapital / (2m * longs.Length));
foreach (var security in shorts) _targets[security] = -Units(security, grossCapital / (2m * shorts.Length));
}
}
import clr
clr.AddReference("StockSharp.Messages")
clr.AddReference("StockSharp.Algo")
clr.AddReference("StockSharp.BusinessEntities")
clr.AddReference("StockSharp.Algo.Strategies")
clr.AddReference("Ecng.ComponentModel")
from System import Boolean, DateTime, Decimal, Int32, Math, TimeSpan, InvalidOperationException
from System.Collections.Generic import IEnumerable
from System.Globalization import CultureInfo, DateTimeStyles, StringInfo, CharUnicodeInfo, UnicodeCategory
from System.IO import File, Path
from Ecng.ComponentModel import WorkingTimeExtensions
from StockSharp.Algo.Strategies import Strategy
from StockSharp.BusinessEntities import Order, Security
from StockSharp.Messages import CandleStates, DataType, OrderStates, OrderTypes, Sides
class lexical_density_filings_strategy(Strategy):
"""Lexical Density Filings with point-in-time inputs and execution-based portfolio accounting."""
def __init__(self):
super(lexical_density_filings_strategy, self).__init__()
self._universe = self.Param[IEnumerable[Security]]("Universe", None).SetRequired() \
.SetDisplay("Universe", "Explicit execution securities with valid native volume metadata", "Parameters")
self._capital = self.Param("Capital", Decimal(100000)).SetGreaterThanZero() \
.SetDisplay("Capital", "Fixed capital budget in USD", "Parameters")
self._leverage = self.Param("Leverage", Decimal(1)).SetGreaterThanZero() \
.SetDisplay("Leverage", "Gross target exposure divided by the capital budget", "Parameters")
self._min_trade_usd = self.Param("MinTradeUsd", Decimal(200)).SetRange(Decimal(0), Decimal.MaxValue) \
.SetDisplay("MinTradeUsd", "Minimum USD adjustment; complete liquidation bypasses this filter", "Parameters")
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromMinutes(1440))) \
.SetDisplay("CandleType", "Finished execution candle type", "Parameters")
self._quintile = self.Param("Quintile", 5).SetRange(2, 2147483647) \
.SetDisplay("Quintile", "Number of lexical-density buckets", "Parameters")
self._max_report_age_days = self.Param("MaxReportAgeDays", 550).SetRange(1, 2147483647) \
.SetDisplay("MaxReportAgeDays", "Maximum age of the latest filing period end in calendar days", "Parameters")
self._filings_file = self.Param[str]("FilingsFile", None).SetRequired() \
.SetDisplay("FilingsFile", "Required filing manifest containing publication dates and document paths", "Parameters")
self._clear_state()
def _clear_state(self):
self._securities = []
self._latest = {}
self._targets = {}
self._pending = []
self._last_rebalance = 0
self._last_bar = None
self._filings = []
@property
def Universe(self):
return self._universe.Value
@Universe.setter
def Universe(self, value):
self._universe.Value = value
@property
def Capital(self):
return self._capital.Value
@Capital.setter
def Capital(self, value):
self._capital.Value = value
@property
def Leverage(self):
return self._leverage.Value
@Leverage.setter
def Leverage(self, value):
self._leverage.Value = value
@property
def MinTradeUsd(self):
return self._min_trade_usd.Value
@MinTradeUsd.setter
def MinTradeUsd(self, value):
self._min_trade_usd.Value = value
@property
def CandleType(self):
return self._candle_type.Value
@CandleType.setter
def CandleType(self, value):
self._candle_type.Value = value
@property
def Quintile(self):
return self._quintile.Value
@Quintile.setter
def Quintile(self, value):
self._quintile.Value = value
@property
def MaxReportAgeDays(self):
return self._max_report_age_days.Value
@MaxReportAgeDays.setter
def MaxReportAgeDays(self, value):
self._max_report_age_days.Value = value
@property
def FilingsFile(self):
return self._filings_file.Value
@FilingsFile.setter
def FilingsFile(self, value):
self._filings_file.Value = value
def GetWorkingSecurities(self):
return [(s, self.CandleType) for s in self.Universe] if self.Universe is not None else []
def OnReseted(self):
super(lexical_density_filings_strategy, self).OnReseted()
self._clear_state()
def OnStarted2(self, time):
self._securities = list(self.Universe) if self.Universe is not None else []
if not self._securities or any(s is None or not s.Id for s in self._securities) or len(set(s.Id.upper() for s in self._securities)) != len(self._securities):
raise InvalidOperationException("Universe must contain distinct execution securities.")
for security in self._securities:
if security.VolumeStep is None or security.MinVolume is None or security.MaxVolume is None or security.VolumeStep <= 0 or security.MinVolume <= 0 or security.MaxVolume <= 0:
raise InvalidOperationException("Every security needs positive VolumeStep, MinVolume and MaxVolume.")
if any(s.Board is None for s in self._securities):
raise InvalidOperationException("A review calendar requires exchange boards.")
self._load_filings()
super(lexical_density_filings_strategy, self).OnStarted2(time)
for security in self._securities:
self.SubscribeCandles(self.CandleType, True, security).Bind(lambda candle, s=security: self._process_candle(s, candle)).Start()
def _process_candle(self, security, candle):
if candle.State != CandleStates.Finished or candle.ClosePrice <= 0:
return
self._latest[security] = (candle.OpenTime, candle.ClosePrice, candle.CloseTime)
if len(self._latest) != len(self._securities) or any(value[0] != candle.OpenTime for value in self._latest.values()) or self._last_bar == candle.OpenTime or not self.IsFormedAndOnlineAndAllowTrading():
return
self._last_bar = candle.OpenTime
month = candle.OpenTime.Year * 100 + candle.OpenTime.Month
if self._last_rebalance != month and self._select_targets(candle.OpenTime, max(value[2] for value in self._latest.values())):
self._last_rebalance = month
self._reconcile_targets()
def _budget(self):
return self.Capital * self.Leverage
def _unit_price(self, security):
return self._latest[security][1]
def _units(self, security, notional):
return Math.Floor(notional / self._unit_price(security) / security.VolumeStep) * security.VolumeStep
def _reconcile_targets(self):
if any(o.State != OrderStates.Done and o.State != OrderStates.Failed for o in self._pending):
return
self._pending = []
for security in self._securities:
if security not in self._targets:
continue
target = self._targets[security]
position = self.GetPositionValue(security, self.Portfolio)
delta = target - (position if position is not None else Decimal(0))
if delta == 0 or (target != 0 and abs(delta) * self._unit_price(security) < self.MinTradeUsd):
continue
quantity = Math.Floor(min(abs(delta), security.MaxVolume) / security.VolumeStep) * security.VolumeStep
if quantity < security.MinVolume:
continue
order = Order()
order.Security = security
order.Portfolio = self.Portfolio
order.Type = OrderTypes.Market
order.Side = Sides.Buy if delta > 0 else Sides.Sell
order.Volume = quantity
order.Comment = "0376Rebalance"
self._pending.append(order)
self.RegisterOrder(order)
@staticmethod
def _parse_utc(value):
return DateTime.ParseExact(value.strip(), "yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal)
@staticmethod
def _read_rows(path, header, fields):
lines = list(File.ReadLines(path))
if not lines or lines[0].strip() != header:
raise InvalidOperationException("Invalid CSV header: expected " + header + ".")
for line in lines[1:]:
if not line.strip():
continue
row = line.split(",")
if len(row) != fields:
raise InvalidOperationException("Invalid CSV field count.")
yield row
def _load_filings(self):
keys = set()
for row in self._read_rows(self.FilingsFile, "SecurityId,PeriodEnd,PublishedAt,DocumentPath", 4):
security = next((s for s in self._securities if s.Id.upper() == row[0].strip().upper()), None)
if security is None:
continue
period = DateTime.ParseExact(row[1].strip(), "yyyy-MM-dd", CultureInfo.InvariantCulture)
published = self._parse_utc(row[2])
key = (security, period, published)
if published.Date < period or key in keys:
raise InvalidOperationException("Filing revisions need causal, unique publication dates.")
keys.add(key)
path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Path.GetFullPath(self.FilingsFile)), row[3].strip()))
words = list(self._words(File.ReadAllText(path)))
if not words:
raise InvalidOperationException("A filing must contain word tokens.")
self._filings.append((security, period, published, Decimal(len(set(words))) / Decimal(len(words))))
@staticmethod
def _words(text):
buffer = []
elements = StringInfo.GetTextElementEnumerator(text)
categories = (UnicodeCategory.UppercaseLetter, UnicodeCategory.LowercaseLetter, UnicodeCategory.TitlecaseLetter,
UnicodeCategory.ModifierLetter, UnicodeCategory.OtherLetter, UnicodeCategory.NonSpacingMark,
UnicodeCategory.SpacingCombiningMark, UnicodeCategory.EnclosingMark)
while elements.MoveNext():
element = elements.GetTextElement()
if CharUnicodeInfo.GetUnicodeCategory(element, 0) in categories:
buffer.append(element)
elif buffer:
yield CultureInfo.InvariantCulture.TextInfo.ToLower("".join(buffer))
buffer = []
if buffer:
yield CultureInfo.InvariantCulture.TextInfo.ToLower("".join(buffer))
def _select_targets(self, time, as_of):
if time.Month not in (2, 5, 8, 11):
return False
calendar = self._securities[0].Board.WorkingTime
if not WorkingTimeExtensions.IsWorkingDate(calendar, time.Date, True):
return False
first = DateTime(time.Year, time.Month, 1)
if sum(1 for i in range(time.Day) if WorkingTimeExtensions.IsWorkingDate(calendar, first.AddDays(i), True)) > 3:
return False
ranked = []
for security in self._securities:
available = [f for f in self._filings if f[0] == security and f[2] <= as_of]
filing = max(available, key=lambda f: (f[1], f[2])) if available else None
if filing is not None and (time.Date - filing[1]).TotalDays <= self.MaxReportAgeDays:
ranked.append(filing)
if len(ranked) < self.Quintile:
return False
ranked = [f[0] for f in sorted(ranked, key=lambda f: (-f[3], f[0].Id))]
count = len(ranked) // self.Quintile
self._set_basket_targets(ranked[:count], ranked[-count:], self._budget())
return True
def _set_basket_targets(self, longs, shorts, gross):
self._targets = {s: Decimal(0) for s in self._securities}
for security in longs:
self._targets[security] = self._units(security, gross / Decimal(2 * len(longs)))
for security in shorts:
self._targets[security] = -self._units(security, gross / Decimal(2 * len(shorts)))
def CreateClone(self):
return lexical_density_filings_strategy()