Skip to content

Commit

Permalink
#483 small code clean-up and bug fix in vuu-data-test
Browse files Browse the repository at this point in the history
- also reverts the addition of prices column in simul instruments
  table in the previous commit.
  • Loading branch information
junaidzm13 committed Dec 8, 2023
1 parent 25017e8 commit 21af6ec
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import InstrumentReferenceData from "./instruments";
import PriceReferenceData from "./prices";
import { instrumentsData } from "./instruments";
import { pricesData } from "./prices";

export type ask = number;
export type askSize = number;
Expand Down Expand Up @@ -61,11 +61,11 @@ const instrumentPrices: InstrumentPricesDataRow[] = [];
// const start = performance.now();
// Create 100_000 Instruments

for (let i = 0; i < InstrumentReferenceData.length; i++) {
for (let i = 0; i < instrumentsData.length; i++) {
// prettier-ignore
const [bbg,currency,description,exchange,isin,lotSize,ric] = InstrumentReferenceData[i];
const [bbg,currency,description,exchange,isin,lotSize,ric] = instrumentsData[i];
const [ask, askSize, bid, bidSize, close, last, open, phase, , scenario] =
PriceReferenceData[i];
pricesData[i];

instrumentPrices.push([
ask,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export type InstrumentsDataRow = [
string,
number,
ric,
price,
supported,
wishlist
wishlist,
price
];

export const InstrumentColumnMap = {
Expand All @@ -37,12 +37,12 @@ export const InstrumentColumnMap = {
string: 4,
number: 5,
ric: 6,
price: 7,
supported: 8,
wishlist: 9,
};
supported: 7,
wishlist: 8,
price: 9,
} as const;

const instruments: InstrumentsDataRow[] = [];
const instrumentsData: InstrumentsDataRow[] = [];

const chars = Array.from("ABCEFGHKMNOPQRTUVWYZ");

Expand Down Expand Up @@ -73,17 +73,17 @@ for (const char of chars) {
const supported = random(0, 1) === 1;
const wishlist = random(0, 1) === 1;

instruments.push([
instrumentsData.push([
bbg,
currency,
description,
exchange,
String(isin),
lotSize,
ric,
price,
supported,
wishlist,
price,
]);
}
}
Expand All @@ -92,8 +92,9 @@ for (const char of chars) {

const instrumentsTable = new Table(
schemas.instruments,
instruments,
instrumentsData,
buildDataColumnMap(schemas.instruments)
);

export { instrumentsData };
export default instrumentsTable;
80 changes: 34 additions & 46 deletions vuu-ui/packages/vuu-data-test/src/simul/reference-data/prices.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { buildDataColumnMap, Table } from "../../Table";
import { BaseUpdateGenerator } from "../../UpdateGenerator";
import { schemas } from "../simul-schemas";
import instrumentTable, { InstrumentsDataRow } from "./instruments";
import { instrumentsData, InstrumentColumnMap } from "./instruments";
import { random } from "../../data-utils";
import basketConstituentData from "../../basket/reference-data/constituents";

Expand Down Expand Up @@ -37,15 +37,14 @@ const pricesUpdateGenerator = new BaseUpdateGenerator({
askSize,
});

const prices: PricesDataRow[] = [];

// const start = performance.now();
// Create 100_000 Instruments

// prettier-ignore
for (const [,,,,,,ric,
priceSeed,
] of instrumentTable.data as InstrumentsDataRow[]) {
const requiredInstrumentFields = ["ric", "price"] as const;
const pricesData: Array<PricesDataRow> = instrumentsData.map((instrument) => {
const { ric, price: priceSeed } = requiredInstrumentFields.reduce(
(obj, f) => ({ ...obj, [f]: instrument[InstrumentColumnMap[f]] }),
{} as { ric: string; price: number }
);
const spread = random(0, 10);

const ask = priceSeed + spread / 2;
Expand All @@ -57,47 +56,35 @@ for (const [,,,,,,ric,
const open = priceSeed + random(0, 1) / 10;
const phase = "C";
const scenario = "close";
prices.push([
ask,
askSize,
bid,
bidSize,
close,
last,
open,
phase,
ric,
scenario,
]);
}
return [ask, askSize, bid, bidSize, close, last, open, phase, ric, scenario];
});

// prettier-ignore
for (const [,,,lastTrade,ric] of basketConstituentData) {
const priceSeed = parseFloat(String(lastTrade));
if (!isNaN(priceSeed)){
const spread = random(0, 10);
const ask = priceSeed + spread / 2;
const askSize = random(1000, 3000);
const bid = priceSeed - spread / 2;
const bidSize = random(1000, 3000);
const close = priceSeed + random(0, 1) / 10;
const last = priceSeed + random(0, 1) / 10;
const open = priceSeed + random(0, 1) / 10;
const phase = "C";
const scenario = "close";
prices.push([
ask,
askSize,
bid,
bidSize,
close,
last,
open,
phase,
ric,
scenario,
]);

if (!isNaN(priceSeed)) {
const spread = random(0, 10);
const ask = priceSeed + spread / 2;
const askSize = random(1000, 3000);
const bid = priceSeed - spread / 2;
const bidSize = random(1000, 3000);
const close = priceSeed + random(0, 1) / 10;
const last = priceSeed + random(0, 1) / 10;
const open = priceSeed + random(0, 1) / 10;
const phase = "C";
const scenario = "close";
pricesData.push([
ask,
askSize,
bid,
bidSize,
close,
last,
open,
phase,
ric as string,
scenario,
]);
}
}

Expand All @@ -106,9 +93,10 @@ for (const [,,,lastTrade,ric] of basketConstituentData) {

const pricesTable = new Table(
schemas.prices,
prices,
pricesData,
buildDataColumnMap(schemas.prices),
pricesUpdateGenerator
);

export { pricesData };
export default pricesTable;
1 change: 0 additions & 1 deletion vuu-ui/packages/vuu-data-test/src/simul/simul-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const schemas: Readonly<Record<SimulTableName, Readonly<TableSchema>>> =
{ name: "isin", serverDataType: "string" },
{ name: "lotSize", serverDataType: "int" },
{ name: "ric", serverDataType: "string" },
{ name: "price", serverDataType: "double" },
{ name: "supported", serverDataType: "boolean" },
{ name: "wishlist", serverDataType: "boolean" },
],
Expand Down

0 comments on commit 21af6ec

Please sign in to comment.