예제 #1
0
파일: Echo.cs 프로젝트: riyanhax/Maui
        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();
        }
예제 #2
0
파일: Echo.cs 프로젝트: riyanhax/Maui
 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));
     }
 }
예제 #3
0
 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")
         );
 }
예제 #4
0
파일: Import.cs 프로젝트: riyanhax/Maui
        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);
            }
        }
예제 #5
0
파일: Avg.cs 프로젝트: riyanhax/Maui
        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()));
        }
예제 #6
0
파일: Percentage.cs 프로젝트: riyanhax/Maui
        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));
        }
예제 #7
0
        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));
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
            });
        }
예제 #10
0
        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);
        }
예제 #11
0
        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));
        }
예제 #12
0
        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)));
        }
예제 #13
0
파일: Fetch.cs 프로젝트: riyanhax/Maui
        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);
            }
        }
예제 #14
0
        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();
            }
        }
예제 #15
0
파일: Import.cs 프로젝트: riyanhax/Maui
        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));
            }
        }
예제 #16
0
파일: Fetch.cs 프로젝트: riyanhax/Maui
        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>());
            }
        }
예제 #17
0
        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);
        }
예제 #18
0
파일: Aggregate.cs 프로젝트: riyanhax/Maui
        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);
        }
예제 #19
0
 public static IEnumerable <double> ToSet(this IMslScript script, TableSchema from)
 {
     return(ToSet(script, from["value"]));
 }
예제 #20
0
 public static TableSchema Growth(this IMslScript script, TableSchema from, DataColumn into)
 {
     return(Growth(script, from["value"], into));
 }
예제 #21
0
파일: Percentage.cs 프로젝트: riyanhax/Maui
 public static TableSchema Percentage(this IMslScript script, TableSchema dividend, TableSchema divisor)
 {
     return(script.Percentage(dividend["value"], divisor["value"]));
 }
예제 #22
0
 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));
 }
예제 #23
0
파일: Fetch.cs 프로젝트: riyanhax/Maui
 public static DataTable Fetch(this IMslScript script, StockHandle stock, Datum datum)
 {
     return(Fetch(script, stock, datum.Name));
 }
예제 #24
0
파일: Percentage.cs 프로젝트: riyanhax/Maui
 public static TableSchema Percentage(this IMslScript script, TableSchema dividend, TableSchema divisor, DataColumn into)
 {
     return(script.Percentage(dividend["value"], divisor["value"], into));
 }
예제 #25
0
파일: Percentage.cs 프로젝트: riyanhax/Maui
 public static TableSchema Percentage(this IMslScript script, DataColumn dividend, DataColumn divisor)
 {
     return(script.Percentage(dividend, divisor, null));
 }
예제 #26
0
        public static TimeSeries CreateSeries(this IMslScript script, DataColumn valueColumn)
        {
            var table = Select(null, valueColumn);

            return(SeriesFactory.Create(table.Schema, table.Rows, valueColumn.ColumnName));
        }
예제 #27
0
 public static TableSchema CrossSeries(this IMslScript script, DataColumn left, DataColumn right, Func <double, double, double> Calculator)
 {
     return(CrossSeries(script, left, right, null, Calculator));
 }
예제 #28
0
 public static TableSchema Growth(this IMslScript script, TableSchema from)
 {
     return(Growth(script, from["value"]));
 }
예제 #29
0
파일: Fetch.cs 프로젝트: riyanhax/Maui
 public static SingleResultValue <T> FetchSingle <T>(this IMslScript script, string isin, Datum datum)
 {
     return(FetchSingle <T>(script, isin, datum.Name));
 }
예제 #30
0
 public static TableSchema Growth(this IMslScript script, DataColumn from)
 {
     return(Growth(script, from, null));
 }