Berechnung Werte der Ordermaske

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    • Berechnung Werte der Ordermaske

      Liebe Gemeinde,

      ich würde gerne die Werte:

      - Units Available
      - 1 PIP
      - Trade value
      - Margin used

      berechnen.

      Ich weiß auch, sie hängen für die verschiedenen Währungen z.T. von den Währungen ab.
      Balance, Hebel, Pip Größe je Markt vorhanden.

      Quellcode

      1. var unitsUse = 10000;
      2. var balance = Convert.ToDecimal("290.0595");
      3. var marginRate = Convert.ToDecimal("0.02");
      4. var unitsAvailable = Math.Floor(balance / marginRate);
      5. var marginUsed = unitsUse * marginRate;


      bei 10000 Units - Markt EUR_USD:
      Units Available: 14,502
      1 PIP: 0.89 EUR
      Trade value = 10.000.00 EUR
      Margin used = 200.00 EUR

      bei 1 Units - Markt DAX:
      Units Available: 1
      1 PIP: 1.00 EUR
      Trade value = 9.714.50 EUR
      Margin used = 194.29 EUR

      ...


      Wie komme ich auf diese Werte. Erste Ansatz für EUR_USD oben.


      Danke!
    • Für alle Interessierte. Das kommt dem Ziel recht nah. Rest muss jeder selbst finden.

      Quellcode

      1. ...
      2. // calculation
      3. decimal unitsAvailable;
      4. decimal onePip;
      5. decimal tradeValue;
      6. decimal marginUsed;
      7. decimal marginAvailable;
      8. decimal convertedPrice = 0;
      9. // current price
      10. if (!isPairACurrency) // TODO: special case Gold/Silver
      11. {
      12. // convert price
      13. var currencyPairPrice = rateDict[currencyPair];
      14. if (currencyPairQuote.Equals(accountCurrency))
      15. {
      16. convertedPrice = currencyPairPrice;
      17. }
      18. else
      19. {
      20. var option1 = accountCurrency + "_" + currencyPairQuote; // quote
      21. var option2 = currencyPairQuote + "_" + accountCurrency;
      22. var converted = false;
      23. if (rateDict.ContainsKey(option1))
      24. {
      25. converted = true;
      26. convertedPrice = Math.Round(currencyPairPrice*1/rateDict[option1], 2);
      27. }
      28. if (rateDict.ContainsKey(option2))
      29. {
      30. converted = true;
      31. convertedPrice = Math.Round(currencyPairPrice*rateDict[option2], 2);
      32. }
      33. if (!converted) // fault
      34. {
      35. convertedPrice = currencyPairPrice;
      36. Console.WriteLine("fault: " + currencyPair);
      37. }
      38. }
      39. // maximum number of units
      40. var reducedPrice = Math.Round(convertedPrice*marginRate, 2);
      41. unitsAvailable = Math.Floor(balance/reducedPrice);
      42. // 1 pip
      43. onePip = unitsUse;
      44. // trade value
      45. tradeValue = unitsUse*convertedPrice;
      46. // margin used
      47. marginUsed = unitsUse*reducedPrice;
      48. // margin available
      49. marginAvailable = Math.Round(balance - marginUsed, 2);
      50. }
      51. else
      52. {
      53. // get divisor
      54. var currencyPairPrice = rateDict[currencyPair];
      55. if (currencyPairQuote.Equals(accountCurrency))
      56. {
      57. // EUR = 1
      58. convertedPrice = !accountCurrency.Equals(accountCurrencies[3]) ? currencyPairPrice : 1;
      59. }
      60. else
      61. {
      62. var option1 = accountCurrency + "_" + currencyPairBase; // base
      63. var option2 = currencyPairBase + "_" + accountCurrency;
      64. var converted = false;
      65. if (rateDict.ContainsKey(option1))
      66. {
      67. converted = true;
      68. convertedPrice = Math.Round(1 / rateDict[option1], decimalCount);
      69. }
      70. if (rateDict.ContainsKey(option2))
      71. {
      72. converted = true;
      73. convertedPrice = Math.Round(rateDict[option2], decimalCount);
      74. }
      75. if (!converted) // fault
      76. {
      77. convertedPrice = currencyPairPrice;
      78. Console.WriteLine("fault: " + currencyPair);
      79. }
      80. }
      81. // maximum number of units
      82. unitsAvailable = Math.Ceiling(Math.Floor(balance / marginRate) / convertedPrice) - 1;
      83. // 1 pip
      84. onePip = unitsUse / convertedPrice * (decimal)currInstrument.Pip;
      85. // trade value
      86. tradeValue = unitsUse * convertedPrice; // TODO: calculation correct?
      87. // margin used
      88. marginUsed = unitsUse * marginRate;
      89. // margin available
      90. marginAvailable = Math.Round(balance - marginUsed, 2);
      91. }
      92. Console.WriteLine(Environment.NewLine);
      93. Console.WriteLine("Account Currency: \t\t\t" + accountCurrency);
      94. Console.WriteLine("Currency Pair ("+ currencyPairBase + "/" + accountCurrency + "): \t" + currencyPair);
      95. Console.WriteLine("Current Price: \t\t\t\t" + convertedPrice);
      96. Console.WriteLine("Margin Ratio: \t\t\t\t" + 1/marginRate + ":1 (" + marginRate + ")");
      97. Console.WriteLine("Margin Available ("+ accountCurrency + "): \t" + balance);
      98. Console.WriteLine("Maximum Number Of Units: \t" + unitsAvailable);
      99. Console.WriteLine("1 Pip: \t\t\t\t\t\t" + onePip);
      100. Console.WriteLine("Trade Value: \t\t\t\t" + tradeValue);
      101. Console.WriteLine("Margin Used: \t\t\t\t" + marginUsed);
      102. Console.WriteLine("Margin Available: \t\t\t" + marginAvailable);
      103. Console.WriteLine(Environment.NewLine);
      Alles anzeigen