forked from ta4j/ta4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCashFlowToChart.java
More file actions
50 lines (41 loc) · 1.84 KB
/
Copy pathCashFlowToChart.java
File metadata and controls
50 lines (41 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* SPDX-License-Identifier: MIT
*/
package ta4jexamples.analysis;
import org.ta4j.core.BarSeries;
import org.ta4j.core.Strategy;
import org.ta4j.core.TradingRecord;
import org.ta4j.core.analysis.CashFlow;
import org.ta4j.core.backtest.BarSeriesManager;
import org.ta4j.core.indicators.helpers.ClosePriceIndicator;
import ta4jexamples.charting.workflow.ChartWorkflow;
import ta4jexamples.datasources.BitStampCsvTradesFileBarSeriesDataSource;
import ta4jexamples.strategies.MovingMomentumStrategy;
/**
* This class builds a graphical chart showing the cash flow of a strategy.
*
* <p>
* This example demonstrates the use of the dual-axis chart functionality in
* {@link ChartWorkflow} to display both the close price and cash flow of a
* trading strategy on the same chart with separate Y-axes.
* </p>
*/
public class CashFlowToChart {
public static void main(String[] args) {
// Getting the bar series
BarSeries series = BitStampCsvTradesFileBarSeriesDataSource.loadBitstampSeries();
// Building the trading strategy
Strategy strategy = MovingMomentumStrategy.buildStrategy(series);
// Running the strategy
BarSeriesManager seriesManager = new BarSeriesManager(series);
TradingRecord tradingRecord = seriesManager.run(strategy);
// Getting the cash flow of the resulting positions
CashFlow cashFlow = new CashFlow(series, tradingRecord);
// Creating indicators for the dual-axis chart
ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
// Building and displaying the dual-axis chart using ChartWorkflow
ChartWorkflow chartWorkflow = new ChartWorkflow();
chartWorkflow.displayDualAxisChart(series, closePrice, "Price (USD)", cashFlow, "Cash Flow Ratio",
"Bitstamp BTC", "Ta4j example - Cash flow to chart");
}
}