Forex_Strategy_Builder.Backtester.RolloverInMoney C# (CSharp) Метод

RolloverInMoney() публичный статический Метод

Calculates the rollover fee in currency.
public static RolloverInMoney ( PosDirection posDir, double lots, int daysRollover, double price ) : double
posDir PosDirection
lots double
daysRollover int
price double
Результат double
        public static double RolloverInMoney(PosDirection posDir, double lots, int daysRollover, double price)
        {
            double point   = Data.InstrProperties.Point;
            int    lotSize = Data.InstrProperties.LotSize;
            double swapLongPips  = 0; // Swap long in pips
            double swapShortPips = 0; // Swap short in pips
            if (Data.InstrProperties.SwapType == Commission_Type.pips)
            {
                swapLongPips  = Data.InstrProperties.SwapLong;
                swapShortPips = Data.InstrProperties.SwapShort;
            }
            else if (Data.InstrProperties.SwapType == Commission_Type.percents)
            {
                swapLongPips  = (price / point) * (0.01 * Data.InstrProperties.SwapLong / 365);
                swapShortPips = (price / point) * (0.01 * Data.InstrProperties.SwapShort / 365);
            }
            else if (Data.InstrProperties.SwapType == Commission_Type.money)
            {
                swapLongPips  = Data.InstrProperties.SwapLong  / (point * lotSize);
                swapShortPips = Data.InstrProperties.SwapShort / (point * lotSize);
            }

            double rollover = lots * lotSize * (posDir == PosDirection.Long ? swapLongPips : -swapShortPips) * point * daysRollover / Backtester.AccountExchangeRate(price);

            return rollover;
        }

Usage Example

        /// <summary>
        /// Calculates the result
        /// </summary>
        private void Calculate()
        {
            bool         isLong       = (CbxDirection.SelectedIndex == 0);
            PosDirection posDir       = isLong ? PosDirection.Long : PosDirection.Short;
            int          lotSize      = Data.InstrProperties.LotSize;
            var          lots         = (double)NUDLots.Value;
            var          entryPrice   = (double)NUDEntryPrice.Value;
            var          exitPrice    = (double)NUDExitPrice.Value;
            var          daysRollover = (int)NUDDays.Value;
            double       point        = Data.InstrProperties.Point;
            string       unit         = " " + Configs.AccountCurrency;
            double       entryValue   = lots * lotSize * entryPrice;
            double       exitValue    = lots * lotSize * exitPrice;

            // Required margin
            double requiredMargin = (lots * lotSize / Configs.Leverage) *
                                    (entryPrice / Backtester.AccountExchangeRate(entryPrice));

            AlblOutputValues[0].Text = requiredMargin.ToString("F2") + unit;

            // Gross Profit
            double grossProfit = (isLong ? exitValue - entryValue : entryValue - exitValue) /
                                 Backtester.AccountExchangeRate(exitPrice);

            AlblOutputValues[1].Text = grossProfit.ToString("F2") + unit;

            // Spread
            double spread = Data.InstrProperties.Spread * point * lots * lotSize / Backtester.AccountExchangeRate(exitPrice);

            AlblOutputValues[2].Text = spread.ToString("F2") + unit;

            // Entry Commission
            double entryCommission = Backtester.CommissionInMoney(lots, entryPrice, false);

            AlblOutputValues[3].Text = entryCommission.ToString("F2") + unit;

            // Exit Commission
            double exitCommission = Backtester.CommissionInMoney(lots, exitPrice, true);

            AlblOutputValues[4].Text = exitCommission.ToString("F2") + unit;

            // Rollover
            double rollover = Backtester.RolloverInMoney(posDir, lots, daysRollover, exitPrice);

            AlblOutputValues[5].Text = rollover.ToString("F2") + unit;

            // Slippage
            double slippage = Data.InstrProperties.Slippage * point * lots * lotSize / Backtester.AccountExchangeRate(exitPrice);

            AlblOutputValues[6].Text = slippage.ToString("F2") + unit;

            // Net Profit
            double netProfit = grossProfit - entryCommission - exitCommission - rollover - slippage;

            AlblOutputValues[7].Text = netProfit.ToString("F2") + unit;
        }