Beispiel #1
0
 public SubAlgoValidator(SubAlgo algo, TimeSpan timeSpan,
                         Dictionary <string, IIndicator> indicators,
                         Func <SubAlgoValidator, decimal> confidenceFunction,
                         bool keepPreviousValues = false)
 {
     Algo                = algo;
     _timeSpan           = timeSpan;
     Indicators          = indicators;
     _confidenceFunction = confidenceFunction;
     if (keepPreviousValues)
     {
         _previous = new Dictionary <string, decimal>();
         foreach (var i in indicators)
         {
             _previous[i.Key] = i.Value.Current;
         }
     }
 }
Beispiel #2
0
        public decimal Percent(SubAlgo subAlgo, Symbol symbol, decimal target, decimal price)
        {
            if (!Positions.ContainsKey(symbol))
            {
                Positions[symbol] = new Position(symbol);
            }

            if (target == 0)
            {
                return(-Positions[symbol].Quantity);
            }
            else
            {
                var actual    = Positions[symbol].GetMarketValue() / TotalPortfolioValue;
                var toExecute = target - actual;

                // TODO: deal multiplicator for futures, options,  etc...
                // TODO: add bid ask & fees
                var qty = (price > 0) ? TotalPortfolioValue * toExecute / price : 0;
                return(qty);
            }
        }