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%
#region imports
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Drawing;
    using QuantConnect;
    using QuantConnect.Algorithm.Framework;
    using QuantConnect.Algorithm.Framework.Selection;
    using QuantConnect.Algorithm.Framework.Alphas;
    using QuantConnect.Algorithm.Framework.Portfolio;
    using QuantConnect.Algorithm.Framework.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;   
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QuantConnect.Data.Custom.AlphaStreams;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion

namespace QuantConnect.Algorithm.CSharp
{
    public class ObjectStoreInsightsAlgorithm : QCAlgorithm
    {
        private string _insightsKey = "insights";

        public override void Initialize()
        {
            UniverseSettings.Resolution = Resolution.Daily;

            SetStartDate(2023, 4, 1);
            SetEndDate(2023, 4, 11);
            SetCash(100000);

            _insightsKey = $"{ProjectId}/{_insightsKey}";

            // Read the file with the insights
            if (ObjectStore.ContainsKey(_insightsKey))
            {
                var insights = ObjectStore.ReadJson<List<Insight>>(_insightsKey);
                Log($"Read {insights.Count} insight(s) from the Object Store");
                Insights.AddRange(insights);

                // Delete the key to reuse it
                ObjectStore.Delete(_insightsKey);
            }

            SetUniverseSelection(new ManualUniverseSelectionModel(QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA)));
            SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(5), 0.025, null));
            SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel(Resolution.Daily));
        }

        public override void OnEndOfAlgorithm()
        {
            // Get all active insights 
            var insights = Insights.GetInsights(x => x.IsActive(UtcTime));
            // If we want to save all insights (expired and active), we can use
            // var insights = Insights.GetInsights(x => true);

            Log($"Save {insights.Count} insight(s) to the Object Store.");
            ObjectStore.SaveJson(_insightsKey, insights);
        }
    }
}