Beispiel #1
0
        public void 大会期間をスラッシュで表示する()
        {
            var act = new HoldingPeriod(
                new DateTime(2020, 9, 25),
                new DateTime(2020, 10, 2));

            Assert.Equal("2020/9/25 ~ 2020/10/2", act.ShortDisplayValue);
        }
Beispiel #2
0
        public void 大会期間を年月日で表示する()
        {
            var act = new HoldingPeriod(
                new DateTime(2020, 9, 25),
                new DateTime(2020, 10, 2));

            Assert.Equal("2020年9月25日 ~ 2020年10月2日", act.DisplayValue);
        }
Beispiel #3
0
 /// <summary>
 /// Initializes this object
 /// </summary>
 /// <param name="tansactionId">The Id of the selling/dividend transaction</param>
 /// <param name="profitAbsolute">Absolute profit</param>
 /// <param name="profitPercentage">Relative profit</param>
 /// <param name="buyDate">The first buying date</param>
 /// <param name="sellDate">The sell date</param>
 /// <param name="r">The maximum risk per trade</param>
 public TransactionPerformance(Guid tansactionId, decimal profitAbsolute, decimal profitPercentage, DateTime buyDate, DateTime sellDate, decimal r)
 {
     Id               = tansactionId;
     ProfitAbsolute   = profitAbsolute;
     ProfitPercentage = profitPercentage;
     ProfitMade       = ProfitAbsolute > 0;
     HoldingPeriod    = new HoldingPeriod(buyDate, sellDate);
     R = r;
 }
Beispiel #4
0
        public void JSONのシリアライズとデシリアライズが正常に実行されること(
            int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay)
        {
            var startDate        = new DateTime(startYear, startMonth, startDay);
            var endDate          = new DateTime(endYear, endMonth, endDay);
            var oldHoldingPeriod = new HoldingPeriod(startDate, endDate);
            var json             = oldHoldingPeriod.ToJson();
            var newHoldingPeriod = HoldingPeriod.FromJson(json);

            Assert.Equal(startDate, newHoldingPeriod.StartDate);
            Assert.Equal(endDate, newHoldingPeriod.EndDate);
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransactionDividendCalculatedEvent"/> class.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 /// <param name="profitAbsolute">The profit absolute.</param>
 /// <param name="profitPercentage">The profit percentage.</param>
 /// <param name="profitMade">if set to <c>true</c> [profit made].</param>
 /// <param name="holdingPeriod">The holding period.</param>
 /// <param name="r">The r.</param>
 public TransactionDividendCalculatedEvent(Guid id, Type aggregateType,
                                           decimal profitAbsolute,
                                           decimal profitPercentage,
                                           bool profitMade,
                                           HoldingPeriod holdingPeriod,
                                           decimal r)
     : base(id, aggregateType)
 {
     ProfitAbsolute   = profitAbsolute;
     ProfitPercentage = profitPercentage;
     ProfitMade       = profitMade;
     HoldingPeriod    = holdingPeriod;
     R = r;
 }
Beispiel #6
0
        public void 申込終了日が開催期間と重なっている場合例外()
        {
            var holdingPeriod = new HoldingPeriod(
                new DateTime(2020, 9, 25),
                new DateTime(2020, 10, 2));

            holdingPeriod.EnsureValidApplicationEndDate(null);
            holdingPeriod.EnsureValidApplicationEndDate(new DateTime(2020, 9, 24));
            var exception = Assert.Throws <ArgumentException>(
                () => holdingPeriod.EnsureValidApplicationEndDate(new DateTime(2020, 9, 25)));

            Assert.Equal(
                "申込期間が開催期間と重複しています。",
                exception.Message);
        }
Beispiel #7
0
        public void 開催日が開催期間の範囲に収まっていること()
        {
            var holdingPeriod = new HoldingPeriod(
                new DateTime(2020, 9, 25),
                new DateTime(2020, 10, 2));

            var holdingDates = new List <HoldingDate>()
            {
                new HoldingDate(new DateTime(2020, 9, 25)),
                new HoldingDate(new DateTime(2020, 9, 26)),
                new HoldingDate(new DateTime(2020, 10, 1)),
                new HoldingDate(new DateTime(2020, 10, 2))
            };

            holdingPeriod.EnsureValidHoldingDates(holdingDates);
        }
Beispiel #8
0
        public void 開催日が開催期間の範囲に収まっていない場合例外(int year, int month, int day)
        {
            var holdingPeriod = new HoldingPeriod(
                new DateTime(2020, 9, 25),
                new DateTime(2020, 10, 2));

            var holdingDates = new List <HoldingDate>()
            {
                new HoldingDate(new DateTime(year, month, day))
            };

            var exception = Assert.Throws <ArgumentException>(
                () => holdingPeriod.EnsureValidHoldingDates(holdingDates));

            Assert.Equal(
                "開催期間の範囲外の開催日が指定されています。",
                exception.Message);
        }
        public HoldingPeriodYieldPricer(HoldingPeriod holdingPeriod, double startAi, double endAi, double principalBetweenTemp, double interestBetweenTemp)
        {
            _startDate       = holdingPeriod.StartDate;
            _endDate         = holdingPeriod.UnderlyingMaturityDate;
            _side            = holdingPeriod.Direction == Direction.BuyThenSell ? 1.0 : -1.0;
            _notional        = holdingPeriod.Notional;
            _faceAmount      = 100.0;
            _startCommission = holdingPeriod.StartFrontCommission + holdingPeriod.StartBackCommission;
            _endCommission   = holdingPeriod.EndFrontCommission + holdingPeriod.EndBackCommission;
            _allCommission   = _startCommission + _endCommission;
            _yearFraction    = holdingPeriod.PaymentBusinessDayCounter.CalcDayCountFraction(_startDate, _startDate == _endDate ? _endDate.AddDays(1) : _endDate);
            _businessTaxRate = holdingPeriod.BusinessTaxRate;
            _interestTaxRate = holdingPeriod.InterestTaxRate;
            _holdingCost     = holdingPeriod.HoldingCost;

            _startAi = startAi;
            _endAi   = endAi;
            _principalBetweenTemp = principalBetweenTemp;
            _interestBetweenTemp  = interestBetweenTemp;
        }
 public void Configure(EntityTypeBuilder <Tournament> builder)
 {
     builder.ToTable("tournaments");
     builder.Property(o => o.Id).HasSnakeCaseColumnName();
     builder.Property(o => o.AggregationMonth)
     .HasConversion(o => o.Value, o => new AggregationMonth(o))
     .HasSnakeCaseColumnName();
     builder.Property(o => o.ApplicationPeriod)
     .HasConversion(o => o.ToJson(), o => ApplicationPeriod.FromJson(o))
     .HasSnakeCaseColumnName();
     builder.Property(o => o.EntryFee)
     .HasConversion(o => o.Value, o => new EntryFee(o))
     .HasSnakeCaseColumnName();
     builder.Property(o => o.HoldingPeriod)
     .HasConversion(o => o.ToJson(), o => HoldingPeriod.FromJson(o))
     .HasSnakeCaseColumnName();
     builder.Property(o => o.Outline)
     .HasConversion(o => o.Value, o => new Outline(o))
     .HasSnakeCaseColumnName();
     builder.Property(o => o.RegistrationYear)
     .HasConversion(o => o.Value, o => new RegistrationYear(o))
     .HasSnakeCaseColumnName();
     builder.Property(o => o.TournamentName)
     .HasConversion(o => o.Value, o => new TournamentName(o))
     .HasSnakeCaseColumnName();
     builder.Property(o => o.Venue)
     .HasConversion(o => o.Value, o => new Venue(o))
     .HasSnakeCaseColumnName();
     builder.Property(o => o.MethodOfPayment)
     .HasEnumerationConversion()
     .HasSnakeCaseColumnName();
     builder.Property(o => o.TournamentType)
     .HasEnumerationConversion()
     .HasSnakeCaseColumnName();
     builder.Property(o => o.TypeOfYear)
     .HasEnumerationConversion()
     .HasSnakeCaseColumnName();
     builder.Property(o => o.TournamentEntryReceptionMailSubject).HasSnakeCaseColumnName();
     builder.Property(o => o.TournamentEntryReceptionMailBody).HasSnakeCaseColumnName();
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransactionPerformanceCalculatedEvent"/> class.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 /// <param name="profitAbsolute">The profit absolute.</param>
 /// <param name="profitPercentage">The profit percentage.</param>
 /// <param name="profitMade">if set to <c>true</c> [profit made].</param>
 /// <param name="holdingPeriod">The holding period.</param>
 /// <param name="r">The r.</param>
 /// <param name="exitEfficiency">The exit efficiency.</param>
 /// <param name="entryEfficiency">The entry efficiency.</param>
 /// <param name="maeAbsolute">The mae absolute.</param>
 /// <param name="mfeAbsolute">The mfe absolute.</param>
 public TransactionPerformanceCalculatedEvent(Guid id, Type aggregateType,
                                              decimal profitAbsolute,
                                              decimal profitPercentage,
                                              bool profitMade,
                                              HoldingPeriod holdingPeriod,
                                              decimal r,
                                              decimal?exitEfficiency,
                                              decimal?entryEfficiency,
                                              decimal?maeAbsolute,
                                              decimal?mfeAbsolute)
     : base(id, aggregateType)
 {
     ProfitAbsolute   = profitAbsolute;
     ProfitPercentage = profitPercentage;
     ProfitMade       = profitMade;
     HoldingPeriod    = holdingPeriod;
     R = r;
     ExitEfficiency  = exitEfficiency;
     EntryEfficiency = entryEfficiency;
     MAEAbsolute     = maeAbsolute;
     MFEAbsolute     = mfeAbsolute;
 }
Beispiel #12
0
    public static List<HoldingPeriod> GenerateHoldingPeriods(ConstructGen<double> historicalWeights_, double? trimDistributionsBy_=null)
    {
      var ret = new List<HoldingPeriod>();

      for (int colIndex = 0; colIndex < historicalWeights_.ArrayLength; ++colIndex)
      {
        var colVals = historicalWeights_.GetColumnValuesAsDDC(colIndex);

        if (colVals.Data.SumAbs() == 0d)
          continue;

        Dictionary<WtState, List<double>> dict = new Dictionary<WtState, List<double>>();

        WtState currentState = WtState.None;
        DateTime stateStart = DateTime.MinValue;

        for (int i = 0; i < colVals.Length; ++i)
        {
          var wt = colVals.Data[i];

          WtState newState = (wt > 0d) ? WtState.Long : (wt < 0d) ? WtState.Short : WtState.Flat;

          if (currentState == WtState.None)
          {
            stateStart = colVals.Dates[i];
            currentState = newState;
          }
          else if (newState == currentState)
          {
            // do nothing
          }
          else // we have a new state
          {
            var ts = colVals.Dates[i] - stateStart;

            if (!dict.ContainsKey(currentState)) dict[currentState] = new List<double>();


            dict[currentState].Add(MyCalendar.NumBusinessDaysBetween(stateStart,colVals.Dates[i]));

            currentState = newState;
            stateStart = colVals.Dates[i];
          }
        }

        // commit the last values

        {

        }

        var hp = new HoldingPeriod()
        {
          Ccy=historicalWeights_.ColumnHeadings[colIndex],
          State=currentState,
          Held=MyCalendar.NumBusinessDaysBetween(stateStart,DateTime.Today),
          Wt=colVals.Data.Last()
        };

        foreach (var key in dict.Keys)
        {
          if (trimDistributionsBy_.HasValue && trimDistributionsBy_.Value >0d && trimDistributionsBy_ <1d)
          {
            var series = dict[key].OrderBy(x => x);

            int numberInTail = Convert.ToInt32(series.Count() * trimDistributionsBy_.Value);

            //var subset = series.TakeWhile<double>(
          }

          hp.SetValues(key, dict[key]);


        }

        ret.Add(hp);
      }

      return ret;
    }