fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. double capital, takeProfitPrice, percentPerTrade, maxLossPercent, entryPrice;
  7.  
  8. cout << "請輸入總本金:";
  9. cin >> capital;
  10.  
  11. cout << "請輸入止盈價格:";
  12. cin >> takeProfitPrice;
  13.  
  14. cout << "請輸入每筆交易使用本金的百分比(例如 5 表示 5%):";
  15. cin >> percentPerTrade;
  16.  
  17. cout << "請輸入最大可接受的總虧損百分比(例如 20 表示 20%):";
  18. cin >> maxLossPercent;
  19.  
  20. cout << "請輸入當前市價(開倉價格):";
  21. cin >> entryPrice;
  22.  
  23. double positionSize = capital * (percentPerTrade / 100.0);
  24. double maxLossAmount = capital * (maxLossPercent / 100.0);
  25.  
  26. double distance = abs(takeProfitPrice - entryPrice);
  27. double stopLossPrice;
  28.  
  29. if (takeProfitPrice > entryPrice) {
  30. stopLossPrice = entryPrice - distance;
  31. } else {
  32. stopLossPrice = entryPrice + distance;
  33. }
  34.  
  35. double priceMove = abs(entryPrice - stopLossPrice);
  36. double lossPerUnit = priceMove;
  37.  
  38. double maxAllowedLossPerTrade = min(maxLossAmount, positionSize);
  39. double maxLeverage = maxAllowedLossPerTrade / (lossPerUnit);
  40. double leverageRatio = maxLeverage / positionSize;
  41.  
  42. cout << "\n========== 槓桿建議結果 ==========" << endl;
  43. cout << "止損價格預估為:" << stopLossPrice << endl;
  44. cout << "最大可用槓桿倍數為:約 " << leverageRatio << " 倍" << endl;
  45. cout << "(保證在價格跌至止損價時,總虧損不超過最大可接受損失)" << endl;
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0.01s 5324KB
stdin
/*  Berechnung des Hamming-Abstandes zwischen zwei 128-Bit Werten in 	*/
/*	einer Textdatei. 													*/
/*  Die Werte müssen auf einer separaten Zeile gespeichert sein			*/
/* 																		*/
/*	Erstellt: 17.5.2010													*/
/*  Autor: Thomas Scheffler												*/

#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE 32

unsigned Hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}



int main (void)
{
	char hex;
	int i;
	int a[ARRAY_SIZE];
	int b[ARRAY_SIZE];
	int hamDist = 0;
	FILE* fp;
	
	//Arrays mit 0 initialisieren
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
  		a[i] = 0;
  		b[i] = 0;
	}

	
	fp = fopen("hex.txt","r");
	if (fp == NULL) 
	{
		printf("Die Datei hex.txt wurde nicht gefunden!");
		exit(EXIT_FAILURE);
	}

	i=0;
	printf("1.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
        a[i]=strtol(&hex,0,16);
		i++;
    }
	i=0;
	printf("2.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
    	b[i]=strtol(&hex,0,16);
        i++;
    }
	fclose(fp);

	printf("Hamming-Abweichung pro Nibble:\n");
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
		printf ("%i\t%i\t%i\n",a[i],b[i],Hamdist(a[i],b[i]));
		hamDist += Hamdist(a[i],b[i]);
	}
	printf ("\nHamming-Abweichung der Hash-Werte:%d\n",hamDist);
}

stdout
請輸入總本金:請輸入止盈價格:請輸入每筆交易使用本金的百分比(例如 5 表示 5%):請輸入最大可接受的總虧損百分比(例如 20 表示 20%):請輸入當前市價(開倉價格):
========== 槓桿建議結果 ==========
止損價格預估為:1.39051e-309
最大可用槓桿倍數為:約 -nan 倍
(保證在價格跌至止損價時,總虧損不超過最大可接受損失)