Esempio n. 1
0
void chartData(std::vector<double>& results, bool cluster, int subjectBond, DoubleMatrix data, long* maturities, int date_tolerance, int lower_date, int upper_date, int length){
	DoubleMatrix lowerBonds;
	DoubleMatrix upperBonds;
	std::vector<double>timeSeries;
	upperAndLowerBonds(cluster, subjectBond, data, maturities, date_tolerance, lower_date, upper_date, upperBonds, lowerBonds);
	flyTimeSeries(results, lowerBonds, data.at(subjectBond), upperBonds, length);
}
Esempio n. 2
0
void MatrixHeatImaging(const DoubleMatrix &m, double minimum, double maximum, QPixmap &pixmap, int width, int height)
{
    pixmap = QPixmap(QSize(width, height));
    pixmap.fill(Qt::white);
    QPainter painter(&pixmap);

    unsigned int rows = m.rows();
    unsigned int cols = m.cols();

    for (unsigned int j=0; j<rows; j++)
    {
        for (unsigned int i=0; i<cols; i++)
        {
            double u = m.at(j,i);
            double ratio = 0.0;
            if (minimum!=maximum)
                ratio = 2.0 * (u-minimum) / (maximum - minimum);
            int b = int(MAX(0, 255*(1 - ratio)));
            int r = int(MAX(0, 255*(ratio - 1)));
            int g = 255 - b - r;
            QColor c(r, g, b);
            painter.setPen(c);
            painter.drawPoint(i,height-j-1);
        }
    }
}
Esempio n. 3
0
void getFlyMetrics(double* results, bool cluster, int subjectBond, DoubleMatrix data, long* maturities, int date_tolerance, int lower_date, int upper_date, int length){
	DoubleMatrix lowerBonds;
	DoubleMatrix upperBonds;
	std::vector<double>timeSeries;
	upperAndLowerBonds(cluster, subjectBond, data, maturities, date_tolerance, lower_date, upper_date, upperBonds, lowerBonds);
	bool dataExists = flyTimeSeries(timeSeries, lowerBonds, data.at(subjectBond), upperBonds, length);
	if (dataExists){
		flyMetrics(results, timeSeries);
	}
	else{
		for (int i = 0; i < 8; i++){
			results[i] = 0;
		}
	}
}
Esempio n. 4
0
long _stdcall getChartData(int bond_id, bool cluster, double* arr, unsigned char bonds[], int numbonds, long* maturities, int microWidth, int dateTolerance, int clusterLower, int clusterUpper, int history){
	SimpleRefData bbg(1);
	DoubleMatrix yieldData;
	std::vector <std::string> bond_vec;
	for (int b = 0; b < numbonds; b++){
		std::string prefix = "/isin/";
		std::string suffix;
		suffix.clear();
		for (int j = 0; j < ISIN_LENGTH; j++){
			char a = bonds[b + j*(numbonds + 1)];
			suffix += a;
		}
		bond_vec.push_back((prefix + suffix).c_str());
	}

	double** yieldArray;
	yieldArray = new double*[numbonds+1];
	for (int i = 0; i <= numbonds; i++){
		yieldArray[i] = new double[history];
	}

	int days_data = bbg.runHistData(yieldArray, bond_vec, history);

	yieldData.resize(numbonds);
	for (int i = 0; i <= numbonds; i++){
		yieldData[i].resize(days_data);
	}
	for (int i = 0; i <= numbonds; i++){
		for (int j = 0; j < days_data; j++){
			yieldData.at(i).at(j) = yieldArray[i][j];
		}
	}
	
	std::vector<double> dataLocal;
	if (cluster){
		chartData(dataLocal, cluster, bond_id, yieldData, maturities, 0, clusterLower, clusterUpper, days_data);
	}
	else{
		chartData(dataLocal, cluster, bond_id, yieldData, maturities, dateTolerance, microWidth, microWidth, days_data);
	}
	
	for (int i = 0; i < days_data; i++){
		arr[i] = dataLocal.at(i);
	}
	return days_data;
}
/*!
 * \brief sumMatrices Sums the two matrices given as parameters in parallel.
 * Spawns threadCount threads for this operation.
 * \param A First matrix - a vector of double precision floating-point values.
 * \param B Second matrix.
 * \param threadCount Number of threads to spawn in the parallel OpenMP block.
 * \return Third matrix - the result of addition of A and B matrices.
 */
const DoubleMatrix *sumMatrices(const DoubleMatrix &A, const DoubleMatrix &B,
        unsigned int threadCount)
{
    assertSizeEqual(A, B);

    DoubleMatrix *C = new DoubleMatrix();
    fillMatrixWithZeros(*C, A.size());

    #pragma omp parallel for default(none) shared(A, B, C) num_threads(threadCount)
    for (unsigned int k = 0; k < 10000; ++k)
    {
        for (unsigned int i = 0; i < A.size(); i++)
        {

            C->at(i) = A.at(i) + B.at(i);

        }
    }
    return C;
}
/*!
 * \brief multiplyMatrices Multiplies the two matrices given as parameters in parallel.
 * Spawns threadCount threads for this operation.
 * \param A First matrix - a vector of double precision floating-point values.
 * \param B Second matrix.
 * \param threadCount Number of threads to spawn in the parallel OpenMP block.
 * \return Third matrix - the result of multiplication of A and B matrices.
 */
const DoubleMatrix *multiplyMatrices(const DoubleMatrix &A,
        const DoubleMatrix &B, unsigned int threadCount)
{
    assertSizeEqual(A, B);

    DoubleMatrix *C = new DoubleMatrix();
    fillMatrixWithZeros(*C, A.size());
    unsigned int rowSize = sqrt(A.size());

    #pragma omp parallel for default(none) shared(A, B, C) firstprivate(rowSize) num_threads(threadCount)
    for (unsigned int k = 0; k < 10000; ++k)
    {
        for (unsigned int i = 0; i < rowSize; ++i)
        {
            for (unsigned int j = 0; j < rowSize; ++j)
            {
                C->at(i * rowSize + j) = A.at(i * rowSize + j)
                        * B.at(i + j * rowSize);
            }
        }
    }

    return C;
}
Esempio n. 7
0
/*Inputs: Destinaion Excel grid, array of ISINS, number of bonds, array of maturities, date tolerance for flies,  */
long _stdcall getFlyData(double* arr, unsigned char bonds[], int numbonds, long* maturities, int microWidth, int dateTolerance, int clusterLower, int clusterUpper, int history){
	SimpleRefData bbg(1);
	DoubleMatrix yieldData;
	DoubleMatrix micro;
	DoubleMatrix cluster;
	std::vector <std::string> bond_vec;
	std::wstring stemp2 = std::to_wstring(numbonds);
	LPCWSTR sw2 = stemp2.c_str();
	OutputDebugString(L"numbonds ");

	OutputDebugString(sw2);

	for (int b = 0; b <= numbonds; b++){
		std::string prefix = "/isin/";
		std::string suffix;
		suffix.clear();
		for (int j = 0; j < ISIN_LENGTH; j++){
			char a = bonds[b + j*(numbonds + 1)];
			suffix += a;
		}
		std::wstring stemp = std::wstring(suffix.begin(), suffix.end());
		LPCWSTR sw = stemp.c_str();
		OutputDebugString(sw);
		OutputDebugString(L"\n");

		bond_vec.push_back((prefix + suffix).c_str());
	}

	double** yieldArray;
	yieldArray = new double*[numbonds+1];
	for (int i = 0; i <= numbonds; i++){
		yieldArray[i] = new double[history];
	}

	int days_data = bbg.runHistData(yieldArray, bond_vec, history);
	std::wstring stemp = std::to_wstring(days_data);
	LPCWSTR sw = stemp.c_str();
	OutputDebugString(sw);

	yieldData.resize(numbonds+1);
	for (int i = 0; i <= numbonds; i++){
		yieldData[i].resize(days_data);
	}
	for (int i = 0; i <= numbonds; i++){
		for (int j = 0; j < days_data; j++){
			yieldData.at(i).at(j) = yieldArray[i][j];
		}
	}

	DoubleMatrix microMatrix;
	DoubleMatrix clusterMatrix;
	for (int i = 0; i < numbonds; i++){
		double microLocal[8];
		double clusterLocal[8];
		getFlyMetrics(microLocal, false, i, yieldData, maturities, dateTolerance, microWidth, microWidth, days_data);
		getFlyMetrics(clusterLocal, true, i, yieldData, maturities, 0, clusterLower, clusterUpper, days_data);
		double flyLocal[16];
		for (int j = 0; j < 8; j++){
			flyLocal[j] = microLocal[j];
			flyLocal[8 + j] = clusterLocal[j];
		}

		for (int k = 0; k < 16; k++){
			arr[i + k*(numbonds + 1)] = flyLocal[k];
		}
	}
	delete[] yieldArray;
	return 0;
}