cost源码
A. 改通达信源码成选股公式
CROSS(MA(COST(10),120),L) AND C>MA(COST(10),120);
B. 模拟退火算法解决路径优化 的源代码
我有 simulated annealing with metropolies(Monte Carlo)做的一个项目的代码,你要看看么?
void anneal(int nparam, int nstep, int nstep_per_block, double t0,
const double * param_in,
double cost_in, double * params_out, double * cost_out) {
int nblock;
int step;
int block;
int nactive;
int rank;
int n_accepted = 0;
int i, j, n;
double cost_current, cost_trial;
int * param_index;
double * param_current;
double * param_trial;
double * Q;
double * S;
double * u;
double * dp;
double * A;
FILE * fp_log_file;
char fname[FILENAME_MAX];
double temp = t0;
double tempmax = temp;
double ebar, evar, emin, eta, specific_heat;
double delta;
double chi = 0.8; // Annealing schele
double chi_s = 3.0; // Vanderbilt/Louie 'growth factor'
double rm;
double root3 = sqrt(3.0);
double p = 0.02/sqrt(3.0); //max size of annealing step
param_current = new double[nparam];
param_trial = new double[nparam];
cost_current = cost_in;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
sprintf(fname, "a_%4.4d.log", rank);
fp_log_file = fopen(fname, "a");
if (fp_log_file == (FILE *) NULL) errorMessage("fopen(log) failed\n");
// Work out the number of active parameters, and set up the
// index table of the active parameters.
// Note that the complete array of parameters (param_trial) must
// be used to evaluate the cost function.
nactive = 0;
for (n = 0; n < nparam; n++) {
param_current[n] = param_in[n];
param_trial[n] = param_in[n];
if (P.is_active[n]) nactive++;
}
param_index = new int[nactive];
i = 0;
for (n = 0; n < nparam; n++) {
if (P.is_active[n]) param_index[i++] = n;
}
// Initialise the step distribution matrix Q_ij
Q = new double[nactive*nactive];
S = new double[nactive*nactive];
u = new double[nactive];
dp = new double[nactive];
A = new double[nactive];
double * Qtmp;
Qtmp = new double[nactive*nactive];
for (i = 0; i < nactive; i++) {
for (j = 0; j < nactive; j++) {
delta = (i == j);
Q[i*nactive + j] = p*delta*param_current[param_index[j]];
}
}
// carry out annealing points
nblock = nstep/nstep_per_block;
rm = 1.0/(double) nstep_per_block;
for (block = 0; block < nblock; block++) {
// Set the schele for this block, and initialise blockwise quantities.
// We also ensure the step distribution matrix is diagonal.
temp = chi*temp;
for (i = 0; i < nactive; i++) {
A[i] = 0.0;
for (j = 0; j < nactive; j++) {
S[i*nactive + j] = 0.0;
delta = (i == j);
Q[i*nactive + j] *= delta;
}
}
ebar = 0.0;
evar = 0.0;
emin = cost_current;
for (i = 0; i < nactive; i++) {
printf("Step: %d %g\n", i, Q[i*nactive + i]);
}
for (step = 0; step < nstep_per_block; step++) {
// Set the random vector u, and compute the step size dp
for (i = 0; i < nactive; i++) {
u[i] = root3*(r_uniform()*2.0 - 1.0);
}
for (i = 0; i < nactive; i++) {
dp[i] = 0.0;
for (j = 0; j < nactive; j++) {
dp[i] += Q[i*nactive + j]*u[j];
}
}
for (i = 0; i < nactive; i++) {
n = param_index[i];
param_trial[n] = param_current[n] + dp[i];
if (param_trial[n] < P.min[n]) param_trial[n] = P.min[n];
if (param_trial[n] > P.max[n]) param_trial[n] = P.max[n];
}
// calculate new cost function score
p_model->setParameters(param_trial);
cost_trial = p_costWild->getCost();
cost_trial += p_costLHY->getCost();
cost_trial += p_costTOC1->getCost();
cost_trial += p_costAPRR->getCost();
// Metropolis
delta = cost_trial - cost_current;
if (delta < 0.0 || r_uniform() < exp(-delta/temp)) {
for (n = 0; n < nparam; n++) {
param_current[n] = param_trial[n];
}
cost_current = cost_trial;
++n_accepted;
}
// 'Energy' statistics
ebar += cost_current;
evar += cost_current*cost_current;
if (cost_current < emin) emin = cost_current;
// Per time step log
fprintf(fp_log_file, "%6d %6d %10.4f %10.4f %10.4f %10.4f\n",
block, step, temp,
cost_current, cost_trial,
(float) n_accepted / (float) (block*nstep_per_block + step));
// Accumulate average, measured covariance
for (i = 0; i < nactive; i++) {
A[i] += param_current[param_index[i]];
for (j = 0; j < nactive; j++) {
S[i*nactive + j]
+= param_current[param_index[i]]*param_current[param_index[j]];
}
}
/* Next step*/
}
// Set the previous block average and measured covariance
for (i = 0; i < nactive; i++) {
A[i] = rm*A[i];
}
for (i = 0; i < nactive; i++) {
for (j = 0; j < nactive; j++) {
S[i*nactive + j] = rm*S[i*nactive + j] - A[i]*A[j];
if (i == j) printf("Average: %d %g %g\n", i, A[i], S[i*nactive+j]);
// Set the convarience for the next iteration s = 6 chi_s S / M
S[i*nactive + j] = 6.0*chi_s*rm*S[i*nactive + j];
}
}
// Reset the step distribution matrix for the next block
i = do_cholesky(nactive, S, Q);
j = test_cholesky(nactive, S, Q);
printf("Cholesky %d %d\n", i, j);
// Block statistics
ebar = rm*ebar;
evar = rm*evar;
specific_heat = (evar - ebar*ebar) / temp*temp;
eta = (ebar - emin)/ebar;
fprintf(fp_log_file, "%d %d %f %f %f %f %f %f\n",
block, nstep_per_block, temp, ebar, evar, emin,
specific_heat, eta);
/* Next block */
}
*cost_out = cost_current;
for (n = 0; n < nparam; n++) {
params_out[n] = param_current[n];
}
fclose(fp_log_file);
delete param_index;
delete param_current;
delete param_trial;
delete Q;
delete u;
delete dp;
delete S;
delete A;
return;
}
C. 一飞冲天公式改成选股公式。
一飞冲天公式改成选股公式,编写如下:
成本0:=COST(0.5);
成本底:=MA(成本0,3),COLORGREEN,LINETHICK2;
成本50:=COST(50 );
平均成本:=MA(成本50,3),COLORWHITE,LINETHICK2;
成本80:=COST(80);
一飞冲天:=MA(成本80,3),COLORRED,LINETHICK2;
成本支撑:=(成本底+平均成本)/2,COLOR000066,LINETHICK2;
MA3:=EMA(EMA(C,3)-MA(成本0,250)/250,3),COLORYELLOW;
条件:CROSS(MA3,一飞冲天);
一飞冲天(通达信指标)公式源码:
1.选股条件伏数源码:
起爆点:=(DCLOSE-REF(CLOSE,1))/REF(CLOSE,1)*100;
XG:CROSS(起爆点,20);
2.副图源码:
起爆点:=(DCLOSE-REF(CLOSE,1))/REF(CLOSE,1)*100;
XG:CROSS(起爆点,20);
拓展资料
三大选股公式:
一、MACD二次翻红
第一次出现红柱后,由逐渐放大到逐渐缩小,缩小到绿柱还没出现时,红柱又开始出现并且逐渐放大,就是MACD连续二次或二次以上出现红柱(经常出现强势股!若均线形成多头排列,成交量放大,大幅上升的概率更大,有好几位朋友都说借助MACD二次翻红捕捉到涨停板)。
二、黑马草上飞
图形特点:
1、60日价格平均线稳步上扬,呈一野缓条斜线。
2、日K线按照60日均线的斜率震荡向上,远看像一片草原。
3、经过大约半年的震荡向上后,终于向上突破原有上升通道,进入飞扬阶段。
4、成交量集中在季价托或短长结合的价托之下,在股价飞扬前后并未有明显的放量。
操作方法:
1、在价托形成后的回档介入。
2、在股价反复震荡的底部吸纳。
3、最节约时间和最大利润的办法是在股价飞扬前迅速介入。
三、出水芙蓉
出水芙蓉是非常典型的大牛股启动形态之一,无论是在长期震荡盘整低位区域还是牛颂厅模股上升途中,该形态出现意味着主力开始新一轮征程,牛股狂欢将再一次拉开序幕。形态上,个股在横盘整理或下跌过程中,某天一根长阳突破了短期均线系统,必须要有较大成交量来配合。这就是出水芙蓉的基本特征。
D. 跪求机构控盘度公式源码,不胜感激
庄家抬轿指标,通达信版本
VAR1:=EMA(EMA(CLOSE,9),9);
控盘:=(VAR1-REF(VAR1,1))/REF(VAR1,1)*1000;
STICKLINE(控盘<0,控盘,0,1,0),COLORWHITE;
A10:=CROSS(控盘,0);
无庄控盘:IF(控盘<0,控盘,0),COLORWHITE,NODRAW;
开始控盘:IF(A10,5,0),LINETHICK1,COLORYELLOW;
STICKLINE(控盘>REF(控盘,1) AND 控盘>0,控盘,0,1,0),COLORRED;
有庄控盘:IF(控盘>REF(控盘,1) AND 控盘>0,控盘,0),COLORRED,NODRAW;
VAR2:=100*WINNER(CLOSE*0.95);
STICKLINE(VAR2>50 AND COST(85)<CLOSE AND 控盘>0,控盘,0,1,0),COLORFF00FF;
高度控盘:IF(VAR2>50 AND COST(85)<CLOSE AND 控盘>0,控盘,0),COLORFF00FF,NODRAW;
STICKLINE(控盘<REF(控盘,1) AND 控盘>0,控盘,0,1,0),COLOR00FF00;
主力出货:IF(控盘<REF(控盘,1) AND 控盘>0,控盘,0),COLOR00FF00,NODRAW;