public static void Echo(this IMslScript script, TableSchema schema) { long ownerId = Interpreter.Context.Scope.Stock.GetId(schema.OwnerIdColumn); Interpreter.Context.TomScripting.GetManager(schema) .Query(ownerId).Rows.Dump(); }
public static void Echo(this IMslScript script, StockCatalog catalog) { Console.WriteLine("Catalog: " + catalog.Name); foreach (var tsh in catalog.TradedStocks) { Console.WriteLine(string.Format(" Isin = {0,15}, Symbol = {1,15}, WPKN = {2,15}", tsh.Stock.Isin, tsh.Symbol, tsh.Wpkn)); } }
public static void RunReport(this IMslScript script, object args) { script.RunReport( GetArg <string>(args, "Template"), GetArg <string>(args, "Output"), GetArg <Layout>(args, "Layout"), GetArg <bool>(args, "LoopCatalog") ); }
public static void Import(this IMslScript script, StockHandle stock, string datum, bool force) { using (var trans = new ObjectTransaction()) { trans.Override(() => Interpreter.Context.Scope.TryStock, stock); Import(script, datum, force); } }
public static TableSchema Avg(this IMslScript script, DataColumn from, DataColumn into) { if (into == null) { TempTable.RewriteOwnerId(from).Create(); into = TempTable["value"]; } return(script.Aggregate(from, into, values => values.Average())); }
public static TableSchema Percentage(this IMslScript script, DataColumn dividend, DataColumn divisor, DataColumn into) { if (into == null) { TempTable.Create(); into = TempTable["value"]; } return(script.CrossSeries(dividend, divisor, into, (_dividend, _divisor) => _dividend / _divisor * 100)); }
public static TableSchema PriceEarningRatio(this IMslScript script, DataColumn price, DataColumn eps, DataColumn into) { if (into == null) { TempTable.Create(); into = TempTable["value"]; } return(script.CrossSeries(price, eps, into, (_price, _eps) => _price / _eps)); }
public static TableSchema Growth(this IMslScript script, DataColumn fromCol, DataColumn into) { if (into == null) { TempTable.RewriteOwnerId(fromCol).Create(); into = TempTable["value"]; } var inputTable = Interpreter.Context.TomScripting.GetManager(fromCol.Table.TableName); var outTable = Interpreter.Context.TomScripting.GetManager(into.Table.TableName); var stock = Interpreter.Context.Scope.Stock; var from = Interpreter.Context.Scope.From; var to = Interpreter.Context.Scope.To; long ownerId = stock.GetId(inputTable.Schema.OwnerIdColumn); using (TransactionScope trans = new TransactionScope()) { ScopedTable inputData = inputTable.Query(ownerId, new DateClause(from, to), OriginClause.Default); var q = from row in inputData.Rows orderby row.GetDateString(inputData.Schema) ascending select new { Date = row.GetDate(inputData.Schema), Value = row.Field <double>(fromCol.ColumnName), }; var result = outTable.Query(ownerId); double prev = double.MaxValue; foreach (var row in q) { if (prev == double.MaxValue) { prev = row.Value; } double growth = row.Value - prev; prev = row.Value; DataRow outRow = result.NewRow(); outRow[result.Schema.OwnerIdColumn] = ownerId; outRow.SetDate(result.Schema, row.Date); outRow[into.ColumnName] = growth; result.AddOrUpdate(outRow, into.ColumnName); } trans.Complete(); } return(Interpreter.Context.TomScripting.GetManager(into.Table.TableName).Schema); }
public static void RunBacktest(this IMslScript script, AbstractSystem systemName) { var settings = new BackTestSettings(); settings.System = systemName; Interpreter.Context.Scope.Catalog.ForEach(() => { settings.TradedStock = Interpreter.Context.Scope.Stock.TradedStock; Interpreter.Context.ServiceProvider.TradingSC().DoBackTest(settings); }); }
public static TableSchema CrossSeries(this IMslScript script, DataColumn leftCol, DataColumn rightCol, DataColumn toCol, Func <double, double, double> Calculator) { if (toCol == null) { TempTable.Create(); toCol = TempTable["value"]; } var leftTable = Interpreter.Context.TomScripting.GetManager(leftCol.Table.TableName); var rightTable = Interpreter.Context.TomScripting.GetManager(rightCol.Table.TableName); var outTable = Interpreter.Context.TomScripting.GetManager(toCol.Table.TableName); var stock = Interpreter.Context.Scope.Stock; var from = Interpreter.Context.Scope.From; var to = Interpreter.Context.Scope.To; using (TransactionScope trans = new TransactionScope()) { var leftData = leftTable.Query(stock.GetId(leftTable.Schema.OwnerIdColumn), new DateClause(from, to), OriginClause.Default); var rightData = rightTable.Query(stock.GetId(rightTable.Schema.OwnerIdColumn), new DateClause(from, to), OriginClause.Default); // for easy processing lets join the left and right for ids and date // TODO: we should optimize this for the case that left and right // are in the same table var q = from left in leftData.Rows from right in rightData.Rows where left.GetDate(leftTable.Schema) == right.GetDate(rightTable.Schema) select new { Date = left.GetDate(leftTable.Schema), Left = left.Field <double>(leftCol.ColumnName), Right = right.Field <double>(rightCol.ColumnName) }; var ownerId = stock.GetId(outTable.Schema.OwnerIdColumn); var result = outTable.Query(ownerId); foreach (var row in q) { double r = Calculator(row.Left, row.Right); DataRow outRow = result.NewRow(); outRow[result.Schema.OwnerIdColumn] = ownerId; outRow.SetDate(result.Schema, row.Date); outRow[toCol.ColumnName] = r; result.AddOrUpdate(outRow, toCol.ColumnName); } trans.Complete(); } return(Interpreter.Context.TomScripting.GetManager(toCol.Table.TableName).Schema); }
public static ScopedTable Select(this IMslScript script, DataColumn valueColumn) { var mgr = Interpreter.Context.TomScripting.GetManager(valueColumn.Table.TableName); var stock = Interpreter.Context.Scope.Stock; var from = Interpreter.Context.Scope.From; var to = Interpreter.Context.Scope.To; long ownerId = stock.GetId(mgr.Schema.OwnerIdColumn); return(mgr.Query(ownerId, new DateClause(from, to), OriginClause.Default)); }
public static IEnumerable <double> ToSet(this IMslScript script, DataColumn fromCol) { var inputTable = Interpreter.Context.TomScripting.GetManager(fromCol.Table.TableName); var stock = Interpreter.Context.Scope.Stock; var from = Interpreter.Context.Scope.From; var to = Interpreter.Context.Scope.To; long ownerId = stock.GetId(inputTable.Schema.OwnerIdColumn); ScopedTable inputData = inputTable.Query(ownerId, new DateClause(from, to), OriginClause.Default); return(inputData.Rows.Select(row => row.Field <double>(fromCol.ColumnName))); }
public static DataTable Fetch(this IMslScript script, StockHandle stock, string datum) { var provider = Interpreter.Context.DatumProviderFactory.Create(datum); if (provider == null) { throw new Exception("No data provider found for datum '" + datum + "'"); } using (var guard = new NestedScopeGuard()) { guard.Scope.Stock = stock; return(provider.Fetch().ResultTable); } }
public static void RunReport(this IMslScript script, string embeddedTemplate, string output, Layout layout, bool loopCatalog) { var assembly = script != null?script.GetType().Assembly : null; Action Runner = () => RunReport(embeddedTemplate, assembly, output, layout, loopCatalog); if (loopCatalog) { // so the report has to be executed for each catalog Interpreter.Context.Scope.Catalog.ForEach(Runner); } else { Runner(); } }
public static void Import(this IMslScript script, string datum, bool force) { var provider = Interpreter.Context.DatumProviderFactory.Create(datum); if (provider == null) { throw new Exception("No data provider found for datum '" + datum + "'"); } if (Interpreter.Context.Scope.TryStock != null) { // so this is called from within a model // e.g. a calc task or a function Fetch(provider, force); } else { Interpreter.Context.Scope.Catalog.ForEach(() => Fetch(provider, force)); } }
public static SingleResultValue <T> FetchSingle <T>(this IMslScript script, string isin, string datum) { var provider = Interpreter.Context.DatumProviderFactory.Create(datum); if (provider == null) { throw new Exception("No data provider found for datum '" + datum + "'"); } // as we have no real stock yet (we might in process of fetching standing data // to get such stock) so we have to overwrite default lookup behaviour using (var trans = new ObjectTransaction()) { trans.Register(new ScopeTransactionAdapter(Interpreter.Context.Scope)); Interpreter.Context.Scope["stock.isin"] = isin; return(provider.FetchSingle <T>()); } }
public static TableSchema CopySeries(this IMslScript script, DataColumn fromCol, DataColumn toCol) { if (toCol == null) { TempTable.Create(); toCol = TempTable["value"]; } var inputTable = Interpreter.Context.TomScripting.GetManager(fromCol.Table.TableName); var outTable = Interpreter.Context.TomScripting.GetManager(toCol.Table.TableName); var stock = Interpreter.Context.Scope.Stock; var from = Interpreter.Context.Scope.From; var to = Interpreter.Context.Scope.To; long ownerId = stock.GetId(inputTable.Schema.OwnerIdColumn); using (TransactionScope trans = new TransactionScope()) { ScopedTable fromData = inputTable.Query(ownerId, new DateClause(from, to), OriginClause.Default); var result = outTable.Query(ownerId); foreach (DataRow row in fromData.Rows) { DataRow outRow = result.NewRow(); outRow[result.Schema.OwnerIdColumn] = ownerId; outRow.SetDate(outTable.Schema, row.GetDate(fromData.Schema)); outRow[toCol.ColumnName] = row[fromCol.ColumnName]; result.AddOrUpdate(outRow, toCol.ColumnName); } trans.Complete(); } return(Interpreter.Context.TomScripting.GetManager(toCol.Table.TableName).Schema); }
public static TableSchema Aggregate(this IMslScript script, DataColumn fromCol, DataColumn toCol, Func <IEnumerable <double>, double> Calculator) { if (toCol == null) { TempTable.RewriteOwnerId(fromCol).Create(); toCol = TempTable["value"]; } var inputTable = Interpreter.Context.TomScripting.GetManager(fromCol.Table.TableName); var outTable = Interpreter.Context.TomScripting.GetManager(toCol.Table.TableName); var stock = Interpreter.Context.Scope.Stock; var from = Interpreter.Context.Scope.From; var to = Interpreter.Context.Scope.To; long ownerId = stock.GetId(inputTable.Schema.OwnerIdColumn); using (TransactionScope trans = new TransactionScope()) { ScopedTable inputData = inputTable.Query(ownerId, new DateClause(from, to), OriginClause.Default); // calculate var aggr = Calculator(inputData.Rows.Select(row => row.Field <double>(fromCol.ColumnName))); var outData = outTable.Query(ownerId); DataRow outRow = outData.NewRow(); outRow[outData.Schema.OwnerIdColumn] = ownerId; outRow[toCol.ColumnName] = aggr; outData.AddOrUpdate(outRow, toCol.ColumnName); trans.Complete(); } return(Interpreter.Context.TomScripting.GetManager(toCol.Table.TableName).Schema); }
public static IEnumerable <double> ToSet(this IMslScript script, TableSchema from) { return(ToSet(script, from["value"])); }
public static TableSchema Growth(this IMslScript script, TableSchema from, DataColumn into) { return(Growth(script, from["value"], into)); }
public static TableSchema Percentage(this IMslScript script, TableSchema dividend, TableSchema divisor) { return(script.Percentage(dividend["value"], divisor["value"])); }
public static TableSchema CrossSeries(this IMslScript script, TableSchema left, TableSchema right, DataColumn to, Func <double, double, double> Calculator) { return(CrossSeries(script, left["value"], right["value"], to, Calculator)); }
public static DataTable Fetch(this IMslScript script, StockHandle stock, Datum datum) { return(Fetch(script, stock, datum.Name)); }
public static TableSchema Percentage(this IMslScript script, TableSchema dividend, TableSchema divisor, DataColumn into) { return(script.Percentage(dividend["value"], divisor["value"], into)); }
public static TableSchema Percentage(this IMslScript script, DataColumn dividend, DataColumn divisor) { return(script.Percentage(dividend, divisor, null)); }
public static TimeSeries CreateSeries(this IMslScript script, DataColumn valueColumn) { var table = Select(null, valueColumn); return(SeriesFactory.Create(table.Schema, table.Rows, valueColumn.ColumnName)); }
public static TableSchema CrossSeries(this IMslScript script, DataColumn left, DataColumn right, Func <double, double, double> Calculator) { return(CrossSeries(script, left, right, null, Calculator)); }
public static TableSchema Growth(this IMslScript script, TableSchema from) { return(Growth(script, from["value"])); }
public static SingleResultValue <T> FetchSingle <T>(this IMslScript script, string isin, Datum datum) { return(FetchSingle <T>(script, isin, datum.Name)); }
public static TableSchema Growth(this IMslScript script, DataColumn from) { return(Growth(script, from, null)); }