Example #1
0
void assembler_init(const char *in_file)
{
	char *f_buffer = f_load_file(in_file);
	if (f_buffer == NULL) {
		printf("compiler error: error on opening input file ...\n");
		exit(EXIT_FAILURE);
	}
	ASM_DESCR.MAIN_FILE = f_process_file(f_buffer);
	fmt_init();
	tokenizer_init();
	parser_init();
	icl_init();
}
Example #2
0
static int preproc_rule_preprocess(token_t *tok, token_rule_t *rule)
{
	if (tok->type == KEYWORD_INCLUDE_PREPROC) {
		int i;
		token_t *arg = tok_get_token(tok, 1);
		if (tok_strlen(arg) == 2) {
			sprintf(COMP_DESCR.err_msg, "illegal file name ...");
			return 0;
		}

		char *f_name = (char*)malloc(tok_strlen(arg) - 1);
		for (i = arg->f_char + 1; i < arg->l_char - 1; i++)
			f_name[i - arg->f_char - 1] = tok->str->ptr[i];
		f_name[i - arg->f_char - 1] = '\0';

		char *f_buffer = f_load_file(f_name);
		if (f_buffer == NULL) {
			sprintf(COMP_DESCR.err_msg, "file not found [file: %s] ...", f_name);
			return 0;
		}

		f_header_t *file = f_parse_text(f_name, f_buffer);

		token_t *f_tokens = tokenizer_run(file);
		if (f_tokens == NULL) {
			printf("preprocessor warning: file '%s' is empty\n", f_name);
			return 1;
		}

		tok_insert_tokens(arg, f_tokens);
	} else if (tok->type == KEYWORD_ENTRY_PREPROC) {
		token_t *arg = tok_get_token(tok, 1);
		if (tok_strlen(arg) >= 64) {
			sprintf(COMP_DESCR.err_msg, "entry name too long (max. 63 chars)");
			return 0;
		}
		tok_strcpy(COMP_DESCR.prg_entry, arg);
		printf("new entry: '%s'\n", COMP_DESCR.prg_entry);
	} else if (tok->type == KEYWORD_MODULE_PREPROC) {
		printf("preproc: module\n");
	}
	return 1;
}
Example #3
0
/**
 * 计算arbitrage
 * 套利模式的计算
 */
void    run_as_arbitrage()
{
	FileSet m_left,m_right;
	FILE *fh;
	char m_sFileName[1024];
	CTimeSegmentedQuote *ct,*dt;
	ST_INTCTRLBLK m_ctrl,m_ctrl2;
	char m_sExchangeID[11];
	char m_sInstrumentID[11];
	char m_sTradingDay[11];

	char m_sExchangeID2[11];
	char m_sInstrumentID2[11];
	char m_sTradingDay2[11];

	CArbitrageBaseData *arb;
	
	st_quoteitem *pi0,*pi1;
	int i0,i1;
	
	/* 判断参数是否足够 */
	if (g_var.m_iParm != 5)
	{
		WARN("quote -arb TradingDay EXCHID ALL|InsturmentID EXCHID ALL|InstrumentID","");
		return;
	}
	/* 找到左边股票集合 */
	f_load_set(g_var.m_pParm[1],g_var.m_pParm[2],g_var.m_pParm[0],&m_left,FILESET_LOAD_CORRELATION);
	f_load_set(g_var.m_pParm[3],g_var.m_pParm[4],g_var.m_pParm[0],&m_right,FILESET_LOAD_CORRELATION);
	
	f_load_file(&m_left);
	f_load_file(&m_right);
	/* 找到右边股票集合 */
	FileSet::iterator it0,it1;
	
	it0 = m_left.begin();
	while (it0 != m_left.end())
	{
		/* 左边股票的cor文件,path exchid_inst_tradingday.cor */
		it0->second->GetQuoteInfo(m_sExchangeID, m_sInstrumentID, m_sTradingDay);
		sprintf(m_sFileName,"%s%s_%s_%s.arb",it0->first.c_str(),m_sExchangeID,m_sInstrumentID,m_sTradingDay);
		EVENT("Processing %s", m_sFileName);
		printf("Processing %s\n",m_sFileName);
		
		fh = fopen(m_sFileName,"a+");
		if (fh == nullptr)
		{
			WARN("Can not open %s", m_sFileName);
			it0++;
			continue;
		}
		ct = it0->second;
		
		ct->GetSegmentInfo(&m_ctrl);
		pi0 = ct->GetQuoteItem(&i0);
		
		arb = new CArbitrageBaseData();
		arb->SetInstrument(0, m_sExchangeID, m_sInstrumentID, m_sTradingDay, &m_ctrl);
		arb->SetInstQuote(0, i0, pi0);

		it1 = m_right.begin();
		while (it1 != m_right.end())
		{
			dt = it1->second;
			dt->GetQuoteInfo(m_sExchangeID2, m_sInstrumentID2, m_sTradingDay2);
			dt->GetSegmentInfo(&m_ctrl2);
			
			pi1 = dt->GetQuoteItem(&i1);
			arb->SetInstrument(1, m_sExchangeID2, m_sInstrumentID2, m_sTradingDay2, &m_ctrl2);
			arb->SetInstQuote(1, i1, pi1);
			
			int iArbCount,i;
			double *pdArbI1BI2A;
			double *pdArbI1AI2B;
			long *plVolumeBA;
			long *plVolumeAB;

			fprintf(fh,"%s_%s_%s\n",m_sExchangeID2,m_sInstrumentID2,m_sTradingDay2);
			fprintf(fh,"Inst2 Ask - Inst1 Bid, volume, Inst2 Bid - Inst1 Ask , volume\n");
			/* 对应实际操作时:卖第一个券同时买入第二个券价差,买入第一个券卖出第二个券的价差 
			 	所以,捕捉第一个较小的数字,捕捉第二个较大的数字 才有利益 */
			arb->CalcArbitrageGaps(&iArbCount, &pdArbI1BI2A, &pdArbI1AI2B, &plVolumeBA, &plVolumeAB);
			for(i=0;i<iArbCount;i++)
			{
				fprintf(fh,"%.5f,%ld,%.5f,%ld\n",pdArbI1BI2A[i],plVolumeBA[i],pdArbI1AI2B[i],plVolumeAB[i]);
			}
			it1++;
		}
		fclose(fh);
		delete arb;
		it0 ++;
	}
	f_unload_set(&m_left);
	f_unload_set(&m_right);
}
Example #4
0
/**
 * 计算correlation
 * 有三种模式
 * 1、全部计算某一天的相关性
 * 2、计算某一天某一只股票与其他股票的相关性
 * 3、计算某一天某一只股票与某一只股票的相关性
 */
void    run_as_correlation()
{
    FileSet m_left,m_right;
    FILE *fh;
    char m_sFileName[1024];
    int iSize0,iSize1;
    CTimeSegmentedQuote *ct;
    double *dPrice0;
    double dHigh,dLow,dPre;
    ST_INTCTRLBLK m_ctrl;
    char m_sExchangeID[11];
    char m_sInstrumentID[11];
    char m_sTradingDay[11];

    /* 判断参数是否足够 */
    if (g_var.m_iParm != 5)
    {
        WARN("quote -cor TradingDay EXCHID ALL|InsturmentID EXCHID ALL|InstrumentID","");
        return;
    }
    /* 找到左边股票集合 */
    f_load_set(g_var.m_pParm[1],g_var.m_pParm[2],g_var.m_pParm[0],&m_left,FILESET_LOAD_CORRELATION);
    f_load_set(g_var.m_pParm[3],g_var.m_pParm[4],g_var.m_pParm[0],&m_right,FILESET_LOAD_CORRELATION);

    f_load_file(&m_left);
    f_load_file(&m_right);
    /* 找到右边股票集合 */
    FileSet::iterator it0,it1;

    it0 = m_left.begin();
    while (it0 != m_left.end())
    {
        /* 左边股票的cor文件,path exchid_inst_tradingday.cor */
        it0->second->GetQuoteInfo(m_sExchangeID, m_sInstrumentID, m_sTradingDay);
        sprintf(m_sFileName,"%s%s_%s_%s.cor",it0->first.c_str(),m_sExchangeID,m_sInstrumentID,m_sTradingDay);
        EVENT("Processing %s", m_sFileName);
        printf("Processing %s\n",m_sFileName);

        fh = fopen(m_sFileName,"a+");
        if (fh == nullptr)
        {
            WARN("Can not open %s", m_sFileName);
            it0++;
            continue;
        }
        ct = it0->second;

        ct->GetSegmentInfo(&m_ctrl);
        iSize0 = m_ctrl.m_dwSegmentEndTime[0] - m_ctrl.m_dwSegmentBeginTime[0] + 1;
        iSize0 = iSize0 / m_ctrl.m_wnSeconds * m_ctrl.m_wmQuotes ;
        if(iSize0<2)
            iSize0 = 2;
        iSize1 = m_ctrl.m_dwSegmentEndTime[1] - m_ctrl.m_dwSegmentBeginTime[1] + 1;
        iSize1 = iSize1 / m_ctrl.m_wnSeconds * m_ctrl.m_wmQuotes ;
        if(iSize1<2)
            iSize1 = 2;

        dPrice0 = new double[iSize0+iSize1];
        ct->GetQuoteLastPrice(0, iSize0, dPrice0, nullptr,&dHigh, &dLow, &dPre);
        ct->GetQuoteLastPrice(1, iSize1, &(dPrice0[iSize0]), nullptr,&dHigh, &dLow, &dPre);

        it1 = m_right.begin();
        while (it1 != m_right.end())
        {
            f_calc_cor(fh,dPrice0,iSize0,iSize1,it1->second,m_sInstrumentID);
            it1++;
        }
        delete [] dPrice0;
        fclose(fh);
        it0 ++;
    }
    f_unload_set(&m_left);
    f_unload_set(&m_right);
}