Ejemplo n.º 1
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    public void ShowNavModeAssets(ApplicationMain.NAVIGATION_MODE mode)
    {
        ASSETS assets = ASSETS.COORDS;

        if (mode == ApplicationMain.NAVIGATION_MODE.MAP)
        {
            assets |= ASSETS.MAP_DISPLAY_MODE;
        }

        if (mode == ApplicationMain.NAVIGATION_MODE.MAP)
        {
            assets |= ASSETS.MAP_ZOOM;
        }

        if (m_UI != null)
        {
            m_UI.SetActive(assets != 0);

            if (m_UI.activeInHierarchy)
            {
                if (m_coords != null)
                {
                    m_coords.SetActive((assets & ASSETS.COORDS) != 0);
                }

                if (m_mapDisplatMode != null)
                {
                    m_mapDisplatMode.SetActive((assets & ASSETS.MAP_DISPLAY_MODE) != 0);
                }

                if (m_mapZoom != null)
                {
                    m_mapZoom.SetActive((assets & ASSETS.MAP_ZOOM) != 0);
                }

                if (m_mapSourceIcon != null)
                {
                    m_mapSourceIcon.SetActive((assets & ASSETS.MAP_DISPLAY_MODE) != 0);
                }

                if (m_mapSource != null)
                {
                    m_mapSource.SetActive((assets & ASSETS.MAP_DISPLAY_MODE) != 0);
                }

                if (m_mapButtons != null)
                {
                    m_mapButtons.SetActive((assets & ASSETS.MAP_DISPLAY_MODE) != 0);
                }
            }
        }
    }
Ejemplo n.º 2
0
    public static string GetAssetUrl(ASSETS asset)
    {
        switch (asset)
        {
        case ASSETS.android_asset:
            return(m_szAndroidAssetUrl);

        case ASSETS.json:
            return(m_szJsonUrl);

        case ASSETS.windows_asset:
            return(m_szWindowsAssetUrl);

        default:
            return("error");
        }
    }
Ejemplo n.º 3
0
        public override IEnumerable <Bar> Run(DateTime?startTime, DateTime?endTime)
        {
            //========== initialization ==========

            StartTime       = startTime ?? Globals.START_TIME;
            EndTime         = endTime ?? Globals.END_TIME;
            WarmupStartTime = StartTime - TimeSpan.FromDays(90);

            CommissionPerShare = Globals.COMMISSION;
            Deposit(Globals.INITIAL_CAPITAL);

            var assets = ASSETS
                         .Select(o => AddDataSource(o))
                         .ToList();
            var tbill = TBILL != null?AddDataSource(TBILL) : null;

            var bench = AddDataSource(BENCH);

            //========== simulation loop ==========

            var weights = new Dictionary <Instrument, double>();

            foreach (var s in SimTimes)
            {
                if (!HasInstruments(assets) || !HasInstrument(bench))
                {
                    continue;
                }

                if (weights.Count == 0 || IsOptimizationDay)
                {
                    var weightsNew = Optimize(assets.Select(a => a.Instrument), tbill?.Instrument);
                    weights = Tranching(weightsNew);
                }

                var assetReturns = Instruments
                                   .ToDictionary(
                    i => i,
                    i => i.Close.LogReturn());

                var rawPortfolioReturns = IndicatorsBasic.BufferedLambda(
                    prev => weights.Sum(kv => kv.Value * assetReturns[kv.Key][0]),
                    0.0);

                var volAdj = IndicatorsBasic.BufferedLambda(
                    prev => VolatilityOverlay(rawPortfolioReturns),
                    0.0);

                if (Positions.Count == 0 || IsTradingDay)
                {
                    foreach (var kv in weights)
                    {
                        var i = kv.Key;
                        var w = volAdj[0] * kv.Value;
                        Alloc.Allocation[i] = w;

                        var shares = (int)Math.Floor(w * NetAssetValue[0] / i.Close[0]);
                        i.Trade(shares - i.Position);
                    }
                }

                if (!IsOptimizing && TradingDays > 0)
                {
                    _plotter.AddNavAndBenchmark(this, bench.Instrument);
                    _plotter.AddStrategyHoldings(this, assets.Select(a => a.Instrument));
                    if (Alloc.LastUpdate == SimTime[0])
                    {
                        _plotter.AddTargetAllocationRow(Alloc);
                    }

                    _plotter.SelectChart("Portfolio Volatility", "Date");
                    _plotter.SetX(SimTime[0]);
                    _plotter.Plot("Volatility NAV", 100.0 * Math.Sqrt(252.0) * NetAssetValue.Volatility(21)[0]);
                    _plotter.Plot("Volatility Raw", 100.0 * Math.Sqrt(252.0) * rawPortfolioReturns.StandardDeviation(21)[0]);
                    _plotter.Plot("Total Exposure", 100.0 * volAdj[0]);
                }

                var v = 10.0 * NetAssetValue[0] / Globals.INITIAL_CAPITAL;
                yield return(Bar.NewOHLC(
                                 Name, SimTime[0],
                                 v, v, v, v, 0));
            }

            //========== post processing ==========

            if (!IsOptimizing)
            {
                _plotter.AddTargetAllocation(Alloc);
                _plotter.AddOrderLog(this);
                _plotter.AddPositionLog(this);
                _plotter.AddPnLHoldTime(this);
                _plotter.AddMfeMae(this);
                _plotter.AddParameters(this);
            }

            FitnessValue = this.CalcFitness();

            yield break;
        }