- ago
Please tell me why the USTYield indicator needs "bars"?
CODE:
public override void Initialize(BarHistory bars) {    usTYield = new USTYield(bars,YieldPeriod.OneYear); }
I'm trying to create a simple static Sharpe Ratio function for my static WL utility class, and I don't want to pass lots of stuff (like bars) into it. I'm looking for a way around this "bars" business.

Does this USTYield indicator create a new copy of itself for each bars instance or is one copy cached somehow?

Is there a simpler way to get USTYield for a Sharpe Ratio calculation?

UPDATE: Hmm. Maybe USTYield employs the bars parameter to determine the Scale of the Chart, and nothing more. I wonder where it caches its result? Certainly not in my static utility class. Maybe it's not possible to create a static utility function employing USTYield.
0
108
Solved
4 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.83% )
- ago
#1
Because fundamentally every indicator in WL8 needs either a BarHistory or a TimeSeries as the first parameter. It’s just the core design.
0
Best Answer
- ago
#2
So is
CODE:
usTYield = USTYield.Series(bars,YieldPeriod.OneYear);
going to cache a separate USTYield TimeSeries in the dataset for each individual stock? If so, how can I avoid that?

In other words, how can a single copy of the USTYield be created to be used with every stock (bars object) in the dataset?
0
Glitch8
 ( 10.83% )
- ago
#3
It’s not possible. Best not to mess with that either, because each symbol in the DataSet might have varying bar counts so it’s good that each gets its own synchronized copy.
1
- ago
#4
QUOTE:
because each symbol in the DataSet might have varying bar counts

Interesting thought.

But I figured out a tricky solution. I only want to compute the Sharpe Ratio for the final bar so I can assign it to the Transaction.Weight for the off-the-Chart trade that appears in the Quotes window. So I only need one double value stored as a field variable.
CODE:
   if (usTYieldLastBar == 0.0)       usTYieldLastBar = new USTYield(bars,YieldPeriod.OneYear)[bars.Count-1];
Yes, that means I'll be using the same USTYield value for all positions of the stock, so this will be a somewhat rough Sharpe Ratio approximation. Maybe I should use the median USTYield value over the last two years instead.
CODE:
   if (usTYieldLastBar == 0.0)       usTYieldLastBar = Median.Value(bars.Count-1,new USTYield(bars,YieldPeriod.OneYear),504);
The bad news is that my SharpeRatioLastValue() function cannot be made static. Bummer.

Thanks for the help and quick reply.
0

Reply

Bookmark

Sort