Node org.unizone.source.Volatility

org.unizone.0.8554
Instance of TypeScriptInfo

Node dataValue
org.edgescript.TypeScriptInfo.prerequisiteParcelsList{}
org.edgescript.TypeScriptInfo.prerequisiteMethodsList{}
org.edgescript.TypeScriptInfo.script/* instance Value[Int] days; constructor() { TimeSeries:(); instance days = new Value(Int, 30); } constructor(Source src, Int days) { TimeSeries:(); setNextSource(src); instance days = new Value(Int, days); } Void setDays(Int days) { instance days = new Value(Int, days); changedHistory(); } class Boolean isResourceOf(Listable node, Symbol aspect) { if (aspect == #adaptors) return true; false; } class String resourceLabel() "Name of resource" { "volatility"; } String resourceString() "Description of resource" { instance days.value.toString + " days volatility of " + nextSource().toString(); } Mixable mixWith(Mixable item) { if (item.class.subclassOf(Source)) { setNextSource(Source{item}); return this; } return TimeSeries:mixWith(item); } Symbol valueType() { nextSource().valueType() } Void designEditor(WidgetWorkspace ws) { ws.addLabel(new Place(0, 0).setPadding(5, 5), "Days"); ws.addField(new Place(1, 0).setPadding(20, 5), instance days, null); } trace Void prepareData(Time from, Time to, Symbol resolution) { Source src = nextSource(); Producer.report("Preparing " + toString()); external cond_history_from = from.addDays(1-instance days.value); external cond_history_to = to; Set[Time] dates = new Set(Time); src.collectSteps(#cond_history, dates); if (dates.size < 2) return; Array[Real] values = new Array(Real, dates.size); 0 .to(values.size - 1, trace Void(Int i) { external cond_history = dates.at(i); values.set(i, src.aspectReal(#value)); }); Array[Real] diffs = new Array(Real, dates.size); Real value = values.at(0); Time time = dates.at(0); Real trailValue; Time trailTime; 1 .to(diffs.size - 1, trace Void(Int i) { trailValue = value; trailTime = time; value = values.at(i); time = dates.at(i); if (value != null && trailValue != null) diffs.set(i, (value.ln - trailValue.ln) / (time.subtractTime(trailTime)/365).sqrt); }); Real sx = 0.0; Real sx2 = 0.0; Int count = 0; Int index = 1; Int fromIndex = 0; Int toIndex = -1; Real s2; while (index < dates.size - 1 && dates.at(index) < from) index = index + 1; while (index < diffs.size) { while (toIndex < index) { toIndex = toIndex + 1; value = diffs.at(toIndex); if (value != null) { sx = sx + value; sx2 = sx2 + value * value; count = count + 1; } } Time fromTime = dates.at(toIndex).addDays(-instance days.value); while (dates.at(fromIndex) < fromTime) { value = diffs.at(fromIndex); if (value != null) { sx = sx - value; sx2 = sx2 - value * value; count = count - 1; } fromIndex = fromIndex + 1; } if (count > 1) s2 = (sx2 - sx * sx / count) / (count - 1); else s2 = 0.0; TimeData data = new TimeData(this, dates.at(index)); if (s2 > 0.0) data.setAspect(#value, s2.sqrt * 100); else data.setAspect(#value, null); addData(data); index = index + 1; } Producer.report(""); } String instanceScript(InstanceScriptInfo info) { nextSource().instanceScript(info); // create variables info.objectId(this, AdaptorVolatility, "vlt"); } String initScript(InstanceScriptInfo info) { String prefix = info.methodPrefix(this); " " + prefix + "setNextSource(" + nextSource().instanceScript(info) + "); " + prefix + "setDays(" + instance days.value.toString + "); "; } */
org.edgescript.TypeScriptInfo.defineTypeorg.unizone.source.Volatility
org.edgescript.TypeScriptInfo.prerequisiteScriptsList{}