Example #1
0
void main()
{
	int CurveLength = file_length(BalanceFile)/sizeof(var);
	var *Balances = file_content(BalanceFile);

	int M = CurveLength - DrawDownDays + 1;
	int T = TradeDays - DrawDownDays + 1;
	
	if(T < 1 || M <= T) {
		printf("Not enough samples!");
		return;
	}
	
	var GMin=0, N=0;
	int i = 0;
	for(; i < M; i++)
	{
		var G = Balances[i+DrawDownDays-1] - Balances[i];
		if(G <= -DrawDown) N += 1.;
		if(G < GMin) GMin = G;
	}  

	var P;
	if(TradeDays > DrawDownDays)
		P = 1. - exp(logsum(M-N)+logsum(M-T)-logsum(M)-logsum(M-N-T));
	else
		P = N/M;

	printf("\nTest period: %i days",CurveLength);
	printf("\nWorst test drawdown: %.f",-GMin);
	printf("\nM: %i  N: %i  T: %i",M,(int)N,T);
	printf("\nCold Blood Index: %.1f%%",100*P);
}
Example #2
0
int main()
{
    int ret;

    struct mmaped_bytes file_bytes;
    ret = file_content(&file_bytes, "10.txt");
    if (ret != 0) {
        return ret;
    }

    struct malloced_bytes data_bytes;
    ret = base64_to_bytes(&data_bytes, file_bytes.data, file_bytes.size);
    if (ret != 0) {
        fini_mmaped_bytes(&file_bytes);
        return ret;
    }

    struct static_bytes key_bytes;
    str_literal(&key_bytes, "YELLOW SUBMARINE");

    uint8_t iv_bytes[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

    struct malloced_bytes decrypted_bytes;
    ret = aes_128_cbc_decrypt(&decrypted_bytes,
                              iv_bytes, 16,
                              key_bytes.data, key_bytes.size,
                              data_bytes.data, data_bytes.size);
    if (ret != 0) {
        fini_malloced_bytes(&data_bytes);
        fini_mmaped_bytes(&file_bytes);
        return ret;
    }

    uint8_t last_byte = decrypted_bytes.data[decrypted_bytes.size - 1];
    size_t size;
    if (last_byte < 16) {
        size = decrypted_bytes.size - last_byte;
    }
    else {
        size = decrypted_bytes.size;
    }

    for (size_t i = 0; i < size; ++i) {
        printf("%c", decrypted_bytes.data[i]);
    }

    fini_malloced_bytes(&decrypted_bytes);
    fini_malloced_bytes(&data_bytes);
    fini_mmaped_bytes(&file_bytes);
    return ret;
}
Example #3
0
void CookieManager::ReadPersistentCookieFile(const std::wstring& file_name,
                                             const bool include_secure_cookies,
                                             std::map<std::string, BrowserCookie>* cookies) {
  LOG(TRACE) << "Entering CookieManager::ReadPersistentCookieFile";
  HANDLE file_handle = ::CreateFile(file_name.c_str(),
                                    GENERIC_READ,
                                    FILE_SHARE_READ | FILE_SHARE_WRITE,
                                    NULL,
                                    OPEN_EXISTING,
                                    0,
                                    NULL);
  // Read the cookie file. Hopefully, we will never have a 2GB cookie file.
  DWORD file_size_high = 0;
  DWORD file_size_low = ::GetFileSize(file_handle, &file_size_high);
  std::vector<char> file_content(file_size_low + 1);
  DWORD bytes_read = 0;
  ::ReadFile(file_handle, &file_content[0], file_size_low, &bytes_read, NULL);
  ::CloseHandle(file_handle);

  // Null-terminate and convert to a string for easier manipulation.
  file_content[bytes_read - 1] = '\0';
  std::string cookie_file_contents = &file_content[0];

  // Each cookie in the file is a record structure separated by
  // a line containing a single asterisk ('*'). Split the file 
  // content on this delimiter, and parse each record.
  std::vector<std::string> persistent_cookie_strings;
  StringUtilities::Split(cookie_file_contents,
                         "\n*\n",
                         &persistent_cookie_strings);
  std::vector<std::string>::const_iterator cookie_string_iterator = persistent_cookie_strings.begin();
  for (;
       cookie_string_iterator != persistent_cookie_strings.end();
       ++cookie_string_iterator) {
    BrowserCookie persistent_cookie = 
        this->ParsePersistentCookieInfo(*cookie_string_iterator);
    if (include_secure_cookies || !persistent_cookie.is_secure()) {
      // Omit the cookie if it's 'secure' flag is set and we are *not*
      // browsing using SSL.
      cookies->insert(
          std::pair<std::string, BrowserCookie>(persistent_cookie.name(),
          persistent_cookie));
    }
  }
}
Example #4
0
std::string CookieManager::ReadCookieFile(const std::wstring& file_name) {
  LOG(TRACE) << "Entering CookieManager::ReadCookieFile";
  HANDLE file_handle = ::CreateFile(file_name.c_str(),
                                    GENERIC_READ,
                                    FILE_SHARE_READ | FILE_SHARE_WRITE,
                                    NULL,
                                    OPEN_EXISTING,
                                    0,
                                    NULL);
  // Read the cookie file. Hopefully, we will never have a 2GB cookie file.
  DWORD file_size_high = 0;
  DWORD file_size_low = ::GetFileSize(file_handle, &file_size_high);
  std::vector<char> file_content(file_size_low + 1);
  DWORD bytes_read = 0;
  ::ReadFile(file_handle, &file_content[0], file_size_low, &bytes_read, NULL);
  ::CloseHandle(file_handle);

  // Null-terminate and convert to a string for easier manipulation.
  file_content[bytes_read - 1] = '\0';
  std::string cookie_file_contents = &file_content[0];
  return cookie_file_contents;
}
Example #5
0
void main()
{
	byte *Content = file_content("Log\\TrendDaily.bin");
	if(!Content) {
		printf("\nFirst produce equity curves!");
		return;
	}
	int i,j,N = 0;
	int MaxN = 0;
	var MaxPerf = 0.0;
	
	while(N<CURVES && *Content) 
	{ 
// extract the next curve from the file
		string Name = Content;
		Content += strlen(Name)+1;
		int Size = *((int*)Content);
		int Length = Size/sizeof(var); // number of values
		Content += 4;
		var *Values = Content;
		Content += Size;

		if(!strstr(Name,SELECT)) continue;

// store the curve		
		Curve[N].Name = Name;
		Curve[N].Length = Length;
		Curve[N].Values = Values;
		var Performance = 1.0/ProfitFactor(Values,Length);
		if(MaxPerf < Performance) {
			MaxN = N;
			MaxPerf = Performance;
		}
		printf("\n%s: %.2f",Curve[N].Name,Performance);
		//_plotHistogram("Profit",Performance,BUCKET,RED);
		N++;
	}
	
	PlotScale = 10;
	PlotHeight1 = 300;
	printf("\n\nBenchmark: %s, %.2f", Curve[MaxN].Name,MaxPerf); 

#ifdef WRC
	plotBar("MaxPerf",MaxPerf/BUCKET,MaxPerf,50,BARS+LBL2,BLUE);	
	printf("\nBootstrap - please wait");
	int Worse = 0, Better = 0;
	for(i=0; i<SAMPLES; i++) {
		var MaxBootstrapPerf = 0;
		for(j=0; j<N; j++) {
			randomize(BOOTSTRAP|DETREND,Daily,Curve[j].Values,Curve[j].Length);
			var Performance = 1.0/ProfitFactor(Daily,Curve[j].Length);
			MaxBootstrapPerf = max(MaxBootstrapPerf,Performance);
		}
		printf(".");
		if(MaxPerf > MaxBootstrapPerf)
			Better++;
		else
			Worse++;
		_plotHistogram("Profit",MaxBootstrapPerf,BUCKET,RED);
		progress(100*i/SAMPLES,0);
	}
	printf("\nBenchmark beats %.0f%% of samples!",
		(var)Better*100./(Better+Worse));
#endif
}