Skip to content

Commit a168ea1

Browse files
chore: api implementation, links pages
1 parent 9b6c0ff commit a168ea1

File tree

2 files changed

+113
-0
lines changed
  • src/quant_research_starter/frontend/cauweb/src/utils

2 files changed

+113
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
export const api = {
2+
async runBacktest(config) {
3+
// Simulate API call
4+
await new Promise(resolve => setTimeout(resolve, 2000));
5+
return {
6+
metrics: {
7+
totalReturn: 0.2345,
8+
annualizedReturn: 0.0876,
9+
volatility: 0.1567,
10+
sharpeRatio: 1.234,
11+
maxDrawdown: 0.1234,
12+
winRate: 0.645,
13+
turnover: 2.34
14+
},
15+
portfolioSnapshots: generateDemoSnapshots(),
16+
trades: []
17+
};
18+
},
19+
async getAssets() {
20+
return [
21+
{ symbol: 'AAPL', name: 'Apple Inc.', sector: 'Technology', marketCap: 2800000000000, price: 182.63 },
22+
{ symbol: 'MSFT', name: 'Microsoft Corp.', sector: 'Technology', marketCap: 2750000000000, price: 370.73 },
23+
{ symbol: 'GOOGL', name: 'Alphabet Inc.', sector: 'Technology', marketCap: 1750000000000, price: 138.21 },
24+
{ symbol: 'AMZN', name: 'Amazon.com Inc.', sector: 'Consumer', marketCap: 1500000000000, price: 145.18 },
25+
{ symbol: 'TSLA', name: 'Tesla Inc.', sector: 'Consumer', marketCap: 750000000000, price: 238.83 }
26+
];
27+
}
28+
};
29+
function generateDemoSnapshots() {
30+
const snapshots = [];
31+
let value = 100000;
32+
const startDate = new Date('2020-01-01');
33+
for (let i = 0; i < 100; i++) {
34+
const date = new Date(startDate);
35+
date.setDate(date.getDate() + i * 7);
36+
value *= 1 + (Math.random() - 0.45) * 0.02;
37+
snapshots.push({
38+
timestamp: date.toISOString(),
39+
totalValue: value,
40+
cash: 10000,
41+
holdingsValue: value - 10000
42+
});
43+
}
44+
return snapshots;
45+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Mock API functions for development
2+
export interface BacktestMetrics {
3+
totalReturn: number;
4+
annualizedReturn: number;
5+
volatility: number;
6+
sharpeRatio: number;
7+
maxDrawdown: number;
8+
winRate: number;
9+
turnover: number;
10+
}
11+
12+
export interface BacktestResult {
13+
metrics: BacktestMetrics;
14+
portfolioSnapshots: any[];
15+
trades: any[];
16+
}
17+
18+
export const api = {
19+
async runBacktest(config: any): Promise<BacktestResult> {
20+
// Simulate API call
21+
await new Promise(resolve => setTimeout(resolve, 2000));
22+
23+
return {
24+
metrics: {
25+
totalReturn: 0.2345,
26+
annualizedReturn: 0.0876,
27+
volatility: 0.1567,
28+
sharpeRatio: 1.234,
29+
maxDrawdown: 0.1234,
30+
winRate: 0.645,
31+
turnover: 2.34
32+
},
33+
portfolioSnapshots: generateDemoSnapshots(),
34+
trades: []
35+
};
36+
},
37+
38+
async getAssets(): Promise<any[]> {
39+
return [
40+
{ symbol: 'AAPL', name: 'Apple Inc.', sector: 'Technology', marketCap: 2800000000000, price: 182.63 },
41+
{ symbol: 'MSFT', name: 'Microsoft Corp.', sector: 'Technology', marketCap: 2750000000000, price: 370.73 },
42+
{ symbol: 'GOOGL', name: 'Alphabet Inc.', sector: 'Technology', marketCap: 1750000000000, price: 138.21 },
43+
{ symbol: 'AMZN', name: 'Amazon.com Inc.', sector: 'Consumer', marketCap: 1500000000000, price: 145.18 },
44+
{ symbol: 'TSLA', name: 'Tesla Inc.', sector: 'Consumer', marketCap: 750000000000, price: 238.83 }
45+
];
46+
}
47+
};
48+
49+
function generateDemoSnapshots() {
50+
const snapshots = [];
51+
let value = 100000;
52+
const startDate = new Date('2020-01-01');
53+
54+
for (let i = 0; i < 100; i++) {
55+
const date = new Date(startDate);
56+
date.setDate(date.getDate() + i * 7);
57+
value *= 1 + (Math.random() - 0.45) * 0.02;
58+
59+
snapshots.push({
60+
timestamp: date.toISOString(),
61+
totalValue: value,
62+
cash: 10000,
63+
holdingsValue: value - 10000
64+
});
65+
}
66+
67+
return snapshots;
68+
}

0 commit comments

Comments
 (0)