Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
6.614%
Drawdown
0.800%
Expectancy
0
Net Profit
0.193%
Sharpe Ratio
1.094
Probabilistic Sharpe Ratio
50.505%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.028
Beta
1.055
Annual Standard Deviation
0.046
Annual Variance
0.002
Information Ratio
5.292
Tracking Error
0.006
Treynor Ratio
0.048
Total Fees
$1.22
Estimated Strategy Capacity
$980000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
8.99%
from AlgorithmImports import *
from Newtonsoft.Json import JsonConvert
from System.Collections.Generic import List

class ObjectStoreInsightsAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.UniverseSettings.Resolution = Resolution.Daily

        self.SetStartDate(2023,4,1)
        self.SetEndDate(2023,4,11)
        self.SetCash(100000)

        self.insightsKey = f"{self.ProjectId}/insights"

        # Read the file with the insights
        if self.ObjectStore.ContainsKey(self.insightsKey):
            insights = self.ObjectStore.ReadJson[List[Insight]](self.insightsKey)
            self.Log(f"Read {len(insights)} insight(s) from the Object Store")
            self.Insights.AddRange(insights)

            # Delete the key to reuse it
            self.ObjectStore.Delete(self.insightsKey)

        self.SetUniverseSelection(ManualUniverseSelectionModel([ Symbol.Create("SPY", SecurityType.Equity, Market.USA) ]))
        self.SetAlpha(ConstantAlphaModel(InsightType.Price, InsightDirection.Up, timedelta(5), 0.025, None))
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel(Resolution.Daily))

    def OnEndOfAlgorithm(self):
        # Get all active insights 
        insights = self.Insights.GetInsights(lambda x: x.IsActive(self.UtcTime))
        # If we want to save all insights (expired and active), we can use
        # insights = self.Insights.GetInsights(lambda x: True)

        self.Log(f"Save {len(insights)} insight(s) to the Object Store.")
        content = ','.join([JsonConvert.SerializeObject(x) for x in insights])
        self.ObjectStore.Save(self.insightsKey, f'[{content}]')