119 lines
5.7 KiB
C#
119 lines
5.7 KiB
C#
// TODO: Remove
|
|
//// namespace bts.SilverPine
|
|
//// using bts;
|
|
//// using BCG;
|
|
//// using MongoDB.Driver.Linq;
|
|
//// using System.ComponentModel.DataAnnotations;
|
|
//// using ZstdSharp.Unsafe;
|
|
|
|
//// [DataStreamUserRespresentation("VWAP")]
|
|
//// public class VWAPStream : ViewStream {
|
|
//// // returns the VWAP stream for each contract
|
|
//// private static ViewStream build_vwap_stream(string symbol, DateTime begin_dt, DateTime end_dt) {
|
|
//// var ohlcv_params = OHLCVStream.get_params(begin_dt, end_dt);
|
|
//// ViewStream ohlc_str = new OHLCVStream(symbol, ohlcv_params);
|
|
//// // stream is grouped per contract and then vwap is calculated per contract
|
|
//// GlobalMapStream rs = new GlobalMapStream(ohlc_str, "ts_event", "contract",
|
|
//// (rows, idx) => {
|
|
//// Log.Gen.info($"VWAPStream.GlobalMapStream delegate n_rows: {rows.Count} idx: {idx}");
|
|
//// IBlueRow ir = rows.ElementAt((int)idx);
|
|
//// var sel_rows = rows.Skip((int)idx).Where(r => r.get_datetime("ts_event") >= end_dt && r.get_datetime("ts_event") <= begin_dt);
|
|
//// var volumeprices = sel_rows.Select(r => Tuple.Create(r.get<int>("volume"), r.get<double>("close"))).ToList();
|
|
//// double vwap = IndicatorCalc.calculate_VWAP(volumeprices);
|
|
//// IBlueTableSchema schema = ir.schema.add_columns(Tuple.Create(typeof(double), "vwap"));
|
|
//// MutableBlueRow nr = new MutableBlueRow(schema, ir);
|
|
//// //vwap = -313.987;
|
|
//// nr.setValue("vwap", vwap);
|
|
//// return nr;
|
|
//// });
|
|
//// return rs;
|
|
//// }
|
|
//// // the args want dt1 > dt2, if its nto we, swap them
|
|
//// static void swap_if_necessary(ref DateTime dt1, ref DateTime dt2) {
|
|
//// if (dt1 < dt2) {
|
|
//// DateTime aux = dt1;
|
|
//// dt1 = dt2;
|
|
//// dt2 = aux;
|
|
//// }
|
|
//// }
|
|
|
|
//// // this assumes the ohlc_str has diff contracts
|
|
//// public VWAPStream(string symbol_or_contract, DateTime begin_dt, DateTime end_dt) {
|
|
//// swap_if_necessary(ref begin_dt, ref end_dt);
|
|
//// Tuple<ContractUtils.ContractCategory, string> ccat_sym_contr = ContractUtils.get_symbol_category(symbol_or_contract);
|
|
//// string symbol = String.Empty;
|
|
//// symbol = ccat_sym_contr.Item2;
|
|
//// var ohlcv_params = OHLCVStream.get_params(begin_dt, end_dt);
|
|
//// ViewStream vwap_str = build_vwap_stream(symbol, begin_dt, end_dt);
|
|
//// // vwap_str now has vwap for all contracts. if the arg was a symbol, we need to filter it for the active contract,
|
|
//// // whihc we do with FutureActivesContractStream. If the arg was a contract we'll simply filter it
|
|
//// ViewStream rs = vwap_str;
|
|
//// switch (ccat_sym_contr.Item1) {
|
|
//// case ContractUtils.ContractCategory.FutureString:
|
|
//// case ContractUtils.ContractCategory.SpreadString:
|
|
//// rs = new FilterStream(vwap_str, r => r.get<string>("contract").CompareTo(ccat_sym_contr.Item2) == 0);
|
|
//// break;
|
|
//// case ContractUtils.ContractCategory.Symbol:
|
|
//// rs = new FuturesActiveContractStream(vwap_str);
|
|
//// break;
|
|
//// }
|
|
//// rs = new FilterStream(rs, r => r.get_datetime("ts_event").CompareTo(begin_dt) == 0);
|
|
//// rs = new NewProjectStream(rs, "! vwap");
|
|
//// mySetRealSource(rs);
|
|
//// }
|
|
|
|
//// public VWAPStream(string symbol_or_contract, string begin_dt, string end_dt)
|
|
//// :
|
|
//// this(symbol_or_contract, DateTime.Parse(begin_dt), DateTime.Parse(end_dt)) { }
|
|
//// }
|
|
//// }
|
|
|
|
//using System;
|
|
|
|
//using BCG;
|
|
|
|
//using bts.api;
|
|
|
|
//namespace bts.SilverPine {
|
|
// /*
|
|
// ----------------------------------------------------------------------
|
|
// *Expression*
|
|
// ----------------------------------------------------------------------
|
|
// //nl("Find Settlement price of the SP500 future in the first week of 2023.")
|
|
|
|
// r=FutureHistoricalBars("ES", "One_Day", "1/1/2024", "2/1/2024")
|
|
// r=math(r, "vprice = volume * close")
|
|
// r=aggregate(r, "vprice:Sum, volume:Sum")
|
|
// r=math(r, "vwap = vprice_sum / volume_sum")
|
|
// r=newProject(r, "vwap !")
|
|
|
|
// ----------------------------------------------------------------------
|
|
// *Schema*
|
|
// ----------------------------------------------------------------------
|
|
// id System.Int32
|
|
// vwap System.Double
|
|
// */
|
|
|
|
// [DataStreamUserRespresentation("VWAP")]
|
|
// public class VWAPStream : ViewStream {
|
|
// public VWAPStream(string symbol_or_contract, DateTime beg_dt, DateTime end_dt)
|
|
// :
|
|
// this(symbol_or_contract, beg_dt, end_dt, ViewStreamDatabase.instance) { }
|
|
|
|
// public VWAPStream(string symbol_or_contract, DateTime beg_dt, DateTime end_dt, ViewStreamDatabase db) {
|
|
// //var fc = new ContractUtils.FutureContract(symbol_or_contract);
|
|
// ViewStream r = new FutureHistoricalBarsStream(symbol_or_contract, beg_dt.ToString(), end_dt.ToString());
|
|
// // since this is already filtered, we can groupBy iit without a groupBy column
|
|
// r = new MathStream(r,
|
|
// "vprice = volume * close");
|
|
// r = new NonIncGroupByStream(r,
|
|
// "vprice:Sum, volume:Sum");
|
|
// r = new MathStream(r,
|
|
// "vwap = vprice_sum / volume_sum");
|
|
// r = new NewProjectStream(r,
|
|
// "vwap !");
|
|
// mySetRealSource(r);
|
|
// }
|
|
// }
|
|
//}
|