You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creating a thread to discuss on security caching sugar, to remove some of the boiler plate scaffolding required building multi asset strategies.
Expected Behavior
Minimal boiler plate code possible. Ideally not require all users to create parallel dictionaries or management classes.
Actual Behavior
To tidily hold multiple securities alpha / trade management you often need to create boiler plate symbol data classes.
With python duck typing it happens for free; but the objects are not transferred between Alpha-Universe models. It would be ideal to suggest a route that transfers that data.
Potential Solution
A use pattern like this: applied with a class collection;
This eliminates the need for the Alpha/QCAlgorithm/Universe Dictionary<Symbol, SymbolData> class and adding/removing it with the OnSecurities changed event.
class SymbolData;
#Store and return or fetch
alpha = security.Store<SymbolData>("key", new SymbolData())
alpha = security.Fetch<SymbolData>("key")
if (alpha.EMAShort > alpha.EMALong)
{
}
or applied directly with objects / no class:
Eliminates the boiler plate wrapper SymbolData class entirely.
# Store and return
long = security.Store<Indicator>("EMA_Long", EMA(security.Symbol, 200));
short = security.Store<Indicator>("EMA_Short", EMA(security.Symbol, 50));
if (short > long)
{
SetHoldings(security.Symbol, 1);
}
#Without saving object / e.g. universes
if (security.Fetch<Indicator>("EMA_Short") > security.Fetch<Indicator>("EMA_Long") )
{
}
Possibly this could be implemented under the hood in the existing SecurityCache class, or extending/replacing the current Security Cache class:
security.Cache.Set(key, value)
security.Cache.Get(key)
security.Cache.Set<T>(key, value)
T security.Cache.Get<T>(key)
Or direct indexer on the Security Object with dynamics+reflection❤️; stored to dynamic Security Cache sub collection under hood. When speed a concern people can switch to typed version.
Puts it on level field with python duck typing, and extends python duck typing to work anywhere in the algorithm.
OnSecuritiesChanged(changes)
for security in changes.AddedSecurities {
security.Long = EMA(security.Symbol, 200)
security.Short = EMA(security.Symbol, 200)
}
...
if (security.Short > security.Long)
...
security.Cache.SetDynamic(key, value)
security.Cache.GetDynamic(key)
Checklist
I have completely filled out this template
I have confirmed that this issue exists on the current master branch
I have confirmed that this is not a duplicate issue by searching issues
The text was updated successfully, but these errors were encountered:
Quick test worked nicely, but for clear separation of properties vs more complex types perhaps the storage collection should be divided into custom-properties and custom-objects in general -- like:
Cache.Properties["EMA"] <<-- security.EMA // accessible only with dynamic key word
Cache.Set("key", value) <<-- security.Set("key", value) // accessible with Get<T>
Cache.Get<T>("ema200") <<-- security.Get<Indicator>("ema200") // accessible with Get<T>
Potentially would solve the often requested "How do I pipe data through the framework?" question rather than attaching other signal objects to Insights.
Creating a thread to discuss on security caching sugar, to remove some of the boiler plate scaffolding required building multi asset strategies.
Expected Behavior
Minimal boiler plate code possible. Ideally not require all users to create parallel dictionaries or management classes.
Actual Behavior
To tidily hold multiple securities alpha / trade management you often need to create boiler plate symbol data classes.
With python duck typing it happens for free; but the objects are not transferred between Alpha-Universe models. It would be ideal to suggest a route that transfers that data.
Potential Solution
A use pattern like this: applied with a class collection;
Dictionary<Symbol, SymbolData>
class and adding/removing it with the OnSecurities changed event.or applied directly with objects / no class:
Possibly this could be implemented under the hood in the existing SecurityCache class, or extending/replacing the current Security Cache class:
Or direct indexer on the Security Object with dynamics+reflection❤️; stored to dynamic Security Cache sub collection under hood. When speed a concern people can switch to typed version.
Checklist
master
branchThe text was updated successfully, but these errors were encountered: