コード例 #1
0
        public void AllocationRuleNo()
        {
            Portfolio p = new Portfolio();

            Position pos1 = new Position();

            pos1.status   = positionStatus.Open;
            pos1.Symbol   = new Symbol("SYM1");
            pos1.price    = 10;
            pos1.quantity = 1;

            Position pos2 = new Position();

            pos2.status   = positionStatus.Open;
            pos1.Symbol   = new Symbol("SYM2");
            pos2.price    = 10;
            pos2.quantity = 1;

            p.Positions = new List <Position>();
            p.Positions.Add(pos1);
            p.Positions.Add(pos2);

            Trade t = new Trade();

            t.type     = tradeTypes.Buy;
            t.Symbol   = new Symbol("SYM2");
            t.price    = 1;
            t.quantity = 2;

            AllocationRule r = new AllocationRule(0.5);

            Assert.Throws <AllocationViolation>(() => r.Apply(p, t));
        }
コード例 #2
0
        public void LoadSettingsFromDb()
        {
            PortfolioManager pm = new PortfolioManager();

            pm.LoadSettings();
            PortfolioRule r = pm.Rules.FirstOrDefault <PortfolioRule>(x => typeof(AllocationRule).IsInstanceOfType(x));

            Assert.IsNotNull(r);
            AllocationRule a = (AllocationRule)r;

            Assert.AreEqual(0.9, a.MaxAllocation);
        }
コード例 #3
0
        public void CreateWithSettings()
        {
            Dictionary <string, string> settings = new Dictionary <string, string>();

            settings.Add("MAX_POSITION_RATIO", "0.9");

            PortfolioManager pm = new PortfolioManager(settings);
            PortfolioRule    r  = pm.Rules.FirstOrDefault <PortfolioRule>(x => typeof(AllocationRule).IsInstanceOfType(x));

            Assert.IsNotNull(r);
            AllocationRule a = (AllocationRule)r;

            Assert.AreEqual(0.9, a.MaxAllocation);
        }
コード例 #4
0
        public static AllocationRule CreateAllocationRule(string dataAreaId,
                                                          string rule,
                                                          global::System.DateTimeOffset dateLastRun,
                                                          global::System.DateTimeOffset expirationDate,
                                                          global::System.DateTimeOffset effectiveDate,
                                                          decimal amount,
                                                          decimal fixedValue)
        {
            AllocationRule allocationRule = new AllocationRule();

            allocationRule.dataAreaId     = dataAreaId;
            allocationRule.Rule           = rule;
            allocationRule.DateLastRun    = dateLastRun;
            allocationRule.ExpirationDate = expirationDate;
            allocationRule.EffectiveDate  = effectiveDate;
            allocationRule.Amount         = amount;
            allocationRule.FixedValue     = fixedValue;
            return(allocationRule);
        }