#twitter-follow { border: 0;position: fixed; top: 240px; left:0;} #live-support { border: 0;position: fixed; top: 370px; left:0;} #knowledge-base { border: 0;position: fixed; top: 170px; left:0;}

 Need assistance with C# creating an indicator 0

 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;
 Mike 2015-05-31 03:54:08   0 Further to this post... I am checking the result of the script in the screener and as a test I sent Bondsymbol which is the time series of symbol TLT. When I use the format Bondsymbol I get the correct value for the close price. When I use the format Bondsymbol[0] I get a range of values with lots of NaN results on the screener result associated with each stock. is this expected? Does anyone know what the current bar index value is that I should be using to get the correct result? Thanks, Mike
 Mike 2015-05-31 05:20:49   0 Ok so I think I've found it, 1) I think the script is calculating the entire vector for each stock and bar, so changed my max value variables to VectorD's. Then looped through all values in the array looking for the max value of each array element. I then needed to change teh way I created the cariable so it initialised to the same size as the score array I was comparing to. I did this at intialisation of variable ScoreMax = Bondsymbol-Bondsymbol; I now seem to be getting values that seem more what I would expect. Though its incredibly slow to process... for(int i=0;i< Score.Length;i++) { if( Score[i] > ScoreMax[i]) { ScoreMax[i] = Score[i]; LBBest[i] = LB; pSharesBest[i] = pShares; fBest[i] = f; } }
 QuantShare 2015-06-01 03:14:13   0 Yes, you need to use [] to get a specific value from a series/vector. In order to detect what is slowing the process, you should remove few lines of code at a time (without breaking the compilation), test then repeat. But I am guessing it is the different loops (for) that is causing this.
No more messages