31 lines
1.3 KiB
C#
31 lines
1.3 KiB
C#
namespace bts.SilverPine {
|
|
using BCG;
|
|
|
|
using bts;
|
|
|
|
[DataStreamUserRespresentation("DailyChange")]
|
|
// takes in the ohlcv stream and computes the closing vs closing difference
|
|
public class DailyChange : ViewStream {
|
|
public DailyChange(ViewStream ohlc_str) {
|
|
GlobalMapStream rs = new GlobalMapStream(ohlc_str, "ts_event", "contract",
|
|
(rows, idx) => {
|
|
double daily_change = Double.NaN;
|
|
double daily_change_perc = Double.NaN;
|
|
IBlueRow ir = rows.ElementAt((int)idx);
|
|
if (idx < rows.Count - 1) {
|
|
IBlueRow pr = rows.ElementAt((int)idx + 1);
|
|
double close = ir.get<double>("close"), prev_close = pr.get<double>("close");
|
|
daily_change = close - prev_close;
|
|
daily_change_perc = 100.0 * daily_change / prev_close;
|
|
}
|
|
IBlueTableSchema schema = ir.schema.add_columns(Tuple.Create(typeof(double), "daily_change"));
|
|
schema = schema.add_columns(Tuple.Create(typeof(double), "daily_change_perc"));
|
|
MutableBlueRow nr = new MutableBlueRow(schema, ir);
|
|
nr.setValue("daily_change", daily_change);
|
|
nr.setValue("daily_change_perc", daily_change_perc);
|
|
return nr;
|
|
});
|
|
mySetRealSource(rs);
|
|
}
|
|
}
|
|
} |