Skip to content

Commit d204bd0

Browse files
committed
Add BB portfolio values
1 parent 20d7fbe commit d204bd0

File tree

9 files changed

+110
-15
lines changed

9 files changed

+110
-15
lines changed

src/components/Dashboard/Chart/BBand.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import React from "react";
22
import { Line } from "react-chartjs-2";
3+
import Table from "@material-ui/core/Table";
4+
import TableBody from "@material-ui/core/TableBody";
5+
import TableCell from "@material-ui/core/TableCell";
6+
import TableContainer from "@material-ui/core/TableContainer";
7+
import TableHead from "@material-ui/core/TableHead";
8+
import TableRow from "@material-ui/core/TableRow";
9+
import Paper from "@material-ui/core/Paper";
310

411
const LineChart = (props) => {
512

@@ -49,8 +56,53 @@ const LineChart = (props) => {
4956
},
5057
};
5158

59+
const rows = [];
60+
61+
for (let i = 0; i < bb.signals.length; i++) {
62+
rows.push({
63+
date: bb.signalDates[i],
64+
signal: bb.signals[i] === 1 ? "BUY" : "SELL",
65+
investedAmount: bb.investedAmount[i].toFixed(2),
66+
liquidAmount: bb.liquidAmount[i].toFixed(2),
67+
totalAmount: bb.totalAmount[i].toFixed(2),
68+
pnl: bb.pnl[i].toFixed(2),
69+
});
70+
}
71+
5272

53-
return <Line style={{ width: "90%" }} data={data} options={options} />;
73+
return (
74+
<>
75+
<Line style={{ width: "90%" }} data={data} options={options} />
76+
<TableContainer style={{marginTop: "25px"}} component={Paper}>
77+
<Table aria-label="simple table">
78+
<TableHead>
79+
<TableRow>
80+
<TableCell>Date</TableCell>
81+
<TableCell align="right">Signal</TableCell>
82+
<TableCell align="right">Invested Amount</TableCell>
83+
<TableCell align="right">Liquid Amount</TableCell>
84+
<TableCell align="right">Total Amount</TableCell>
85+
<TableCell align="right">Trade Profit</TableCell>
86+
</TableRow>
87+
</TableHead>
88+
<TableBody>
89+
{rows.map((row) => (
90+
<TableRow key={row.date}>
91+
<TableCell component="th" scope="row">
92+
{row.date}
93+
</TableCell>
94+
<TableCell align="right">{row.signal}</TableCell>
95+
<TableCell align="right">{row.investedAmount}</TableCell>
96+
<TableCell align="right">{row.liquidAmount}</TableCell>
97+
<TableCell align="right">{row.totalAmount}</TableCell>
98+
<TableCell align="right">{row.pnl}</TableCell>
99+
</TableRow>
100+
))}
101+
</TableBody>
102+
</Table>
103+
</TableContainer>
104+
</>
105+
);
54106
};
55107

56108
export default LineChart;

src/components/Dashboard/Chart/Chart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import BBand from "./BBand";
33
import RSI from "./RSI";
44
import MACD from "./MACD";
55

6-
import Styles from "../styles";
6+
// import Styles from "../styles";
77
import LottieLoader from "../../LottieLoader"
88

99
let ChartJS = (props) => {

src/components/Dashboard/Chart/MACD.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ const LineChart = (props) => {
5656

5757
return (
5858
<>
59-
<Line style={{ width: "90%" }} data={data} options={options} />;
60-
<TableContainer component={Paper}>
59+
<Line style={{ width: "90%" }} data={data} options={options} />
60+
<TableContainer style={{marginTop: "25px"}} component={Paper}>
6161
<Table aria-label="simple table">
6262
<TableHead>
6363
<TableRow>
@@ -66,7 +66,7 @@ const LineChart = (props) => {
6666
<TableCell align="right">Invested Amount</TableCell>
6767
<TableCell align="right">Liquid Amount</TableCell>
6868
<TableCell align="right">Total Amount</TableCell>
69-
<TableCell align="right">Net Profit</TableCell>
69+
<TableCell align="right">Trade Profit</TableCell>
7070
</TableRow>
7171
</TableHead>
7272
<TableBody>

src/components/Dashboard/Chart/RSI.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const LineChart = (props) => {
5555
}
5656
return (
5757
<>
58-
<Line style={{ width: "90%" }} data={data} options={options} />;
59-
<TableContainer component={Paper}>
58+
<Line style={{ width: "90%" }} data={data} options={options} />
59+
<TableContainer style={{marginTop: "25px"}} component={Paper}>
6060
<Table aria-label="simple table">
6161
<TableHead>
6262
<TableRow>
@@ -65,7 +65,7 @@ const LineChart = (props) => {
6565
<TableCell align="right">Invested Amount</TableCell>
6666
<TableCell align="right">Liquid Amount</TableCell>
6767
<TableCell align="right">Total Amount</TableCell>
68-
<TableCell align="right">Net Profit</TableCell>
68+
<TableCell align="right">Trade Profit</TableCell>
6969
</TableRow>
7070
</TableHead>
7171
<TableBody>

src/components/Dashboard/Dashboard.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function ResponsiveDrawer(props) {
2929
//BB params
3030

3131
let [BBData, setBBData] = useState({});
32+
let [BBAmount, setBBAmount] = useState(10000);
3233
let [BBWindow, setBBWindow] = useState(20);
3334
let [BBSDFactor, setBBSDFactor] = useState(2);
3435

@@ -67,6 +68,7 @@ function ResponsiveDrawer(props) {
6768
end: endDate.toISOString().substring(0, 10),
6869
window: 20,
6970
sdfactor: 2,
71+
investment: BBAmount
7072
},
7173
};
7274

@@ -149,6 +151,8 @@ function ResponsiveDrawer(props) {
149151
setEndDate={setEndDate}
150152

151153
setBBData={setBBData}
154+
BBAmount={BBAmount}
155+
setBBAmount={setBBAmount}
152156
BBWindow={BBWindow}
153157
setBBWindow={setBBWindow}
154158
BBSDFactor={BBSDFactor}
@@ -200,6 +204,9 @@ function ResponsiveDrawer(props) {
200204
endDate={endDate}
201205
setEndDate={setEndDate}
202206

207+
208+
BBAmount={BBAmount}
209+
setBBAmount={setBBAmount}
203210
setBBData={setBBData}
204211
BBWindow={BBWindow}
205212
setBBWindow={setBBWindow}

src/components/Dashboard/Drawer/Drawer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const DashboardDrawer = (props) => {
3232
let setChartType = props.setChartType;
3333

3434
// let setBBData = props.setBBData;
35+
let BBAmount = props.BBAmount;
36+
let setBBAmount = props.setBBAmount;
3537
let BBWindow = props.BBWindow;
3638
let setBBWindow = props.setBBWindow;
3739
let BBSDFactor = props.BBSDFactor;
@@ -93,6 +95,7 @@ const DashboardDrawer = (props) => {
9395
end: endDate.toISOString().substring(0, 10),
9496
window: BBWindow,
9597
sdfactor: BBSDFactor,
98+
investment: BBAmount
9699
},
97100
};
98101
props.setBBData(await getBBData(data));
@@ -202,6 +205,8 @@ const DashboardDrawer = (props) => {
202205
setRSIUpperBand={setRSIUpperBand}
203206
RSILowerBand={RSILowerBand}
204207
setRSILowerBand={setRSILowerBand}
208+
BBAmount={BBAmount}
209+
setBBAmount={setBBAmount}
205210
BBWindow={BBWindow}
206211
setBBWindow={setBBWindow}
207212
BBSDFactor={BBSDFactor}

src/components/Dashboard/Drawer/Hyperparameters.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ const Hyperparameter = (props) => {
1010
case "BB":
1111
return (
1212
<>
13+
<TextField
14+
id="standard-basic"
15+
label="Amount"
16+
value={props.BBAmount}
17+
className={classes.drawerItem}
18+
onChange={(e) => {
19+
props.setBBAmount(e.target.value);
20+
}}
21+
/>
1322
<TextField
1423
id="standard-basic"
1524
label="Lookback Period"

src/components/Dashboard/getBBdata.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,51 @@ import axios from "axios";
22

33
const getBBData = async (data) => {
44

5-
let res = await axios.post("https://secret-reaches-87237.herokuapp.com/getBBands", data);
5+
let res = await axios.post("http://127.0.0.1:5000/getBBands", data);
66
let ma = [];
77
let ub = [];
88
let lb = [];
99
let close = [];
1010
let date = [];
11-
for (let i = 0; i < res.data.length; i++) {
11+
12+
13+
let Signals = [];
14+
let SignalDates = [];
15+
let InvestedAmount = [];
16+
let LiquidAmount = [];
17+
let TotalAmount = [];
18+
let Pnl = [];
19+
20+
for (let i = 0; i < res.data.data_length; i++) {
1221
ma[i] = res.data.data[i].moving_average;
1322
ub[i] = res.data.data[i].upper_band;
1423
lb[i] = res.data.data[i].lower_band;
1524
close[i] = res.data.data[i].close;
1625
date[i] = res.data.data[i].date;
1726
}
27+
28+
for (let i = 0; i < res.data["ordered_signals_len"]; i++) {
29+
Signals.push(res.data.ordered_signals[i]["signal"]);
30+
SignalDates.push(res.data.ordered_signals[i]["date"]);
31+
InvestedAmount.push(res.data.ordered_signals[i]["invested_amount"]);
32+
LiquidAmount.push(res.data.ordered_signals[i]["liquid_amount"]);
33+
TotalAmount.push(res.data.ordered_signals[i]["total_amount"]);
34+
Pnl.push(res.data.ordered_signals[i]["pnl"]);
35+
36+
}
37+
1838
let BB = {
1939
avg: ma,
2040
uband: ub,
2141
lband: lb,
2242
close: close,
2343
date: date,
44+
signals: Signals,
45+
signalDates: SignalDates,
46+
investedAmount: InvestedAmount,
47+
liquidAmount: LiquidAmount,
48+
totalAmount: TotalAmount,
49+
pnl: Pnl
2450
}
2551
return BB;
2652

src/components/Dashboard/getMACDData.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ const getMACDData = async (data) => {
44

55
let res = await axios.post("https://secret-reaches-87237.herokuapp.com/getMACD", data);
66

7-
console.log(res);
8-
97
let MACDData = [];
108
let Dates = [];
119
let Signals = [];
1210
let SignalDates = [];
1311
let InvestedAmount = [];
1412
let LiquidAmount = [];
1513
let TotalAmount = [];
16-
let Pnl = []
14+
let Pnl = [];
1715

1816
for(let i = 0; i < res.data.data_len; i++)
1917
{
@@ -41,8 +39,6 @@ const getMACDData = async (data) => {
4139
totalAmount: TotalAmount,
4240
pnl: Pnl
4341
}
44-
45-
console.log(MACD);
4642

4743

4844
return MACD;

0 commit comments

Comments
 (0)