@@ -111,15 +111,17 @@ export class AutopilotComponent implements OnInit, OnDestroy {
111
111
Strategy . Short
112
112
] ;
113
113
114
- riskCounter = 2 ;
114
+ riskCounter = 1 ;
115
115
116
116
riskToleranceList = [
117
117
RiskTolerance . None ,
118
118
RiskTolerance . ExtremeFear ,
119
119
RiskTolerance . Fear ,
120
120
RiskTolerance . Neutral ,
121
121
RiskTolerance . Greed ,
122
- RiskTolerance . ExtremeGreed
122
+ RiskTolerance . ExtremeGreed ,
123
+ RiskTolerance . XLGreed ,
124
+ RiskTolerance . XXLGreed
123
125
] ;
124
126
125
127
backtestBuffer$ ;
@@ -227,6 +229,12 @@ export class AutopilotComponent implements OnInit, OnDestroy {
227
229
this . cartService . buyOrders . length || this . cartService . otherOrders . length ) ;
228
230
}
229
231
232
+ resetBacktested ( ) {
233
+ setTimeout ( ( ) => {
234
+ this . isBacktested = false ;
235
+ } , 18000000 ) ;
236
+ }
237
+
230
238
setProfitLoss ( ) {
231
239
const profitObj : ProfitLossRecord = {
232
240
'date' : moment ( ) . format ( ) ,
@@ -251,7 +259,7 @@ export class AutopilotComponent implements OnInit, OnDestroy {
251
259
resetCart ( ) {
252
260
this . executedIndex = 0 ;
253
261
this . lastOrderListIndex = 0 ;
254
- this . isBacktested = false ;
262
+ this . resetBacktested ( ) ;
255
263
this . isTradingStarted = false ;
256
264
this . buyList = [ ] ;
257
265
this . dayTradeList = [ ] ;
@@ -292,7 +300,12 @@ export class AutopilotComponent implements OnInit, OnDestroy {
292
300
console . log ( 'developing strategy lastProfitLoss' , lastProfitLoss ) ;
293
301
if ( lastProfitLoss && lastProfitLoss . profit ) {
294
302
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
+ }
296
309
} else if ( lastProfitLoss . profit * 1 > 0 ) {
297
310
this . increaseRiskTolerance ( ) ;
298
311
}
@@ -687,8 +700,8 @@ export class AutopilotComponent implements OnInit, OnDestroy {
687
700
this . aiPicksService . mlNeutralResults . pipe (
688
701
take ( data . length )
689
702
) . 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 ;
692
705
const order = this . cartService . buildOrder ( stockSymbol ) ;
693
706
const found = this . currentHoldings . find ( ( value ) => {
694
707
return value . name === stockSymbol ;
@@ -803,7 +816,7 @@ export class AutopilotComponent implements OnInit, OnDestroy {
803
816
checkForStopLoss ( holdings : PositionHoldings [ ] ) {
804
817
holdings . forEach ( val => {
805
818
const percentLoss = divide ( val . pl , val . netLiq ) ;
806
- if ( percentLoss < - 0.051 ) {
819
+ if ( percentLoss < - 0.05 ) {
807
820
this . portfolioSell ( val ) ;
808
821
} else if ( percentLoss > 0 ) {
809
822
this . addBuy ( val ) ;
@@ -822,6 +835,9 @@ export class AutopilotComponent implements OnInit, OnDestroy {
822
835
currentHoldings . sort ( ( a , b ) => a . pl - b . pl ) ;
823
836
const toBeSold = currentHoldings . slice ( currentHoldings . length - 10 , currentHoldings . length ) ;
824
837
console . log ( 'too many holdings. selling' , toBeSold , 'from' , currentHoldings ) ;
838
+ toBeSold . splice ( 0 , 1 ) . forEach ( holdingInfo => {
839
+ this . portfolioSell ( holdingInfo ) ;
840
+ } ) ;
825
841
}
826
842
}
827
843
0 commit comments