How to use data-forge - 10 common examples

To help you get started, we’ve selected a few data-forge examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SockTrader / SockTrader / src / __tests__ / data / candleNormalizer.spec.ts View on Github external
function createDataFrame() {
    // @formatter:off
    return new DataFrame([
        {high: 5663.99, low: 5639.25, open: 5658.11, close: 5647.88, volume: 0.67, timestamp: moment("2019-05-06T10:00:00.000Z")},
        {high: 5660, low: 5608.04, open: 5627.37, close: 5658.11, volume: 10.623, timestamp: moment("2019-05-06T02:00:00.000Z")},
        {high: 5638, low: 5613.12, open: 5621.01, close: 5627.3766, volume: 20, timestamp: moment("2019-05-06T01:00:00.000Z")},
    ]);
    // @formatter:on
}
github data-forge / data-forge-plot / src / index.ts View on Github external
}

const seriesPlotDefaults: IPlotConfig = {
    legend: {
        show: false,
    },
};

function plotSeries(this: ISeries, plotConfig?: IPlotConfig, axisMap?: IAxisMap): IPlotAPI {
    const serializedData = this
        .inflate((value: any) => ({ __value__: value }))
        .serialize();
    return new PlotAPI(serializedData, plotConfig || {}, axisMap || {}, seriesPlotDefaults);
}

Series.prototype.startPlot = startPlot;
Series.prototype.endPlot = endPlot;
Series.prototype.plot = plotSeries;

//
// Augment IDataFrame and DataFrame with plot function.
//
declare module "data-forge/build/lib/dataframe" {
    interface IDataFrame {
        startPlot(): void;
        endPlot(): void;

        plot(plotDef?: IPlotConfig, axisMap?: IAxisMap): IPlotAPI;
    }

    interface DataFrame {
        startPlot(): void;
github data-forge / data-forge-plot / src / index.ts View on Github external
const seriesPlotDefaults: IPlotConfig = {
    legend: {
        show: false,
    },
};

function plotSeries(this: ISeries, plotConfig?: IPlotConfig, axisMap?: IAxisMap): IPlotAPI {
    const serializedData = this
        .inflate((value: any) => ({ __value__: value }))
        .serialize();
    return new PlotAPI(serializedData, plotConfig || {}, axisMap || {}, seriesPlotDefaults);
}

Series.prototype.startPlot = startPlot;
Series.prototype.endPlot = endPlot;
Series.prototype.plot = plotSeries;

//
// Augment IDataFrame and DataFrame with plot function.
//
declare module "data-forge/build/lib/dataframe" {
    interface IDataFrame {
        startPlot(): void;
        endPlot(): void;

        plot(plotDef?: IPlotConfig, axisMap?: IAxisMap): IPlotAPI;
    }

    interface DataFrame {
        startPlot(): void;
        endPlot(): void;
github data-forge / data-forge-plot / src / index.ts View on Github external
const seriesPlotDefaults: IPlotConfig = {
    legend: {
        show: false,
    },
};

function plotSeries(this: ISeries, plotConfig?: IPlotConfig, axisMap?: IAxisMap): IPlotAPI {
    const serializedData = this
        .inflate((value: any) => ({ __value__: value }))
        .serialize();
    return new PlotAPI(serializedData, plotConfig || {}, axisMap || {}, seriesPlotDefaults);
}

Series.prototype.startPlot = startPlot;
Series.prototype.endPlot = endPlot;
Series.prototype.plot = plotSeries;

//
// Augment IDataFrame and DataFrame with plot function.
//
declare module "data-forge/build/lib/dataframe" {
    interface IDataFrame {
        startPlot(): void;
        endPlot(): void;

        plot(plotDef?: IPlotConfig, axisMap?: IAxisMap): IPlotAPI;
    }

    interface DataFrame {
        startPlot(): void;
        endPlot(): void;
github Grademark / grademark / src / lib / compute-drawdown.ts View on Github external
let peakCapital = startingCapital;
    let workingDrawdown = 0;

    for (const trade of trades) {
        workingCapital *= trade.growth;
        if (workingCapital < peakCapital) {
            workingDrawdown = workingCapital - peakCapital;
        }
        else {
            peakCapital = workingCapital;
            workingDrawdown = 0; // Reset at the peak.
        }
        drawdown.push(workingDrawdown);
    }

    return new Series(drawdown);
}
github data-forge / data-forge-indicators / src / indicators / ema.ts View on Github external
function ema(this: ISeries, period: number): ISeries {

    assert.isNumber(period, "Expected 'period' parameter to 'Series.ema' to be a number that specifies the time period of the moving average.");

    // https://www.investopedia.com/ask/answers/122314/what-exponential-moving-average-ema-formula-and-how-ema-calculated.asp
    const mult = (2 / (period + 1));
    let avgValue = this.take(period).average(); //TODO: this destroy the index.
    return new Series({
            index: [ this.getIndex().skip(period-1).first() ], // TODO: The construction of this 1 elements series is quite awkward.
            values: [ avgValue ],
        }) 
        .concat(
            this.skip(period)
                .select(value => {
                    avgValue = ((value - avgValue) * mult) + avgValue;
                    return avgValue;
                })
                .bake()
        );
}
github data-forge / data-forge-plot / examples / example-10.ts View on Github external
async function main(): Promise {

    const df = new DataFrame({
            columns: {
                versicolor_x: versicolor_x,
                versicolor_y: versicolor_y,
                setosa_x: setosa_x,
                setosa_y: setosa_y,  
            },
        });
    
    //console.log(df.head(10).toString());
    
    const plot = df.plot()
        .chartType(ChartType.Scatter)
        .y()
            .addSeries("versicolor_y")
                .label("Versicolor")
                //todo: .color("blue")
github data-forge / data-forge-plot / examples / example-7.ts View on Github external
async function main(): Promise {

    const df = new DataFrame({
            columns: {
                versicolor_x: versicolor_x,
                versicolor_y: versicolor_y,
            },
        });
    
    //console.log(df.toString());
    
    const plot = df.plot({ chartType: ChartType.Scatter }, { x: "versicolor_x", y: "versicolor_y" });
    await plot.renderImage(path.join(outputPath, "image.png"), { openImage: false });
    await plot.exportWeb(path.join(outputPath, "web"), { overwrite: true, openBrowser: false });
}
github data-forge / data-forge-plot / examples / example-3.ts View on Github external
async function main(): Promise {

    const df = new DataFrame({
            columns: {
                date: x,
                data1: data1,
                data2: data2
            },
        })
        .parseDates("date", "YYYY-MM-DD");
    
    //console.log(df.toString());
    
    const plot = df.plot({}, { x: "date", y: [ "data1", "data2" ]});
    await plot.renderImage(path.join(outputPath, "image.png"), { openImage: false });
    await plot.exportWeb(path.join(outputPath, "web"), { overwrite: true, openBrowser: false });
}
github data-forge / data-forge-plot / examples / example-6.ts View on Github external
async function main(): Promise {

    const df = new DataFrame({
            columns: {
                data1: data1,
                data2: data2,
                data3: data3,
            },
        });
    
    //console.log(df.toString());
    
    const plot = df.plot()
        .chartType(ChartType.Bar);
    await plot.renderImage(path.join(outputPath, "image.png"), { openImage: false });
    await plot.exportWeb(path.join(outputPath, "web"), { overwrite: true, openBrowser: false });
}

data-forge

JavaScript data transformation and analysis toolkit inspired by Pandas and LINQ.

MIT
Latest version published 9 months ago

Package Health Score

64 / 100
Full package analysis