Sencer.DataFrame 1.0.5

dotnet add package Sencer.DataFrame --version 1.0.5
NuGet\Install-Package Sencer.DataFrame -Version 1.0.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sencer.DataFrame" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sencer.DataFrame --version 1.0.5
#r "nuget: Sencer.DataFrame, 1.0.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sencer.DataFrame as a Cake Addin
#addin nuget:?package=Sencer.DataFrame&version=1.0.5

// Install Sencer.DataFrame as a Cake Tool
#tool nuget:?package=Sencer.DataFrame&version=1.0.5

DataFrame

It is the implementation of Python dataframe on C#. In this project, SciSharp's pandas.net project was used. See https://github.com/SciSharp/Pandas.NET

Usage Methods

Creation

Create without parameters

DataFrame dataframe = new DataFrame();

Create by giving column name.

DataFrame dataframe = new DataFrame(new string[]{"col1","col2","col3");

Creating dataframedata array and column names as parameters. The column names parameter can be left blank. In this case, alphabetical letters are determined as the column name. Ex: "A","B","C". Naming is done according to the number of dataframedata.If column names are given, data is retrieved as many as the number of columns. Even if the number of columns is more than the number of data, as many columns as the number of data are created.

List<DataFrameData> list = new List<DataFrameData>(5);
string[] colls1 = new string[7];
string[] colls2 = new string[4];
DataFrame dataframe1 = new DataFrame(list,colls1);
DataFrame dataframe2 = new DataFrame(list,colls2);

Creating dataframe with single dataframedata.The column name parameter can be left blank. In this case, the column name is determined as the letter a

DataFrame dataframe = new DataFrame(new DataFrameData(typeof(decimal),10),"col1");

Creating Dataframe with dictinoary data type.The column names parameter can be left blank.

Dictionary<string,IConvertible[]> list = new Dictionary<string,IConvertible[]>(5);
string[] colls1 = new string[7];
string[] colls2 = new string[4];
DataFrame dataframe1 = new DataFrame(list,colls1);
DataFrame dataframe2 = new DataFrame(list,colls2);

Creating Dataframe with custom object type. Column names will be the names of the object elements.

public class CustomClass{
    public int Int1 { get; set; }
    public string String1 { get; set; }
    public decimal Decimal1 { get; set; }
    public DateTime DateTime1 { get; set; }
}
List<CustomClass> customlist = new List<CustomClass>(4);
DataFrame dataframe1 = new DataFrame(customlist);

DataFrame Items

Columns: Returns columns in dictionary format

Count: Returns the number of rows of any column. The row size of all columns must be equal.

Methods

AddRow: Adds new line. The added row must contain all columns.

IConvertible[] row = new IConvertible[] { DateTime.Now, 5, "row3", 6.0m, 5.13d };
List<IConvertible> row2 = new List<IConvertible>(){DateTime.Now, 5, "row3", 6.0m, 5.13};
dataframe.AddRow(row);
dataframe.AddRow(3,row2); // by giving line number

DeleteRow: deletes the line given the line number

dataframe.DeleteRow(1);

Clear: clears all lines

dataframe.Clear();

Rename: Replaces the column name with the new name. It must be in Dictionary<string,string> format.

dataframe.Rename(new Dictionary<string,string>(){{"col1","newcol1"},{"col2","newcoll2"}};

Short: Reorder all rows with given column name.

dataframe.Short("T",ShortSide.Desc);

Cci: cci indicator.

DataFrameData cci = dataframe.Cci(24);

HeikinAshi: Heikin Ashi ohlc dataframe.

DataFrame heikin= dataframe.HeikinAshi();

Pivots: To identify pivot levels.

Dictionary<string,IConvertible?> pivots= dataframe.Pivots(PivotType.Traditional);
Console.WriteLine(pivots["R1"].ToString());

BollBands: Bollinger bands indicator.

DataFrame bollbandas= dataframe.BollBands(26);
Console.WriteLine(bollbandas["Upper"].ToString());

Macd: macd indicator.

DataFrame macd= dataframe.Macd();
Console.WriteLine(macd["Signal"].ToString());

Atr: atr indicator.

DataFrameData atr= dataframe.Atr();
Console.WriteLine(atr.ToString());

Indexing

DataFrameData this[string collname]: Returns the column called column as Dataframedata.

var dataframe2 = dataframe1["coll1"];

DataFrameData this[string collname, int rowstart, int rowend]: Returns the column called column as Dataframedata within the specified range.

var dataframe2 = dataframe1["coll1", 1, 5];

IConvertible? this[string collname, int row]: Returns the data in the specified row and column.

var data = dataframe1["coll1", 1];

**List<IConvertible?> this[int row]: **Returns the data in the form of a list in the given row.

var datas = dataframe1[1];

DataFrame this[string[] colls]: Returns the columns given as parameters as DataFrame.

var dataframe2 = dataframe1[new string[]{"col1","col2"}];

Columns can be added later using the indexing method.The column to be added must have data. The size of the DataFrameData to be added must be the same as the DataFrame. If the DataFrame is empty, the size will be the DataFrameData size. ex:

var dataframe = new DataFrame();
dataframe["col1"]=new DataFrameData(typeof(int),10);

In this example, a new column named col1 has been added. The value of the data can be changed with the indexing method. ex:

dataframe["col1",3] = 12;

DataFrameData

This is the most comprehensive object. Mathematical operations, comparison, averaging and square root operations can be performed with DataFrameData. All data types used must be of nullable type. Example: new DataFrameData(new int?[5])

Usage Methods

Creation

Create by specifying type and size

DataFrameData dataframedata = new DataFrame(typeof(int),10);

Create with array

float[] array = new float[]{3.5, 2.75, 1.43, 14.6};
DataFrameData dataframedata = new DataFrame(array);

DataFrameData Items

Values: Array of values

Type: DataFrameData type of data of the data.

Methods

Add: Add new data

DataFrameData dataframedata = new DataFrameData(typeof(int),3);
dataframedata.Add(5);
dataframedata.Add(0,5); //Adding data with index number

Delete: Deletes the data given the index number

DataFrameData dataframedata = new DataFrameData(typeof(int),3);
dataframedata.Delete(1);

Clear: Clears all data

DataFrameData dataframedata = new DataFrameData(typeof(int),3);
dataframedata.Celar();

ToString: Converts data to string in tabular form

DataFrameData dataframedata = new DataFrameData(typeof(int),3);
Console.WriteLine(dataframedata.ToString());

ShiftLeft: Shifts the array to the left by the given number. Initial values ​​are assigned as null

DataFrameData dataframedata = new DataFrameData(typeof(int),10);
dataframedata2 = dataframedata.ShiftLeft(1);

ShiftRight: Shifts the array to the right by the given number. Initial values ​​are assigned as null

DataFrameData dataframedata = new DataFrameData(typeof(int),10);
dataframedata2 = dataframedata.ShiftRight(2);

index: Returns the index number of the given data

DataFrameData dataframedata = new DataFrameData(typeof(decimal),5);
int index = dataframedata.index(10m);

ForEach: Foreach method used in the list method

DataFrameData dataframedata = new DataFrameData(typeof(decimal),7);
dataframedata.ForEach(Console.WriteLine);

Rolling: Implementation of pandas.rolling function. For explanation: here

DataFrameData dataframedata = new DataFrameData(typeof(decimal),128);
List<DataFrameData> datalist = dataframedata.Rolling(5);

First: Returns the first data

IConvertible? data = dataframedata.First();

Last: Returns the last data

IConvertible? data = dataframedata.Last();

Count: Returns the total number of data

int size = dataframedata.Count();

Sum: Returns the total of the datas

IConvertible sum = dataframedata.Sum();

Mean: Averages the datas

IConvertible mean = dataframedata.Mean();

Min: Returns the minimum of all data

IConvertible min = dataframedata.Min();

Max: Returns the maximum of all data

IConvertible max = dataframedata.Max();

Abs: Returns the absolute value of a number

DataFrameData abs = dataframedata.Abs();

Diff: Find the difference between the values for each row and the values from the previous row

DataFrameData diff = dataframedata.Diff();

Clip: Used to trim values at specified input threshold. We can use this function to put a lower limit and upper limit on the values that any cell can have in the dataframe.

DataFrameData clip = dataframedata.Clip();

Std: Return sample standard deviation over requested axis.

DataFrameData std = dataframedata.Std();

Join: merge existing DataFrameData with DataFrameData given in parameter

DataFrameData joins = dataframedata.Join(dataframedata2,"both");

Ewm: ewm method used in pandas.dataframe

DataFrameData ewm = dataframedata.Ewm(21);

Sma: sma indicator

DataFrameData sma = dataframedata.Sma(50);

Ema: ema indicator

DataFrameData ema = dataframedata.Ema(17);

Wma: wma indicator

DataFrameData wma = dataframedata.Wma(18);

Hma: hma indicator

DataFrameData hma = dataframedata.Hma(18);

StockRsi: stochastic rsi indicator

(var stock, var rsi) = dataframedata.StockRsi(14,3);

Dema: dema indicator

DataFrameData dema = dataframedata.Dema(14);

BollBands: Bollinger bands indicator

(var upper, var lower) = dataframedata.BollBands(21);

Macd: macd indicator

(var longEma, var shortEma, var macd, var signal) = dataframedata.Macd();

Indexing

Returns the data given the index number

IConvertible data = dataframedata[1];

Index number returns data up to the size of the given number.

DataFrameData dataframedata2 = dataframedata[1,3]; //The size of the new DataFrameData is 3

Operators

Contain Operators

==, != , >, <, >=, ⇐, & Operators:

DataFrameData newDataFrameData = dataframedata1 == dataframedata2; //The values ​​of the new dataframedata will be of type bool
DataFrameData newDataFrameData = dataframedata1 != dataframedata2;
DataFrameData newDataFrameData = dataframedata1 > dataframedata2;
DataFrameData newDataFrameData = dataframedata1 & dataframedata2; //Do not use it with two & characters. It will be single & character
    ....

Math Operators

+, -, *, /, ++, --, % Operators:

DataFrameData newDataFrameData = dataframedata1 == dataframedata2; //The values ​​of the new dataframedata will be of type bool
DataFrameData newDataFrameData = dataframedata1 + dataframedata2;
DataFrameData newDataFrameData = dataframedata1 / dataframedata2;
DataFrameData newDataFrameData = dataframedata1 % dataframedata2;
DataFrameData newDataFrameData = dataframedata1++;
    ....

Examples

DataFrame dataframe = new DataFrame();
dataframe["T"] = new DataFrameData(new DateTime?[5]{DateTime.Parse("01.01.2024","02.01.2024","03.01.2024","04.01.2024","05.01.2024"});
dataframe["high"] = new DataFrameData(new decimal?[5]{"5.12,6.25,5.13,8.26,15});
dataframe["low"] = new DataFrameData(new decimal?[5]{"4.48,5.15,3.27,7.55,11,45});
dataframe["close"] = new DataFrameData(new decimal?[5]{"4.51,5.18,3.51,7.99,13,74});
dataframe["hl2"] = (dataframe["high"]+dataframe["low"])/2;
//Calculate 10 days sma
dataframe["sma"] = dataframe["close"].Rolling(10).Mean();
//Buy Sell indicator
dataframe["buy"] = General.Where(dataframe["close"] < dataframe["low"].ShiftLeft(),"BUY",""); //Buy if the close is less than the previous low
dataframe["sell"] = General.Where(dataframe["close"] > dataframe["high"].ShiftLeft(),"SELL",""); //Sell ​​if the close is higher than the previous high
dataframe["buysell"] = dataframe["buy"].Join(dataframe["sell"],"");  //Combine buy and sell and put them in one column

Strategy Example

public class MyStrategy : IStrategy
    {
        public override string Name => "My Strategy";
        public override string Description => "This is my strategy";
        public override string LongString => "Buy";
        public override string ShortString => "Sell";
        public MyStrategy()
        {
            Properties = new Dictionary<string, Property<Any>>() {
                {"LongDay",new Property<Any>(){Default=21,Description="Number of long days to calculate Ema",Max=200, Min=1 } },
                {"ShortDay",new Property<Any>(){Default=1,Description="Number of short days to calculate Ema" ,Max=200, Min=1 } },
                {"DeviationDay",new Property<Any>(){Default=21,Description="Ema average standard deviation number of days",Max=200, Min=1  } }
            };
        }
        public async override Task<SignalResult> Calculate()
        {
            SignalResult signal = new SignalResult();
            signal.SignalName = "Buy Sell Strategy";
            DataFrame result = new DataFrame();


            //........................

            int longDay = (int)Properties["LongDay"].Value;
            if (Candles.Count < longDay)
                return signal;

            var xEma1 = close.Ema(longDay);
            var xEma2 = xEma1.Ema(longDay);
            var XEma3 = xEma2.Ema(longDay);


            var nRes1 = xEma1 * 3 - xEma2 * 3 + XEma3;


            int shortDay = (int)Properties["ShortDay"].Value;

            var xEma21 = close.Ema(shortDay);
            var xEma22 = xEma21.Ema(shortDay);
            var XEma23 = xEma22.Ema(shortDay);

            var nRes2 = xEma21 * 3 - xEma22 * 3 + XEma23;


            var kesişim = General.Cross(nRes1, nRes2);

            var buys = nRes1 < nRes2;
            var sells = nRes2 < nRes1;

            var buy = General.Where(kesişim & buys, "Buy", "Both");
            var sell = General.Where(kesişim & sells, "Sell", "Both");


            result["T"] = Candles["T"];
            result["BuySell"] = buy.Join(sell,"Both");

            int deviationDay = (int)Properties["DeviationDay"].Value;

            var sma = close.Sma(deviationDay);
            var std = close.Std(deviationDay);
            var high = sma + std * 2;
            var low = sma - std * 2;

            var highs = General.Where(close > high, "AboveChannel", "InsideChannel");
            var lows = General.Where(close < low, "UnderChannel", "InsideChannel");


            result["Channel"] = highs.Join(lows, "InsideChannel");
            if (result.ContainsKey("BuySell") && result.ContainsKey("Channel"))
            {
                signal.Result = result;
                if (result["BuySell"].Last() == "Buy")
                    signal.Side = eSide.BUY;
                else if (result["BuySell"].Last() == "Sell")
                    signal.Side = eSide.SELL;
                else
                    signal.Side=eSide.BOTH;
                signal.ResultString = "S:" + General.convertToString(signal.Side) + "|";
                signal.ResultString += " F " + result["Channel"].Last();
            }
            return signal;
        }
    }
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 110 1/24/2024
1.0.4 76 1/19/2024
1.0.3 102 1/12/2024
1.0.2 82 1/11/2024
1.0.1 92 1/9/2024
1.0.0 71 1/8/2024

Addeds: DataFrameData.Dema indicator
DataFrameData.BollBands indicator
DataFrameData.Macd indicator
DataFrame.Cci indicator
DataFrame.HeikinAshi indicator
DataFrame.Pivots indicator
DataFrame.BollBands indicator
DataFrame.Macd indicator
DataFrame.Atr indicator