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;