Skip to content

Commit df5601e

Browse files
committed
Updated daytrading
1 parent 4ab0624 commit df5601e

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

app.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
runtime: nodejs12
1+
runtime: nodejs16
22
env_variables:
33
CLIENT_ID: "0033"

package.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
"main": "server/app.js",
66
"scripts": {
77
"ng": "ng",
8-
"start": "pm2 start ecosystem.config.js",
9-
"build": "npm run tslint && npm run lintfix && ng build --aot && npm run build-ts",
10-
"serve": "node dist/app.js",
8+
"serve": "pm2 start ecosystem.config.js",
9+
"build:all": "ng build --aot && npm run build-ts",
10+
"build": "npm run build-ts",
11+
"start": "node dist/app.js",
1112
"test-server": "npm run build-ts && node server-tests.js",
1213
"test": "ng test",
13-
"lint": "ng lint",
1414
"e2e": "ng e2e",
1515
"postinstall": "npm run build",
1616
"build-ts": "tsc -p ./server/tsconfig.json",
1717
"watch-ts": "tsc -p ./server/tsconfig.json -w",
18+
"lint": "npm run tslint && npm run lintfix",
1819
"tslint": "tslint -c tslint.json -p tsconfig.json",
1920
"lintfix": "tslint --fix -c tslint.json -p tsconfig.json",
20-
"deploy": "copyfiles app.yaml dist && cd dist && gcloud app deploy"
21+
"deploy": "copyfiles package.json dist && copyfiles app.yaml dist && cd dist && gcloud app deploy"
2122
},
2223
"private": true,
2324
"dependencies": {
@@ -81,7 +82,6 @@
8182
"tslib": "^1.10.0",
8283
"tulind": "^0.8.15",
8384
"twilio": "^3.50.0",
84-
"typescript": "4.1.5",
8585
"websocket-extensions": "^0.1.4",
8686
"xlsx": "^0.18.5",
8787
"y18n": "^4.0.1",
@@ -115,10 +115,11 @@
115115
"nodemon": "^1.14.1",
116116
"protractor": "^7.0.0",
117117
"ts-node": "^3.3.0",
118-
"tslint": "^6.1.3"
118+
"tslint": "^6.1.3",
119+
"typescript": "4.1.5"
119120
},
120121
"engines": {
121-
"node": ">12.18.3"
122+
"node": "16.20.0"
122123
},
123124
"babel": {
124125
"presets": [

src/app/autopilot/autopilot.component.ts

+23-7
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,17 @@ export class AutopilotComponent implements OnInit, OnDestroy {
111111
Strategy.Short
112112
];
113113

114-
riskCounter = 2;
114+
riskCounter = 1;
115115

116116
riskToleranceList = [
117117
RiskTolerance.None,
118118
RiskTolerance.ExtremeFear,
119119
RiskTolerance.Fear,
120120
RiskTolerance.Neutral,
121121
RiskTolerance.Greed,
122-
RiskTolerance.ExtremeGreed
122+
RiskTolerance.ExtremeGreed,
123+
RiskTolerance.XLGreed,
124+
RiskTolerance.XXLGreed
123125
];
124126

125127
backtestBuffer$;
@@ -227,6 +229,12 @@ export class AutopilotComponent implements OnInit, OnDestroy {
227229
this.cartService.buyOrders.length || this.cartService.otherOrders.length);
228230
}
229231

232+
resetBacktested() {
233+
setTimeout(() => {
234+
this.isBacktested = false;
235+
}, 18000000);
236+
}
237+
230238
setProfitLoss() {
231239
const profitObj: ProfitLossRecord = {
232240
'date': moment().format(),
@@ -251,7 +259,7 @@ export class AutopilotComponent implements OnInit, OnDestroy {
251259
resetCart() {
252260
this.executedIndex = 0;
253261
this.lastOrderListIndex = 0;
254-
this.isBacktested = false;
262+
this.resetBacktested();
255263
this.isTradingStarted = false;
256264
this.buyList = [];
257265
this.dayTradeList = [];
@@ -292,7 +300,12 @@ export class AutopilotComponent implements OnInit, OnDestroy {
292300
console.log('developing strategy lastProfitLoss', lastProfitLoss);
293301
if (lastProfitLoss && lastProfitLoss.profit) {
294302
if (lastProfitLoss.profit * 1 < 0) {
295-
this.decreaseRiskTolerance();
303+
if (lastProfitLoss.lastStrategy === Strategy.Daytrade &&
304+
this.riskCounter < this.riskToleranceList.length) {
305+
this.increaseRiskTolerance();
306+
} else {
307+
this.decreaseRiskTolerance();
308+
}
296309
} else if (lastProfitLoss.profit * 1 > 0) {
297310
this.increaseRiskTolerance();
298311
}
@@ -687,8 +700,8 @@ export class AutopilotComponent implements OnInit, OnDestroy {
687700
this.aiPicksService.mlNeutralResults.pipe(
688701
take(data.length)
689702
).subscribe(latestMlResult => {
690-
console.log('Received results', latestMlResult);
691-
const stockSymbol = latestMlResult.label;
703+
console.log('Received results for current holdings', latestMlResult);
704+
const stockSymbol = latestMlResult.label;
692705
const order = this.cartService.buildOrder(stockSymbol);
693706
const found = this.currentHoldings.find((value) => {
694707
return value.name === stockSymbol;
@@ -803,7 +816,7 @@ export class AutopilotComponent implements OnInit, OnDestroy {
803816
checkForStopLoss(holdings: PositionHoldings[]) {
804817
holdings.forEach(val => {
805818
const percentLoss = divide(val.pl, val.netLiq);
806-
if (percentLoss < -0.051) {
819+
if (percentLoss < -0.05) {
807820
this.portfolioSell(val);
808821
} else if (percentLoss > 0) {
809822
this.addBuy(val);
@@ -822,6 +835,9 @@ export class AutopilotComponent implements OnInit, OnDestroy {
822835
currentHoldings.sort((a, b) => a.pl - b.pl);
823836
const toBeSold = currentHoldings.slice(currentHoldings.length - 10, currentHoldings.length);
824837
console.log('too many holdings. selling', toBeSold, 'from', currentHoldings);
838+
toBeSold.splice(0, 1).forEach(holdingInfo => {
839+
this.portfolioSell(holdingInfo);
840+
});
825841
}
826842
}
827843

station-client.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
echo on
2-
npm i && npm start
2+
npm i && npm run serve

0 commit comments

Comments
 (0)