|
Mike
2015-05-31 01:34:06
|
|
Guys,
I need some assistance understanding how to reference the data of the present bar value of a VectorD. I want to test if the current bar value is the highest in the last lookback period by doing a comparison with my current highest value (algoithm loops to optimize variables).
I am new to C# so there is likely a simple gap in my understanding of how this should work.
The indicator I'm trying to build will find the highest sharpe value for combinations of the current stock and a specified bond. Lookback, % allocation and f factor are being optimised. this is based on Frank Grossmans articles
All advice appreciated! Thanks,
Mike
//////////extracted from full listing below
total = Nshares*close + Nbonds*Bondsymbol;
perf = TA.PerfD(total,LB);
sd = TA.Pow(TA.Stddev(total,LB),f);
Score = perf / sd;
if( Score < ScoreMax) <- This line fails I want to capture the highest Sharpe values generated by the optimised variables
//////////////Full listing
VectorD Bondsymbol = (VectorD)BondSymbol1;
VectorD close = cFunctions.Close;
VectorD total = 0; // stores the composite NoBonds*BondClosePrice + Noshares*ShareClosePrice close price
VectorD Score = 0;
double ScoreMax = 0;
int LBBest = 0;
double pSharesBest = 0;
double fBest = 0;
double pShares =100;
VectorD Nshares =0;
VectorD Nbonds =0;
VectorD perf =0;
VectorD sd=0;
int LB=0;
double f =0;
double scoretest =0;
cFunctions.SetForwardAndBackwardBars(81,0);
//VectorD bond = cFunctions.CompileFormula("bonda = getseries(" + BondSymbol + ",close);").GetVectorDouble("bonda");
for( LB =80;LB <81;LB++)
{
for(f=2.9;f<3;f=f+0.2)
{
for(pShares =100 ;pShares<101;pShares = pShares+10)
{
Nshares = (pShares/100) / TA.Ref(close,LB);
Nbonds = ((100 - pShares) / 100) / TA.Ref(Bondsymbol,LB);
total = Nshares*close + Nbonds*Bondsymbol;
perf = TA.PerfD(total,LB);
sd = TA.Pow(TA.Stddev(total,LB),f);
Score = perf / sd;
if( Score < ScoreMax) <- This line fails I want to capture the highest Sharpe values generated by the optimised variables
{
ScoreMax = Score.GetValue(0);
LBBest = LB;
pSharesBest = pShares;
fBest = f;
}
}
}
}
result = ScoreMax;
|
|