Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed task 3 #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions 0001-Update-README-setupv3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From ab64da60f7f7839fbd1437d78ed201575601bbba Mon Sep 17 00:00:00 2001
From: jbf-insidesherpa <54832297+jbf-insidesherpa@users.noreply.github.com>
Date: Mon, 25 Nov 2019 10:10:52 +0800
Subject: [PATCH] Update README (setupv3)

---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index d846191..0295c56 100755
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ Use Perspective to create the chart for the trader’s dashboard.
</ol>

<h2 id="installation" >Setup / Installation</h2>
-<p>In order to get the server and client application code working on your machine, <a href="https://insidesherpa.s3.amazonaws.com/vinternships/companyassets/Sj7temL583QAYpHXD/setup_devenv_m3_v2.pdf">follow the setup here</a></p>
+<p>In order to get the server and client application code working on your machine, <a href="https://insidesherpa.s3.amazonaws.com/vinternships/companyassets/Sj7temL583QAYpHXD/setup_devenv_m3_v3.pdf">follow the setup here</a></p>

<p><b>Note</b>:This is the version of the JPM 3 exercise that uses Python 3. The Python 2.7 version is in <a href="https://github.com/insidesherpa/JPMC-tech-task-3">this other repo</a></p>

--
2.26.2.windows.1

31 changes: 21 additions & 10 deletions src/DataManipulator.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import { ServerRespond } from './DataStreamer';

export interface Row {
stock: string,
top_ask_price: number,
price_abc: number,
price_def: number,
ratio: number,
timestamp: Date,
upper_bound: number,
lower_bound: number,
trigger_alert: number | undefined,
}


export class DataManipulator {
static generateRow(serverResponds: ServerRespond[]): Row[] {
return serverResponds.map((el: any) => {
return {
stock: el.stock,
top_ask_price: el.top_ask && el.top_ask.price || 0,
timestamp: el.timestamp,
};
})
static generateRow(serverResponds: ServerRespond[]): Row {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static generateRow(serverRespond: ServerRespond[]): Row {

const priceABC = (serverRespond[0].top_ask.price + serverRespond[0].top_bid.price)/2;
const priceDEF = (serverRespond[1].top_ask.price + serverRespond[1].top_bid.price)/2;
const ratio = priceABC / priceDEF;
const upperBound = 1 + 0.05;
const lowerBound = 1 - 0.05;
return {
price_abc: priceABC,
price_def: priceDEF,
ratio,
timestamp: serverRespond[0].timestamp > serverRespond[1].timestamp ? serverRespond[0].timestamp : serverRespond[1].timestamp,
upper_bound: upperBound,
lower_bound: lowerBound,
trigger_alert: (ratio > upperBound || ratio < lowerBound) ? ratio : undefined,
};
}
}
25 changes: 15 additions & 10 deletions src/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ class Graph extends Component<IProps, {}> {
const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement;

const schema = {
stock: 'string',
top_ask_price: 'float',
top_bid_price: 'float',
prive_abc: 'float',
price_def: 'float',
ratio: 'float',
timestamp: 'date',
upper_bound: 'float',
lower_bound: 'float',
trigger_alert: 'float',
};

if (window.perspective && window.perspective.worker()) {
Expand All @@ -36,23 +39,25 @@ class Graph extends Component<IProps, {}> {
// Load the `table` in the `<perspective-viewer>` DOM reference.
elem.load(this.table);
elem.setAttribute('view', 'y_line');
elem.setAttribute('column-pivots', '["stock"]');
elem.setAttribute('row-pivots', '["timestamp"]');
elem.setAttribute('columns', '["top_ask_price"]');
elem.setAttribute('columns', '["ratio", "lower_bound", "upper_bound", "trigger_alert"]');
elem.setAttribute('aggregates', JSON.stringify({
stock: 'distinctcount',
top_ask_price: 'avg',
top_bid_price: 'avg',
price_abc: 'avg',
price_def: 'avg',
ratio: 'avg',
timestamp: 'distinct count',
upper_bound: 'avg',
lower_bound: 'avg',
trigger_alert: 'avg',
}));
}
}

componentDidUpdate() {
if (this.table) {
this.table.update(
this.table.update([
DataManipulator.generateRow(this.props.data),
);
]);
}
}
}
Expand Down